https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91397
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |msebor at gcc dot gnu.org --- Comment #10 from Martin Sebor <msebor at gcc dot gnu.org> --- GCC assumes that no object can be bigger than PTRDIFF_MAX - 1 bytes and warns when it detects code that expects otherwise. A more general condition to add to mem_strdupl() to avoid the warning is: if (len >= PTRDIFF_MAX) __builtin_unreachable (); GCC doesn't track pointer ranges as well as it does integers and it easily "loses" information about their relationships. For instance, in the functions below, GCC folds the first test to false but it doesn't fold the second. void f (long a, long b) { if (a < b) return; if (a - b < 0) // folded to false __builtin_abort (); } void g (int *a, int *b) { if (a < b) return; if (a - b < 0) // not folded __builtin_abort (); }