This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC 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] | |
On 07/07/2017 10:27 AM, Xi Ruoyao wrote:
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.
Ah, yes, I forgot. GCC 7 doesn't handle format strings consisting solely of a single %s directive because it transforms such calls to strcpy very early on, before the warning pass has a chance to see them. It's fixed in GCC 8 under bug 77671. Martin
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |