diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 60137f036..07294cadc 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -2102,7 +2102,7 @@ void CheckBufferOverrun::arrayIndexThenCheck() // statement can be closed in parentheses, so "(| " is using if (Token::Match(tok, "&& (| %varid% <|<=", indexID)) arrayIndexThenCheckError(tok, indexName); - else if (Token::Match(tok, "&& (| %any% >|>= %varid%", indexID)) + else if (Token::Match(tok, "&& (| %any% >|>= %varid% !!+", indexID)) arrayIndexThenCheckError(tok, indexName); } } diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 94fc8a720..6a1320c47 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -3976,6 +3976,12 @@ private: "}"); ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", errout.str()); + check("void f(char* e, int y) {\n" + " if (e[y] == '/' && elen > y + 1 && e[y + 1] == '?') {\n" + " }\n" + "}"); + ASSERT_EQUALS("", errout.str()); + // this one doesn't work for now, hopefully in the future check("void f(const int a[], unsigned i) {\n" " if(a[i] < func(i) && i <= 42) {\n"