diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index c97642b9930..742d5dbb6a8 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -221,7 +221,7 @@ static bool getDimensionsEtc(const Token * const arrayToken, const Settings &set return ChildrenToVisit::op1_and_op2; }); } - } else if (const Token *stringLiteral = array->getValueTokenMinStrSize(settings, &path)) { + } else if (const Token *stringLiteral = array->getValueTokenMinStrSize(settings, &path, &errorPath)) { Dimension dim; dim.tok = nullptr; dim.num = Token::getStrArraySize(stringLiteral); @@ -360,7 +360,7 @@ void CheckBufferOverrunImpl::arrayIndex() const std::vector& indexValues = getOverrunIndexValues(tok, tok->astOperand1(), dimensions, indexTokens, path); if (!indexValues.empty()) - arrayIndexError(tok, dimensions, indexValues); + arrayIndexError(tok, dimensions, indexValues, std::move(errorPath)); } // Negative index @@ -421,7 +421,8 @@ static std::string arrayIndexMessage(const Token* tok, void CheckBufferOverrunImpl::arrayIndexError(const Token* tok, const std::vector& dimensions, - const std::vector& indexes) + const std::vector& indexes, + ErrorPath errorPath) { if (!tok) { reportError(tok, Severity::error, "arrayIndexOutOfBounds", "Array 'arr[16]' accessed at index 16, which is out of bounds.", CWE_BUFFER_OVERRUN, Certainty::normal); @@ -440,7 +441,10 @@ void CheckBufferOverrunImpl::arrayIndexError(const Token* tok, index = &indexValue; } - reportError(getErrorPath(tok, index, "Array index out of bounds"), + const ErrorPath errorPathTok = getErrorPath(tok, index, "Array index out of bounds"); + errorPath.insert(errorPath.end(), errorPathTok.begin(), errorPathTok.end()); + + reportError(errorPath, index->errorSeverity() ? Severity::error : Severity::warning, index->condition ? "arrayIndexOutOfBoundsCond" : "arrayIndexOutOfBounds", arrayIndexMessage(tok, dimensions, indexes, condition), @@ -1342,7 +1346,7 @@ void CheckBufferOverrun::runChecks(const Tokenizer &tokenizer, ErrorLogger& erro void CheckBufferOverrun::getErrorMessages(ErrorLogger& errorLogger, const Settings &settings) const { CheckBufferOverrunImpl c(nullptr, settings, errorLogger); - c.arrayIndexError(nullptr, std::vector(), std::vector()); + c.arrayIndexError(nullptr, std::vector(), std::vector(), {}); c.pointerArithmeticError(nullptr, nullptr, nullptr); c.negativeIndexError(nullptr, std::vector(), std::vector()); c.arrayIndexThenCheckError(nullptr, "i"); diff --git a/lib/checkbufferoverrun.h b/lib/checkbufferoverrun.h index afac19d796c..7564900fdcc 100644 --- a/lib/checkbufferoverrun.h +++ b/lib/checkbufferoverrun.h @@ -102,7 +102,8 @@ class CPPCHECKLIB CheckBufferOverrunImpl : public CheckImpl void arrayIndex(); void arrayIndexError(const Token* tok, const std::vector& dimensions, - const std::vector& indexes); + const std::vector& indexes, + ErrorPath errorPath); void negativeIndexError(const Token* tok, const std::vector& dimensions, const std::vector& indexes); diff --git a/lib/token.cpp b/lib/token.cpp index 3f8e2a88d4c..d9ec6c9a909 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -1978,12 +1978,13 @@ const ValueFlow::Value * Token::getInvalidValue(const Token *ftok, nonneg int ar return ret; } -const Token *Token::getValueTokenMinStrSize(const Settings &settings, MathLib::bigint* path) const +const Token *Token::getValueTokenMinStrSize(const Settings &settings, MathLib::bigint* path, ErrorPath* errorPath) const { if (!mImpl->mValues) return nullptr; const Token *ret = nullptr; int minsize = INT_MAX; + auto itMin = mImpl->mValues->end(); for (auto it = mImpl->mValues->begin(); it != mImpl->mValues->end(); ++it) { if (it->isTokValue() && it->tokvalue && it->tokvalue->tokType() == Token::eString) { const int size = getStrSize(it->tokvalue, settings); @@ -1992,9 +1993,12 @@ const Token *Token::getValueTokenMinStrSize(const Settings &settings, MathLib::b ret = it->tokvalue; if (path) *path = it->path; + itMin = it; } } } + if (errorPath && itMin != mImpl->mValues->end()) + errorPath->insert(errorPath->end(), itMin->errorPath.begin(), itMin->errorPath.end()); return ret; } diff --git a/lib/token.h b/lib/token.h index 5e200f63b9c..cf38191dbfa 100644 --- a/lib/token.h +++ b/lib/token.h @@ -1415,7 +1415,7 @@ class CPPCHECKLIB Token { const ValueFlow::Value* getContainerSizeValue(MathLib::bigint val) const; const Token *getValueTokenMaxStrLength() const; - const Token *getValueTokenMinStrSize(const Settings &settings, MathLib::bigint* path = nullptr) const; + const Token *getValueTokenMinStrSize(const Settings &settings, MathLib::bigint* path = nullptr, ErrorPath* errorPath = nullptr) const; /** Add token value. Return true if value is added. */ bool addValue(const ValueFlow::Value &value); diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 0e0bf5ce385..eba322b443c 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -442,7 +442,7 @@ class TestBufferOverrun : public TestFixture { " str[i] = 0;\n" "}\n" "void b() { a(16); }\n"); - ASSERT_EQUALS("[test.cpp:4:8]: (error) Array 'str[16]' accessed at index 16, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:15] -> [test.cpp:4:8]: (error) Array 'str[16]' accessed at index 16, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_4() { @@ -1304,7 +1304,7 @@ class TestBufferOverrun : public TestFixture { " p[10] = 7;\n" " free(p);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4:4]: (error) Array 'p[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14] -> [test.cpp:4:4]: (error) Array 'p[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" @@ -1312,7 +1312,7 @@ class TestBufferOverrun : public TestFixture { " p[10] = 7;\n" " free(p);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4:4]: (error) Array 'p[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:15] -> [test.cpp:4:4]: (error) Array 'p[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" @@ -2711,14 +2711,14 @@ class TestBufferOverrun : public TestFixture { " const char *str = \"abc\";\n" " bar(str[10]);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3:12]: (error) Array 'str[4]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:23] -> [test.cpp:3:12]: (error) Array 'str[4]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" " const char *str = \"abc\";\n" " bar(str[4]);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4:12]: (error) Array 'str[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:23] -> [test.cpp:4:12]: (error) Array 'str[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" @@ -2732,7 +2732,7 @@ class TestBufferOverrun : public TestFixture { " const char *str = \"a\tc\";\n" " bar(str[4]);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4:12]: (error) Array 'str[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:23] -> [test.cpp:4:12]: (error) Array 'str[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" // #6973 " const char *name = \"\";\n" @@ -2937,7 +2937,7 @@ class TestBufferOverrun : public TestFixture { " p[5] = 1;\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:4:6]: (error) Array 'p[3]' accessed at index 5, which is out of bounds. [arrayIndexOutOfBounds]\n", + "[test.cpp:3:20] -> [test.cpp:4:6]: (error) Array 'p[3]' accessed at index 5, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" @@ -3032,7 +3032,7 @@ class TestBufferOverrun : public TestFixture { " z[n] = 0;\n" " delete[] z;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4:10]: (error) Array 'z[1]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:4:10]: (error) Array 'z[1]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " int* z = new int(1);\n" @@ -3040,7 +3040,7 @@ class TestBufferOverrun : public TestFixture { " z[n] = 0;\n" " delete[] z;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4:10]: (error) Array 'z[1]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:4:10]: (error) Array 'z[1]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " int* z = new int{};\n" @@ -3048,7 +3048,7 @@ class TestBufferOverrun : public TestFixture { " z[n] = 0;\n" " delete[] z;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4:10]: (error) Array 'z[1]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:4:10]: (error) Array 'z[1]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " int* z = new int[5];\n" @@ -3056,7 +3056,7 @@ class TestBufferOverrun : public TestFixture { " z[n] = 0;\n" " delete[] z;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void g() {\n" " int* z = new int[5]();\n" @@ -3064,7 +3064,7 @@ class TestBufferOverrun : public TestFixture { " z[n] = 1;\n" " delete[] z;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void h() {\n" " int** z = new int* [5];\n" @@ -3072,7 +3072,7 @@ class TestBufferOverrun : public TestFixture { " z[n] = nullptr;\n" " delete[] z;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void h() {\n" " int** z = new int* [5]();\n" @@ -3080,7 +3080,7 @@ class TestBufferOverrun : public TestFixture { " z[n] = nullptr;\n" " delete[] z;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void h() {\n" " int** z = new int* [5]{};\n" @@ -3088,7 +3088,7 @@ class TestBufferOverrun : public TestFixture { " z[n] = nullptr;\n" " delete[] z;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void h() {\n" " int** z = new int* [5]{ 0 };\n" @@ -3096,7 +3096,7 @@ class TestBufferOverrun : public TestFixture { " z[n] = nullptr;\n" " delete[] z;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void buffer_overrun_2_struct() { @@ -3799,6 +3799,17 @@ class TestBufferOverrun : public TestFixture { "[test.cpp:9:14]: note: Assignment 'j=-1', assigned value is -1\n" "[test.cpp:10:9]: note: Assuming condition is false\n" "[test.cpp:12:13]: note: Negative array index\n", errout_str()); + + check("char g(const char* s) {\n" // #10253 + " return s[6];\n" + "}\n" + "void f() {\n" + " g(\"abc\");\n" + "}\n", s); + ASSERT_EQUALS("[test.cpp:2:13]: error: Array 's[4]' accessed at index 6, which is out of bounds. [arrayIndexOutOfBounds]\n" + "[test.cpp:5:7]: note: Calling function 'g', 1st argument '\"abc\"' value is \"abc\"\n" + "[test.cpp:2:13]: note: Array index out of bounds\n", + errout_str()); } void buffer_overrun_bailoutIfSwitch() { @@ -4071,7 +4082,7 @@ class TestBufferOverrun : public TestFixture { " if (cond) x = \"abcde\";\n" " return x[20];\n" // <- array index out of bounds when x is "abcde" "}\n"); - ASSERT_EQUALS("[test.cpp:4:11]: (error) Array 'x[6]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:17] -> [test.cpp:3:7] -> [test.cpp:4:11]: (error) Array 'x[6]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void pointer_out_of_bounds_1() { @@ -4311,7 +4322,7 @@ class TestBufferOverrun : public TestFixture { " char *s; s = new char[10];\n" " s[10] = 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16] -> [test.cpp:4:6]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); // ticket #1670 - false negative when using return check("char f()\n" @@ -4319,7 +4330,7 @@ class TestBufferOverrun : public TestFixture { " int *s; s = new int[10];\n" " return s[10];\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4:13]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:15] -> [test.cpp:4:13]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("struct Fred { char c[10]; };\n" "char f()\n" @@ -4352,7 +4363,7 @@ class TestBufferOverrun : public TestFixture { " buf[9] = 0;\n" " delete [] buf;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6:6]: (error) Array 'buf[9]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:7] -> [test.cpp:6:6]: (error) Array 'buf[9]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void foo()\n" "{\n" @@ -4360,7 +4371,7 @@ class TestBufferOverrun : public TestFixture { " char *s; s = new char[Size];\n" " s[Size] = 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5:6]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:16] -> [test.cpp:5:6]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void foo()\n" "{\n" @@ -4368,7 +4379,7 @@ class TestBufferOverrun : public TestFixture { " E *e; e = new E[10];\n" " e[10] = ZERO;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5:6]: (error) Array 'e[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13] -> [test.cpp:5:6]: (error) Array 'e[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } // data is allocated with malloc @@ -4378,14 +4389,14 @@ class TestBufferOverrun : public TestFixture { " char *s; s = (char *)malloc(10);\n" " s[10] = 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16] -> [test.cpp:4:6]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); // ticket #842 check("void f() {\n" " int *tab4 = (int *)malloc(20 * sizeof(int));\n" " tab4[20] = 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15] -> [test.cpp:3:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); // ticket #1478 check("void foo() {\n" @@ -4394,7 +4405,7 @@ class TestBufferOverrun : public TestFixture { " p = (char *)malloc(10);\n" " p[10] = 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5:6]: (error) Array 'p[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7] -> [test.cpp:5:6]: (error) Array 'p[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); // ticket #1134 check("void f() {\n" @@ -4402,7 +4413,7 @@ class TestBufferOverrun : public TestFixture { " x = (int *)malloc(10 * sizeof(int));\n" " x[10] = 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 'x[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:7] -> [test.cpp:4:6]: (error) Array 'x[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " int *tab4; tab4 = malloc(20 * sizeof(int));\n" @@ -4428,21 +4439,21 @@ class TestBufferOverrun : public TestFixture { " E *tab4 = (E *)malloc(Size * 4);\n" " tab4[Size] = Size;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13] -> [test.cpp:4:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " enum E { Size = 20 };\n" " E *tab4 = (E *)malloc(4 * Size);\n" " tab4[Size] = Size;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13] -> [test.cpp:4:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " enum E { ZERO };\n" " E *tab4 = (E *)malloc(20 * sizeof(E));\n" " tab4[20] = ZERO;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13] -> [test.cpp:4:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" // #8721 " unsigned char **cache = malloc(32);\n" @@ -4456,14 +4467,14 @@ class TestBufferOverrun : public TestFixture { " for (int i = 0; i < 3; i++)\n" " a[i] = NULL;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:4:6]: (error) Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " int **a = new int*[2];\n" " for (int i = 0; i < 3; i++)\n" " a[i] = NULL;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:4:6]: (error) Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f(const uint8_t* a) {\n" // 10421 " uint8_t* p = (uint8_t*)malloc(20U * sizeof(uint8_t));\n" @@ -4472,7 +4483,7 @@ class TestBufferOverrun : public TestFixture { " p[i] = a[i];\n" " free(p);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5:10]: (error) Array 'p[20]' accessed at index 29, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16] -> [test.cpp:3:9] -> [test.cpp:5:10]: (error) Array 'p[20]' accessed at index 29, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } // statically allocated buffer @@ -4482,14 +4493,14 @@ class TestBufferOverrun : public TestFixture { " const char *s = \"123\";\n" " s[10] = 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 's[4]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:21] -> [test.cpp:4:6]: (error) Array 's[4]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void foo()\n" "{\n" " char *s; s = \"\";\n" " s[10] = 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 's[1]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:18] -> [test.cpp:4:6]: (error) Array 's[1]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void foo() {\n" " const char *s = \"\";\n"