Skip to content

Commit ee39f64

Browse files
committed
reverted fix for cppcheck-opensource#3168, I'll rewrite it
1 parent 897e863 commit ee39f64

3 files changed

Lines changed: 14 additions & 33 deletions

File tree

‎lib/checkbufferoverrun.cpp‎

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ void CheckBufferOverrun::parse_for_body(const Token *tok2, const ArrayInfo &arra
514514

515515

516516

517-
void CheckBufferOverrun::checkFunctionParameter(const Token &tok, unsigned int par, const ArrayInfo &arrayInfo, std::list<std::string> functionNames)
517+
void CheckBufferOverrun::checkFunctionParameter(const Token &tok, unsigned int par, const ArrayInfo &arrayInfo)
518518
{
519519
// total_size : which parameter in function call takes the total size?
520520
std::map<std::string, unsigned int> total_size;
@@ -677,31 +677,21 @@ void CheckBufferOverrun::checkFunctionParameter(const Token &tok, unsigned int p
677677
}
678678
}
679679
}
680-
681-
// Calling function..
682-
if (Token::Match(ftok, "%var% (")) {
683-
ArrayInfo ai(arrayInfo);
684-
ai.varid(parameterVarId);
685-
checkFunctionCall(ftok, ai, functionNames);
686-
}
687680
}
688681
}
689682
}
690683
}
691684

692685

693-
void CheckBufferOverrun::checkFunctionCall(const Token *tok, const ArrayInfo &arrayInfo, std::list<std::string> functionNames)
686+
void CheckBufferOverrun::checkFunctionCall(const Token *tok, const ArrayInfo &arrayInfo)
694687
{
695-
if (std::find(functionNames.begin(), functionNames.end(), tok->str()) != functionNames.end())
696-
return;
697-
functionNames.push_back(tok->str());
698688

699689
// 1st parameter..
700690
if (Token::Match(tok->tokAt(2), "%varid% ,|)", arrayInfo.varid()))
701-
checkFunctionParameter(*tok, 1, arrayInfo, functionNames);
691+
checkFunctionParameter(*tok, 1, arrayInfo);
702692
else if (Token::Match(tok->tokAt(2), "%varid% + %num% ,|)", arrayInfo.varid())) {
703693
const ArrayInfo ai(arrayInfo.limit(MathLib::toLongNumber(tok->strAt(4))));
704-
checkFunctionParameter(*tok, 1, ai, functionNames);
694+
checkFunctionParameter(*tok, 1, ai);
705695
}
706696

707697
// goto 2nd parameter and check it..
@@ -714,10 +704,10 @@ void CheckBufferOverrun::checkFunctionCall(const Token *tok, const ArrayInfo &ar
714704
break;
715705
if (tok2->str() == ",") {
716706
if (Token::Match(tok2, ", %varid% ,|)", arrayInfo.varid()))
717-
checkFunctionParameter(*tok, 2, arrayInfo, functionNames);
707+
checkFunctionParameter(*tok, 2, arrayInfo);
718708
else if (Token::Match(tok2, ", %varid% + %num% ,|)", arrayInfo.varid())) {
719709
const ArrayInfo ai(arrayInfo.limit(MathLib::toLongNumber(tok2->strAt(3))));
720-
checkFunctionParameter(*tok, 2, ai, functionNames);
710+
checkFunctionParameter(*tok, 2, ai);
721711
}
722712
break;
723713
}
@@ -911,9 +901,9 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
911901
// memset, memcmp, memcpy, strncpy, fgets..
912902
if (varid == 0 && size > 0) {
913903
if (Token::Match(tok, ("%var% ( " + varnames + " ,").c_str()))
914-
checkFunctionParameter(*tok, 1, arrayInfo, std::list<std::string>());
904+
checkFunctionParameter(*tok, 1, arrayInfo);
915905
if (Token::Match(tok, ("%var% ( %var% , " + varnames + " ,").c_str()))
916-
checkFunctionParameter(*tok, 2, arrayInfo, std::list<std::string>());
906+
checkFunctionParameter(*tok, 2, arrayInfo);
917907
}
918908

919909
// Loop..
@@ -985,8 +975,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
985975
continue;
986976

987977
const ArrayInfo arrayInfo1(varid, varnames, total_size / size, size);
988-
const std::list<std::string> functionNames;
989-
checkFunctionCall(tok, arrayInfo1, functionNames);
978+
checkFunctionCall(tok, arrayInfo1);
990979
}
991980

992981
// undefined behaviour: result of pointer arithmetic is out of bounds
@@ -1110,7 +1099,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo
11101099

11111100
// Check function call..
11121101
if (Token::Match(tok, "%var% (")) {
1113-
checkFunctionCall(tok, arrayInfo, std::list<std::string>());
1102+
checkFunctionCall(tok, arrayInfo);
11141103
}
11151104

11161105
if (Token::Match(tok, "strncpy|memcpy|memmove ( %varid% , %str% , %num% )", arrayInfo.varid())) {

‎lib/checkbufferoverrun.h‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,17 +203,15 @@ class CheckBufferOverrun : public Check {
203203
* \param tok token for the function name
204204
* \param par on what parameter is the array used
205205
* \param arrayInfo the array information
206-
* \param functionNames function names (to prevent endless recursion)
207206
*/
208-
void checkFunctionParameter(const Token &tok, const unsigned int par, const ArrayInfo &arrayInfo, std::list<std::string> functionNames);
207+
void checkFunctionParameter(const Token &tok, const unsigned int par, const ArrayInfo &arrayInfo);
209208

210209
/**
211210
* Helper function that checks if the array is used and if so calls the checkFunctionCall
212211
* @param tok token that matches "%var% ("
213212
* @param arrayInfo the array information
214-
* \param functionNames function names (to prevent endless recursion)
215213
*/
216-
void checkFunctionCall(const Token *tok, const ArrayInfo &arrayInfo, std::list<std::string> functionNames);
214+
void checkFunctionCall(const Token *tok, const ArrayInfo &arrayInfo);
217215

218216
void arrayIndexOutOfBoundsError(const Token *tok, const ArrayInfo &arrayInfo, const std::vector<MathLib::bigint> &index);
219217
void arrayIndexOutOfBoundsError(const std::list<const Token *> &callstack, const ArrayInfo &arrayInfo, const std::vector<MathLib::bigint> &index);

‎test/testbufferoverrun.cpp‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class TestBufferOverrun : public TestFixture {
3333

3434
private:
3535

36+
37+
3638
void check(const char code[], bool experimental = true, const std::string &filename="test.cpp") {
3739
// Clear the error buffer..
3840
errout.str("");
@@ -722,14 +724,6 @@ class TestBufferOverrun : public TestFixture {
722724
" foo(p+1);\n"
723725
"}\n");
724726
ASSERT_EQUALS("", errout.str());
725-
726-
// #3168
727-
check("void a(char *p) { memset(p,0,100); }\n"
728-
"void b() {\n"
729-
" char buf[10];\n"
730-
" a(buf);"
731-
"}");
732-
ASSERT_EQUALS("[test.cpp:1]: (error) Buffer access out-of-bounds: buf\n", errout.str());
733727
}
734728

735729

0 commit comments

Comments
 (0)