unicodeobject.c from Python 2.5 assumes signed integer overflow in the following code in unicode_expandtabs function : i and j are signed integers (defined as ssize_t) : [...] else { j++; if (*p == '\n' || *p == '\r') { i += j; <=== Possible overflow old_j = j = 0; if (i < 0) { <== Code won't work due to undefined overflow PyErr_SetString(PyExc_OverflowError, "new string is too long"); return NULL; } } } [...] Now if I compile this file with -O3 -Wstrict-overflow=3 I got no warning although undefined overflow occurs and code is miscompiled unless -fwrapv is specified. I think gcc should be warning us here about undefined overflow.
Created attachment 14964 [details] Preprocessed source code for unicodeobject.c
When I compile this code with current mainline with -O3 -Wstrict-overflow=3 I get the following warnings: Objects/unicodeobject.c: In function ‘unicode_startswith’: Objects/unicodeobject.c:6943: warning: dereferencing type-punned pointer will break strict-aliasing rules Objects/unicodeobject.c:6947: warning: dereferencing type-punned pointer will break strict-aliasing rules Objects/unicodeobject.c: In function ‘unicode_endswith’: Objects/unicodeobject.c:6989: warning: dereferencing type-punned pointer will break strict-aliasing rules Objects/unicodeobject.c:6992: warning: dereferencing type-punned pointer will break strict-aliasing rules Objects/unicodeobject.c: In function ‘unicode_expandtabs’: Objects/unicodeobject.c:5719: warning: assuming signed overflow does not occur when simplifying conditional to constant Objects/unicodeobject.c:5727: warning: assuming signed overflow does not occur when simplifying conditional to constant Objects/unicodeobject.c: In function ‘rsplit’: Objects/unicodeobject.c:368: warning: assuming signed overflow does not occur when simplifying conditional to constant Objects/unicodeobject.c: In function ‘PyUnicodeUCS4_Join’: Objects/unicodeobject.c:4659: warning: assuming signed overflow does not occur when simplifying conditional to constant Objects/unicodeobject.c: In function ‘PyUnicodeUCS4_Compare’: Objects/unicodeobject.c:5376: warning: assuming signed overflow does not occur when changing X +- C1 cmp C2 to X cmp C1 +- C2 Objects/unicodeobject.c:5376: warning: assuming signed overflow does not occur when changing X +- C1 cmp C2 to X cmp C1 +- C2 The code you are talking about seems to be around line 5722, so this seems to provide the warnings that you are looking for. So: which compiler are you using? What output do you see?
Looks like -Wall being at the end disables this warning uh oh. This is invalid, sorry for taking your time.
Actually I am reopening this because after talking to Richi we agree that -Wall should not reset -Wstrict-overflow. But of course final decision is up to iant.
*** This bug has been marked as a duplicate of 32102 ***