diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 97d167ed2..22a853710 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -2209,5 +2209,9 @@ void CheckBufferOverrun::arrayIndexThenCheck() void CheckBufferOverrun::arrayIndexThenCheckError(const Token *tok, const std::string &indexName) { - reportError(tok, Severity::style, "arrayIndexThenCheck", "array index " + indexName + " is used before bounds check"); + reportError(tok, Severity::style, "arrayIndexThenCheck", + "Array index " + indexName + " is used before limits check\n" + "Defensive programming: The variable " + indexName + " is used as array index and then there is a check that it is within limits. This can " + "mean that the array might be accessed out-of-bounds. Reorder conditions such as '(a[i] && i < 10)' to '(i < 10 && a[i])'. That way the " + "array will not be accessed when the index is out of limits."); } diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 3aa68370e..fbd6a5701 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -3026,13 +3026,13 @@ private: " if (s[i] == 'x' && i < y) {\n" " }" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) array index i is used before bounds check\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) Array index i is used before limits check\n", errout.str()); check("void f(const char s[]) {\n" " for (i = 0; s[i] == 'x' && i < y; ++i) {\n" " }" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) array index i is used before bounds check\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) Array index i is used before limits check\n", errout.str()); } };