https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88771
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|ASSIGNED |NEW --- Comment #20 from Martin Sebor <msebor at gcc dot gnu.org> --- The patch to make the warning less misleading has been committed in r268775. With the test case from comment #0 cleaned up a bit, the warning looks like this: $ cat pr88771.c && gcc -O2 -S -Wall pr88771.c int f (char *d, const char *s, int n) { int i = n + 1 ? n + 1 : 1; __builtin_strncpy (d, s, n); if (i) return 1; return 0; } pr88771.c: In function ‘f’: pr88771.c:5:3: warning: ‘__builtin_strncpy’ specified bound 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=] 5 | __builtin_strncpy (d, s, n); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ It's interesting to note that the test after the (n + 1) addition relies on signed integer overflow having wrapping semantics. With that invalid assumption removed by making n's and i's type unsigned the warning is gone because doing so prevents jump threading from inserting the additional strncpy call. (But there are other, valid cases where the invalid call still is introduced and the warning triggers.)