You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const std::string s = calc ? calc->expressionString() : "ptr+1";
1386
+
reportError(tok, Severity::warning, "pointerAdditionResultNotNull", "Comparison is wrong. Result of '" + s + "' can't be 0 unless there is pointer overflow, and pointer overflow is undefined behaviour.");
@@ -2212,27 +2213,27 @@ class TestCondition : public TestFixture {
2212
2213
check("void f(char *p, unsigned int x) {\n"
2213
2214
" assert((p + x) < p);\n"
2214
2215
"}");
2215
-
ASSERT_EQUALS("[test.cpp:2]: (warning) Invalid test for overflow '(p+x)<p'. Condition is always false unless there is overflow, and overflow is UB.\n", errout.str());
2216
+
ASSERT_EQUALS("[test.cpp:2]: (warning) Invalid test for overflow '(p+x)<p'. Condition is always false unless there is overflow, and overflow is undefined behaviour.\n", errout.str());
2216
2217
2217
2218
check("void f(char *p, unsigned int x) {\n"
2218
2219
" assert((p + x) >= p);\n"
2219
2220
"}");
2220
-
ASSERT_EQUALS("[test.cpp:2]: (warning) Invalid test for overflow '(p+x)>=p'. Condition is always true unless there is overflow, and overflow is UB.\n", errout.str());
2221
+
ASSERT_EQUALS("[test.cpp:2]: (warning) Invalid test for overflow '(p+x)>=p'. Condition is always true unless there is overflow, and overflow is undefined behaviour.\n", errout.str());
2221
2222
2222
2223
check("void f(char *p, unsigned int x) {\n"
2223
2224
" assert(p > (p + x));\n"
2224
2225
"}");
2225
-
ASSERT_EQUALS("[test.cpp:2]: (warning) Invalid test for overflow 'p>(p+x)'. Condition is always false unless there is overflow, and overflow is UB.\n", errout.str());
2226
+
ASSERT_EQUALS("[test.cpp:2]: (warning) Invalid test for overflow 'p>(p+x)'. Condition is always false unless there is overflow, and overflow is undefined behaviour.\n", errout.str());
2226
2227
2227
2228
check("void f(char *p, unsigned int x) {\n"
2228
2229
" assert(p <= (p + x));\n"
2229
2230
"}");
2230
-
ASSERT_EQUALS("[test.cpp:2]: (warning) Invalid test for overflow 'p<=(p+x)'. Condition is always true unless there is overflow, and overflow is UB.\n", errout.str());
2231
+
ASSERT_EQUALS("[test.cpp:2]: (warning) Invalid test for overflow 'p<=(p+x)'. Condition is always true unless there is overflow, and overflow is undefined behaviour.\n", errout.str());
2231
2232
2232
2233
check("void f(signed int x) {\n"
2233
2234
" assert(x + 100 < x);\n"
2234
2235
"}");
2235
-
ASSERT_EQUALS("[test.cpp:2]: (warning) Invalid test for overflow 'x+100<x'. Condition is always false unless there is overflow, and overflow is UB.\n", errout.str());
2236
+
ASSERT_EQUALS("[test.cpp:2]: (warning) Invalid test for overflow 'x+100<x'. Condition is always false unless there is overflow, and overflow is undefined behaviour.\n", errout.str());
2236
2237
2237
2238
check("void f(signed int x) {\n"// unsigned overflow => don't warn
2238
2239
" assert(x + 100U < x);\n"
@@ -2266,6 +2267,13 @@ class TestCondition : public TestFixture {
2266
2267
"}");
2267
2268
ASSERT_EQUALS("[test.cpp:2]: (style) Condition 'a+1' is always true\n", errout.str());
2268
2269
}
2270
+
2271
+
voidpointerAdditionResultNotNull() {
2272
+
check("void f(char *ptr) {\n"
2273
+
" if (ptr + 1 != 0);\n"
2274
+
"}");
2275
+
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison is wrong. Result of 'ptr+1' can't be 0 unless there is pointer overflow, and pointer overflow is undefined behaviour.\n", errout.str());
0 commit comments