This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Use C99-compliant scanf under _GNU_SOURCE with C99/C++11 and higher.


On Mon, Dec 17, 2018 at 12:01 PM Florian Weimer <fweimer@redhat.com> wrote:
> * Zack Weinberg:
> > +
> > +  GCC's -Wformat warnings can detect most uses of this extension, as long
> > +  as all functions that call vscanf, vfscanf, or vsscanf are annotated with
> > +  __attribute__ ((format (scanf, ...))).
>
> What's the state of GCC warnings?  Does GCC already anticipate this
> change?

Yes, that's what I meant.  Current versions of GCC, in -std=[c|gnu]99
mode, already diagnose use of `%as` in the old GNU sense, regardless
of _GNU_SOURCE.

$ cat test.c
#include <stdio.h>

int main(void)
{
  char *foo;
  scanf("%as", &foo);
  printf("%s", foo);
  return 0;
}

$ gcc --version
gcc (Debian 8.2.0-12) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gcc -std=gnu89 -D_GNU_SOURCE -c -Wall test.c
[no warnings]

$ gcc -std=gnu99 -D_GNU_SOURCE -c -Wall test.c
test.c: In function ‘main’:
test.c:6:11: warning: format ‘%a’ expects argument of type ‘float *’,
but argument 2 has type ‘char **’ [-Wformat=]
   scanf("%as", &foo);
          ~^    ~~~~

I don't know how long this has been true.

zw


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]