https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82046
Bug ID: 82046 Summary: Bogus -fsanitize=undefined error with -O2 -Wall Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: sanitizer Assignee: unassigned at gcc dot gnu.org Reporter: hjl.tools at gmail dot com CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org, jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at gcc dot gnu.org Target Milestone: --- [hjl@gnu-6 gcc]$ cat /tmp/x.i typedef struct sym { unsigned long bb_addr[10]; unsigned long bb_calls[10]; } Sym; void annotate_with_count (Sym *b) { unsigned int i; unsigned long last_count; char tmpbuf[10 * 30]; char *p; p = tmpbuf; *p = '\0'; for (i = 0; i < 10 && b->bb_addr[i]; i++) { last_count = b->bb_calls[i]; if (p > tmpbuf) *p++ = ','; __builtin_sprintf (p, "%lu", last_count); p += __builtin_strlen (p); } } [hjl@gnu-6 gcc]$ ./xgcc -B./ -S /tmp/x.i -Wall -O2 -fsanitize=undefined /tmp/x.i: In function ‘annotate_with_count’: /tmp/x.i:24:7: warning: null destination pointer [-Wformat-overflow=] __builtin_sprintf (p, "%lu", last_count); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [hjl@gnu-6 gcc]$