2nd attempt to fix crash in CheckUnusedFunctions::check. CheckBufferOverrun::checkBufferAllocatedWithStrlen: Don't check for 'new' in C code.
This commit is contained in:
parent
02a3a01eca
commit
0b225fa02f
|
@ -1520,7 +1520,7 @@ void CheckBufferOverrun::checkBufferAllocatedWithStrlen()
|
||||||
dstVarId = tok->varId();
|
dstVarId = tok->varId();
|
||||||
srcVarId = tok->tokAt(6)->varId();
|
srcVarId = tok->tokAt(6)->varId();
|
||||||
tok = tok->tokAt(8);
|
tok = tok->tokAt(8);
|
||||||
} else if (Token::Match(tok, "%var% = new char [ strlen ( %name% ) ]")) {
|
} else if (_tokenizer->isCPP() && Token::Match(tok, "%var% = new char [ strlen ( %name% ) ]")) {
|
||||||
dstVarId = tok->varId();
|
dstVarId = tok->varId();
|
||||||
srcVarId = tok->tokAt(7)->varId();
|
srcVarId = tok->tokAt(7)->varId();
|
||||||
tok = tok->tokAt(9);
|
tok = tok->tokAt(9);
|
||||||
|
|
|
@ -209,14 +209,14 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void CheckUnusedFunctions::check(ErrorLogger * const errorLogger)
|
void CheckUnusedFunctions::check(ErrorLogger * const errorLogger, const Settings& settings)
|
||||||
{
|
{
|
||||||
for (std::map<std::string, FunctionUsage>::const_iterator it = _functions.begin(); it != _functions.end(); ++it) {
|
for (std::map<std::string, FunctionUsage>::const_iterator it = _functions.begin(); it != _functions.end(); ++it) {
|
||||||
const FunctionUsage &func = it->second;
|
const FunctionUsage &func = it->second;
|
||||||
if (func.usedOtherFile || func.filename.empty())
|
if (func.usedOtherFile || func.filename.empty())
|
||||||
continue;
|
continue;
|
||||||
if (it->first == "main" ||
|
if (it->first == "main" ||
|
||||||
(_settings->isWindowsPlatform() && (it->first == "WinMain" || it->first == "_tmain")) ||
|
(settings.isWindowsPlatform() && (it->first == "WinMain" || it->first == "_tmain")) ||
|
||||||
it->first == "if" ||
|
it->first == "if" ||
|
||||||
(it->first.compare(0, 8, "operator") == 0 && it->first.size() > 8 && !std::isalnum(it->first[8])))
|
(it->first.compare(0, 8, "operator") == 0 && it->first.size() > 8 && !std::isalnum(it->first[8])))
|
||||||
continue;
|
continue;
|
||||||
|
@ -268,5 +268,5 @@ Check::FileInfo *CheckUnusedFunctions::getFileInfo(const Tokenizer *tokenizer, c
|
||||||
void CheckUnusedFunctions::analyseWholeProgram(const std::list<Check::FileInfo*> &fileInfo, const Settings& settings, ErrorLogger &errorLogger)
|
void CheckUnusedFunctions::analyseWholeProgram(const std::list<Check::FileInfo*> &fileInfo, const Settings& settings, ErrorLogger &errorLogger)
|
||||||
{
|
{
|
||||||
(void)fileInfo;
|
(void)fileInfo;
|
||||||
check(&errorLogger);
|
check(&errorLogger, settings);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ public:
|
||||||
// * What functions are declared
|
// * What functions are declared
|
||||||
void parseTokens(const Tokenizer &tokenizer, const char FileName[], const Settings *settings);
|
void parseTokens(const Tokenizer &tokenizer, const char FileName[], const Settings *settings);
|
||||||
|
|
||||||
void check(ErrorLogger * const errorLogger);
|
void check(ErrorLogger * const errorLogger, const Settings& settings);
|
||||||
|
|
||||||
/** @brief Parse current TU and extract file info */
|
/** @brief Parse current TU and extract file info */
|
||||||
Check::FileInfo *getFileInfo(const Tokenizer *tokenizer, const Settings *settings) const;
|
Check::FileInfo *getFileInfo(const Tokenizer *tokenizer, const Settings *settings) const;
|
||||||
|
|
|
@ -72,7 +72,7 @@ private:
|
||||||
// Check for unused functions..
|
// Check for unused functions..
|
||||||
CheckUnusedFunctions checkUnusedFunctions(&tokenizer, &settings, this);
|
CheckUnusedFunctions checkUnusedFunctions(&tokenizer, &settings, this);
|
||||||
checkUnusedFunctions.parseTokens(tokenizer, "someFile.c", &settings);
|
checkUnusedFunctions.parseTokens(tokenizer, "someFile.c", &settings);
|
||||||
checkUnusedFunctions.check(this);
|
checkUnusedFunctions.check(this, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
void incondition() {
|
void incondition() {
|
||||||
|
@ -349,8 +349,6 @@ private:
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
Settings settings;
|
|
||||||
|
|
||||||
Tokenizer tokenizer2(&settings, this);
|
Tokenizer tokenizer2(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer2.tokenize(istr, fname.str().c_str());
|
tokenizer2.tokenize(istr, fname.str().c_str());
|
||||||
|
@ -359,7 +357,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for unused functions..
|
// Check for unused functions..
|
||||||
c.check(this);
|
c.check(this, settings);
|
||||||
|
|
||||||
ASSERT_EQUALS("[test1.cpp:1]: (style) The function 'f' is never used.\n", errout.str());
|
ASSERT_EQUALS("[test1.cpp:1]: (style) The function 'f' is never used.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue