Closed
Description
-Wtautological-compare
should report pointer "bounds checks" patterns that are always true/false because unsigned pointer arithmetic cannot overflow.
bool test1(const char *ptr, size_t index) {
return ptr + index < ptr; // always false
}
bool test2(const char *ptr, size_t index) {
return ptr + index >= ptr; // always true
}
These two are fine though:
bool test3(const char *ptr, ssize_t index) {
return ptr + index < ptr; // unknown (same as index < 0)
}
bool test4(const char *ptr, ssize_t index) {
return ptr + index >= ptr; // unknown (same as index >= 0)
}
Idea from #118472 (comment).