[PATCH] Use C99-compliant scanf under _GNU_SOURCE with C99/C++11 and higher.
Zack Weinberg
zackw@panix.com
Mon Dec 17 17:22:00 GMT 2018
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
More information about the Libc-alpha
mailing list