This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Use C99-compliant scanf under _GNU_SOURCE with C99/C++11 and higher.
- From: Zack Weinberg <zackw at panix dot com>
- To: Florian Weimer <fweimer at redhat dot com>
- Cc: GNU C Library <libc-alpha at sourceware dot org>, Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- Date: Mon, 17 Dec 2018 12:07:15 -0500
- Subject: Re: [PATCH] Use C99-compliant scanf under _GNU_SOURCE with C99/C++11 and higher.
- References: <20181217161827.12154-1-zackw@panix.com> <8736qw6qbb.fsf@oldenburg2.str.redhat.com>
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