This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: -Wformat-overflow works strangely with struct members
- From: Xi Ruoyao <ryxi at stu dot xidian dot edu dot cn>
- To: Martin Sebor <msebor at gmail dot com>, Basin Ilya <basinilya at gmail dot com>, gcc-help at gcc dot gnu dot org
- Cc: ryxi at stu dot xidian dot edu dot cn
- Date: Sat, 08 Jul 2017 00:27:14 +0800
- Subject: Re: -Wformat-overflow works strangely with struct members
- Authentication-results: sourceware.org; auth=none
- References: <918b22e7-b918-0f6f-17f5-84960c00bfef@gmail.com> <21c65b5f-50c3-f7ad-2b88-303c3925b23c@gmail.com>
On 2017-07-07 09:35 -0600, Martin Sebor wrote:
> On 07/07/2017 07:05 AM, Basin Ilya wrote:
> > #include <stdio.h>
> >
> > extern struct {
> > char s[142];
> > } x;
> >
> > extern char s[142];
> >
> > int main(int argc, char *argv[]) {
> > char buf[12];
> > sprintf(buf, "%c%s", 'x', x.s); // why warning?
> > sprintf(buf, "%s", x.s); // why no warning then?
> > sprintf(buf, "%c%s", 'x', s); // why no warning then?
> > return 0;
> > }
> With GCC 8 I get a warning for the second call to sprintf for
> the same reason at both -Wformat-overflow levels. I'm not sure
> what prevents it in your case. Please open a new bug for it and
> either attach the translation unit for your test case (obtained
> by preprocessing it with with -E) or remove the #include and
> declare sprintf or use __builtin_sprintf. (This should tell
> us if the sprintf declaration in <stdio.h> is causing it.)
No. Using __builtin_sprintf still produces no warning with
GCC 7. I think it's a GCC 7 bug.
--
Xi Ruoyao <ryxi@stu.xidian.edu.cn>
School of Aerospace Science and Technology, Xidian University