[Bug tree-optimization/85700] Spurious -Wstringop-truncation warning with strncat
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85700 Martin Sebor changed: What|Removed |Added Status|ASSIGNED|RESOLVED Resolution|--- |FIXED --- Comment #5 from Martin Sebor --- Patch committed to the trunk of GCC 9 in r262110. Patrick, please reopen the bug if it's important to you that it be backported to GCC 8 (e.g., if it's preventing you or your users from enabling the new option).
[Bug tree-optimization/85700] Spurious -Wstringop-truncation warning with strncat
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85700 --- Comment #4 from Martin Sebor --- Author: msebor Date: Mon Jun 25 20:33:28 2018 New Revision: 262110 URL: https://gcc.gnu.org/viewcvs?rev=262110=gcc=rev Log: PR tree-optimization/85700 - Spurious -Wstringop-truncation warning with strncat gcc/ChangeLog: PR tree-optimization/85700 * gimple-fold.c (gimple_fold_builtin_strncat): Adjust comment. * tree-ssa-strlen.c (is_strlen_related_p): Handle integer subtraction. (maybe_diag_stxncpy_trunc): Distinguish strncat from strncpy. gcc/testsuite/ChangeLog: PR tree-optimization/85700 * gcc.dg/Wstringop-truncation-4.c: New test. Added: trunk/gcc/testsuite/gcc.dg/Wstringop-truncation-4.c Modified: trunk/gcc/ChangeLog trunk/gcc/gimple-fold.c trunk/gcc/testsuite/ChangeLog trunk/gcc/tree-ssa-strlen.c
[Bug tree-optimization/85700] Spurious -Wstringop-truncation warning with strncat
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85700 Martin Sebor changed: What|Removed |Added Keywords||patch --- Comment #3 from Martin Sebor --- Patch: https://gcc.gnu.org/ml/gcc-patches/2018-05/msg01189.html
[Bug tree-optimization/85700] Spurious -Wstringop-truncation warning with strncat
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85700 Martin Sebor changed: What|Removed |Added Status|NEW |ASSIGNED Assignee|unassigned at gcc dot gnu.org |msebor at gcc dot gnu.org --- Comment #2 from Martin Sebor --- Let me look into it.
[Bug tree-optimization/85700] Spurious -Wstringop-truncation warning with strncat
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85700 Martin Sebor changed: What|Removed |Added Keywords||diagnostic Status|UNCONFIRMED |NEW Last reconfirmed||2018-05-08 CC||msebor at gcc dot gnu.org Component|c++ |tree-optimization Ever confirmed|0 |1 --- Comment #1 from Martin Sebor --- Confirmed. Strncat is handled in maybe_diag_stxncpy_trunc() the same way as strncpy and the approach doesn't seem right for the former. The following test case shows the inconsistency. (The difference between C and C++ is due to the C defining strncat as a macro which suppresses the warning due to -Wno-system-headers; in C++, strncat is defined as a function so -Wno-system-headers has no effect on calls to it.) $ cat u.c && gcc -O2 -S -Wall -ftrack-macro-expansion=0 /build/tmp/u.c #define strncat __builtin_strncat #define strlen __builtin_strlen char a[4], b[4]; void f1 (void) { strncat (a, "1", sizeof a - strlen (a) - 1); // no warning (good) } void f2 (void) { strncat (a, "12", sizeof a - strlen (a) - 1); // bogus -Wstringop-truncation } void fx (void) { strncat (a, b, sizeof a - strlen (a) - 1); // bogus -Wstringop-truncation } /build/tmp/u.c: In function ‘f2’: /build/tmp/u.c:13:3: warning: ‘__builtin_strncat’ output may be truncated copying between 0 and 3 bytes from a string of length 2 [-Wstringop-truncation] strncat (a, "12", sizeof a - strlen (a) - 1); // bogus -Wstringop-truncation ^~~~ /build/tmp/u.c: In function ‘fx’: /build/tmp/u.c:18:3: warning: ‘__builtin_strncat’ output may be truncated copying between 0 and 3 bytes from a string of length 3 [-Wstringop-truncation] strncat (a, b, sizeof a - strlen (a) - 1); // bogus -Wstringop-truncation ^