diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index aaeff55d5..c3ac0ddc8 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -47,21 +47,6 @@ CheckBufferOverrun instance; //--------------------------------------------------------------------------- -void CheckBufferOverrun::arrayIndexOutOfBoundsError(const Token *tok, MathLib::bigint size, MathLib::bigint index) -{ - if (size >= 1) - { - std::ostringstream errmsg; - errmsg << "Array '"; - if (tok) - errmsg << tok->str(); - else - errmsg << "array"; - errmsg << "[" << size << "]' index " << index << " out of bounds"; - reportError(tok, Severity::error, "arrayIndexOutOfBounds", errmsg.str().c_str()); - } -} - void CheckBufferOverrun::arrayIndexOutOfBoundsError(const Token *tok, const ArrayInfo &arrayInfo, const std::vector &index) { std::ostringstream oss; @@ -557,11 +542,15 @@ void CheckBufferOverrun::parse_for_body(const Token *tok2, const ArrayInfo &arra //printf("min_index = %d, max_index = %d, size = %d\n", min_index, max_index, size); if (min_index < 0 || max_index < 0) { - arrayIndexOutOfBoundsError(tok2, (int)arrayInfo.num(0), std::min(min_index, max_index)); + std::vector indexes; + indexes.push_back(std::min(min_index, max_index)); + arrayIndexOutOfBoundsError(tok2, arrayInfo, indexes); } if (min_index >= (int)arrayInfo.num(0) || max_index >= (int)arrayInfo.num(0)) { - arrayIndexOutOfBoundsError(tok2, (int)arrayInfo.num(0), std::max(min_index, max_index)); + std::vector indexes; + indexes.push_back(std::max(min_index, max_index)); + arrayIndexOutOfBoundsError(tok2, arrayInfo, indexes); } } } @@ -890,7 +879,9 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vectorstrAt(2)); if (index >= size) { - arrayIndexOutOfBoundsError(tok, size, index); + std::vector indexes; + indexes.push_back(index); + arrayIndexOutOfBoundsError(tok, info, indexes); } } } @@ -899,7 +890,9 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vectorstrAt(2 + varc)); if (index >= size) { - arrayIndexOutOfBoundsError(tok->tokAt(varc), size, index); + std::vector indexes; + indexes.push_back(index); + arrayIndexOutOfBoundsError(tok->tokAt(varc), info, indexes); } } @@ -945,7 +938,9 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector size || !Token::simpleMatch(tok->previous(), "& (")) { - arrayIndexOutOfBoundsError(tok->next(), size, index); + std::vector indexes; + indexes.push_back(index); + arrayIndexOutOfBoundsError(tok->next(), info, indexes); } } } @@ -954,7 +949,9 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vectorstrAt(3)); if (index < 0 || index >= size) { - arrayIndexOutOfBoundsError(tok->next(), size, index); + std::vector indexes; + indexes.push_back(index); + arrayIndexOutOfBoundsError(tok->next(), info, indexes); } } } @@ -963,7 +960,9 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vectorstrAt(3 + varc)); if (index >= size) { - arrayIndexOutOfBoundsError(tok->tokAt(1 + varc), size, index); + std::vector indexes; + indexes.push_back(index); + arrayIndexOutOfBoundsError(tok->tokAt(1 + varc), info, indexes); } tok = tok->tokAt(4); continue; @@ -1486,7 +1485,7 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable() continue; std::vector v; - ArrayInfo temp(varid, "", total_size / size, size); + ArrayInfo temp(varid, tok->next()->str(), total_size / size, size); checkScope(tok->tokAt(nextTok), v, temp); } } diff --git a/lib/checkbufferoverrun.h b/lib/checkbufferoverrun.h index 7c014d44c..26bdf3bb1 100644 --- a/lib/checkbufferoverrun.h +++ b/lib/checkbufferoverrun.h @@ -217,7 +217,6 @@ public: */ void checkFunctionCall(const Token *tok, const ArrayInfo &arrayInfo); - void arrayIndexOutOfBoundsError(const Token *tok, MathLib::bigint size, MathLib::bigint index); void arrayIndexOutOfBoundsError(const Token *tok, const ArrayInfo &arrayInfo, const std::vector &index); void arrayIndexOutOfBoundsError(const std::list &callstack, const ArrayInfo &arrayInfo, const std::vector &index); void bufferOverrunError(const Token *tok, const std::string &varnames = ""); @@ -235,7 +234,9 @@ public: void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { CheckBufferOverrun c(0, settings, errorLogger); - c.arrayIndexOutOfBoundsError(0, 2, 2); + std::vector indexes; + indexes.push_back(2); + c.arrayIndexOutOfBoundsError(0, ArrayInfo(0, "array", 1, 2), indexes); c.bufferOverrunError(0, std::string("buffer")); c.strncatUsageError(0); c.outOfBoundsError(0, "index");