Skip to content

Commit 2c73518

Browse files
committed
Fix platform-dependent test result, formatting and crash in whole program analysis
1 parent 4a47b8b commit 2c73518

10 files changed

Lines changed: 20 additions & 21 deletions

lib/check.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ class CPPCHECKLIB Check {
9797
return nullptr;
9898
}
9999

100-
virtual void analyseWholeProgram(const std::list<FileInfo*> &fileInfo, ErrorLogger &errorLogger) {
100+
virtual void analyseWholeProgram(const std::list<FileInfo*> &fileInfo, const Settings& settings, ErrorLogger &errorLogger) {
101101
(void)fileInfo;
102+
(void)settings;
102103
(void)errorLogger;
103104
}
104105

lib/checkbufferoverrun.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1797,7 +1797,7 @@ Check::FileInfo* CheckBufferOverrun::getFileInfo(const Tokenizer *tokenizer, con
17971797
return fileInfo;
17981798
}
17991799

1800-
void CheckBufferOverrun::analyseWholeProgram(const std::list<Check::FileInfo*> &fileInfo, ErrorLogger &errorLogger)
1800+
void CheckBufferOverrun::analyseWholeProgram(const std::list<Check::FileInfo*> &fileInfo, const Settings& settings, ErrorLogger &errorLogger)
18011801
{
18021802
// Merge all fileInfo
18031803
MyFileInfo all;

lib/checkbufferoverrun.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class CPPCHECKLIB CheckBufferOverrun : public Check {
212212
Check::FileInfo *getFileInfo(const Tokenizer *tokenizer, const Settings *settings) const;
213213

214214
/** @brief Analyse all file infos for all TU */
215-
void analyseWholeProgram(const std::list<Check::FileInfo*> &fileInfo, ErrorLogger &errorLogger);
215+
void analyseWholeProgram(const std::list<Check::FileInfo*> &fileInfo, const Settings& settings, ErrorLogger &errorLogger);
216216

217217
private:
218218

lib/checkmemoryleak.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,8 +1379,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
13791379

13801380
void CheckMemoryLeakInFunction::simplifycode(Token *tok) const
13811381
{
1382-
if (_tokenizer->isCPP())
1383-
{
1382+
if (_tokenizer->isCPP()) {
13841383
// Replace "throw" that is not in a try block with "return"
13851384
int indentlevel = 0;
13861385
int trylevel = -1;

lib/checknonreentrantfunctions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void CheckNonReentrantFunctions::nonReentrantFunctions()
5757
continue;
5858

5959
// Check for "std" or global namespace, ignore other namespaces
60-
if (_tokenizer->isCPP() && prev->str() == "::" && prev->previous() && prev->previous()->str() != "std" && prev->previous()->isName())
60+
if (_tokenizer->isCPP() && prev->str() == "::" && prev->previous() && prev->previous()->str() != "std" && prev->previous()->isName())
6161
continue;
6262
}
6363

lib/checkunusedfunctions.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi
5151
continue;
5252

5353
// Don't care about templates
54-
if (tokenizer.isCPP() && func->retDef->str() == "template")
54+
if (tokenizer.isCPP() && func->retDef->str() == "template")
5555
continue;
5656

5757
FunctionUsage &usage = _functions[func->name()];
@@ -216,7 +216,7 @@ void CheckUnusedFunctions::check(ErrorLogger * const errorLogger)
216216
if (func.usedOtherFile || func.filename.empty())
217217
continue;
218218
if (it->first == "main" ||
219-
(_settings->isWindowsPlatform() && (it->first == "WinMain" || it->first == "_tmain")) ||
219+
(_settings->isWindowsPlatform() && (it->first == "WinMain" || it->first == "_tmain")) ||
220220
it->first == "if" ||
221221
(it->first.compare(0, 8, "operator") == 0 && it->first.size() > 8 && !std::isalnum(it->first[8])))
222222
continue;
@@ -268,5 +268,5 @@ Check::FileInfo *CheckUnusedFunctions::getFileInfo(const Tokenizer *tokenizer, c
268268
void CheckUnusedFunctions::analyseWholeProgram(const std::list<Check::FileInfo*> &fileInfo, ErrorLogger &errorLogger)
269269
{
270270
(void)fileInfo;
271-
instance.check(&errorLogger);
271+
check(&errorLogger);
272272
}

lib/cppcheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ void CppCheck::analyseWholeProgram()
690690
{
691691
// Analyse the tokens
692692
for (std::list<Check *>::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
693-
(*it)->analyseWholeProgram(fileInfo, *this);
693+
(*it)->analyseWholeProgram(fileInfo, _settings, *this);
694694
}
695695

696696
bool CppCheck::unusedFunctionCheckIsEnabled() const

lib/tokenize.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9859,7 +9859,7 @@ namespace {
98599859
void Tokenizer::simplifyMicrosoftStringFunctions()
98609860
{
98619861
// skip if not Windows
9862-
if (!_settings->isWindowsPlatform())
9862+
if (!_settings->isWindowsPlatform())
98639863
return;
98649864

98659865
const bool ansi = _settings->platformType == Settings::Win32A;
@@ -9892,7 +9892,7 @@ void Tokenizer::simplifyMicrosoftStringFunctions()
98929892
void Tokenizer::simplifyBorland()
98939893
{
98949894
// skip if not Windows
9895-
if (!_settings->isWindowsPlatform())
9895+
if (!_settings->isWindowsPlatform())
98969896
return;
98979897
if (isC())
98989898
return;
@@ -9909,8 +9909,7 @@ void Tokenizer::simplifyBorland()
99099909
tok = tok->link();
99109910
if (!tok)
99119911
break;
9912-
}
9913-
else if (Token::Match(tok, "class %name% :|{")) {
9912+
} else if (Token::Match(tok, "class %name% :|{")) {
99149913
while (tok && tok->str() != "{" && tok->str() != ";")
99159914
tok = tok->next();
99169915
if (!tok)

test/testmemleak.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ class TestMemleakInFunction : public TestFixture {
672672
}
673673
}
674674

675-
Tokenizer tokenizer;
675+
Tokenizer tokenizer;
676676
CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, this);
677677
checkMemoryLeak.simplifycode(tokens);
678678

test/testunusedfunctions.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ class TestUnusedFunctions : public TestFixture {
5757
TEST_CASE(ignore_declaration); // ignore declaration
5858
}
5959

60-
void check(const char code[]) {
60+
void check(const char code[], Settings::PlatformType platform = Settings::Unspecified) {
6161
// Clear the error buffer..
6262
errout.str("");
6363

6464
Settings settings;
6565
settings.addEnabled("style");
66-
66+
settings.platform(platform);
6767
// Tokenize..
6868
Tokenizer tokenizer(&settings, this);
6969
std::istringstream istr(code);
@@ -228,10 +228,10 @@ class TestUnusedFunctions : public TestFixture {
228228
check("int main() { }");
229229
ASSERT_EQUALS("", errout.str());
230230

231-
check("int _tmain() { }");
231+
check("int _tmain() { }", Settings::Win32A);
232232
ASSERT_EQUALS("", errout.str());
233233

234-
check("int WinMain() { }");
234+
check("int WinMain() { }", Settings::Win32A);
235235
ASSERT_EQUALS("", errout.str());
236236
}
237237

@@ -334,8 +334,8 @@ class TestUnusedFunctions : public TestFixture {
334334

335335
void multipleFiles() {
336336
Settings settings;
337-
Tokenizer tokenizer(&settings, this);
338-
CheckUnusedFunctions c(&tokenizer, &settings, nullptr);
337+
Tokenizer tokenizer(&settings, this);
338+
CheckUnusedFunctions c(&tokenizer, &settings, nullptr);
339339

340340
// Clear the error buffer..
341341
errout.str("");

0 commit comments

Comments
 (0)