-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Closed
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer
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).
Metadata
Metadata
Assignees
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer