https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94021
Bug ID: 94021 Summary: -Werror=format-truncation= seems to cause incorrect warning, thus error. Product: gcc Version: 9.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: ishikawa at yk dot rim.or.jp Target Milestone: --- Created attachment 47961 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47961&action=edit preprocessed input file. I am attaching the preprocessed source file, and the exact command that produced the error. And the error log in the following. The crux of the "bogus" error is as follows.: /NEW-SSD/NREF-COMM-CENTRAL/mozilla/comm/calendar/libical/src/libical/icaltimezone.c:1913:35: error: ‘%02i’ directive output may be truncated writing 2 bytes into a region of size between 1 and 5 [-Werror=format-truncation=] 1913 | snprintf (buffer, buffer_size, "%s%02i%02i%02i", sign, hours, minutes, seconds); | ^~~~~~~~~~~~~~~~ /NEW-SSD/NREF-COMM-CENTRAL/mozilla/comm/calendar/libical/src/libical/icaltimezone.c:1913:35: note: directive argument in the range [0, 59] /NEW-SSD/NREF-COMM-CENTRAL/mozilla/comm/calendar/libical/src/libical/icaltimezone.c:1913:35: note: directive argument in the range [1, 59] In file included from /usr/include/stdio.h:867, from /NEW-SSD/moz-obj-dir/objdir-tb3/dist/system_wrappers/stdio.h:3, from /NEW-SSD/NREF-COMM-CENTRAL/mozilla/comm/calendar/libical/src/libical/icaltimezone.c:34, from Unified_c_libical_src_libical1.c:2: /usr/include/x86_64-linux-gnu/bits/stdio2.h:67:10: note: ‘__builtin___snprintf_chk’ output between 8 and 12 bytes into a destination of size 8 67 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 68 | __bos (__s), __fmt, __va_arg_pack ()); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from Unified_c_libical_src_libical1.c:2: /NEW-SSD/NREF-COMM-CENTRAL/mozilla/comm/calendar/libical/src/libical/icaltimezone.c:1911:35: error: ‘%02i’ directive output may be truncated writing 2 bytes into a region of size between 1 and 5 [-Werror=format-truncation=] 1911 | snprintf (buffer, buffer_size, "%s%02i%02i", sign, hours, minutes); | ^~~~~~~~~~~~ /NEW-SSD/NREF-COMM-CENTRAL/mozilla/comm/calendar/libical/src/libical/icaltimezone.c:1911:35: note: directive argument in the range [0, 59] In file included from /usr/include/stdio.h:867, from /NEW-SSD/moz-obj-dir/objdir-tb3/dist/system_wrappers/stdio.h:3, from /NEW-SSD/NREF-COMM-CENTRAL/mozilla/comm/calendar/libical/src/libical/icaltimezone.c:34, from Unified_c_libical_src_libical1.c:2: /usr/include/x86_64-linux-gnu/bits/stdio2.h:67:10: note: ‘__builtin___snprintf_chk’ output between 6 and 10 bytes into a destination of size 8 67 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 68 | __bos (__s), __fmt, __va_arg_pack ()); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This comes from the source (unprocessed).: |sign| is either "+" or "-", and the |hours|, |minutes|, and |seconds| are limited to [0,24), [0, 60). if ((0 <= minutes && minutes <= 60) && (0 <= hours && hours <= 24) && (0 <= seconds && seconds <= 60)) { if (seconds == 0) snprintf (buffer, buffer_size, "%s%02i%02i", sign, hours, minutes); else snprintf (buffer, buffer_size, "%s%02i%02i%02i", sign, hours, minutes, seconds); } else { Please note that in the error/warning message, the range is reported slightly differently in a place. /icaltimezone.c:1913:35: note: directive argument in the range [0, 59] /NEW-SSD/NREF-COMM-CENTRAL/mozilla/comm/calendar/libical/src/libical/icaltimezone.c:1913:35: note: directive argument in the range [1, 59] I suspect some kind of internal data corruption. A very simple program source code, t-snrpintf-issue.c does not cause the problem to manifest. So I think the problem is caused by a combination of large source file and maybe inlining? The source code is part of mozilla thunderbird (its calendar subsystem). In another instance where such error/warning was observed, when I added the constraint of the form of if ((0 <= minutes && minutes <= 60) && (0 <= hours && hours <= 24) && (0 <= seconds && seconds <= 60)) the compilation worked without the truncation error/warning message. But here even though I added the if-expr to constrain the values to only two decimal digits, the error/warning persists. TIA