https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108939
Ivan Krylov <ikrylov at disroot dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ikrylov at disroot dot org
--- Comment #3 from Ivan Krylov <ikrylov at disroot dot org> ---
gcc 12.2.0-14 from Debian stable emits -Wstringop-truncation for the following
example in similar circumstances: -O2 -fsanitize=address -Wall
#include <string.h>
#include <stdio.h>
#define STRING10 "1234567890"
#define MAXLINE 10
void foo(void) {
char s1[MAXLINE + 1];
strcpy(s1, STRING10);
char trunc_s1[5] = { 0, };
// recommended by GCC documentation: pass sizeof buf - 1 to avoid warning
strncpy(trunc_s1, s1, sizeof(trunc_s1) - 1);
trunc_s1[sizeof trunc_s1 - 1] = '\0';
}
Same thing currently happens with gcc 14.2 and trunk:
https://godbolt.org/z/Gb8bxWT9s
The example was reduced from a larger problem discussed on the R-package-devel
mailing list: https://stat.ethz.ch/pipermail/r-package-devel/2024q4/011287.html
Following an IRC discussion with sam_ and Arsen, this may be yet another
instance of bug 117881.