Skip to content

Commit 7d47fd6

Browse files
committed
Renamed --environment to --library. Added --check-library. Renamed Environment to Library
1 parent b7bb16e commit 7d47fd6

File tree

12 files changed

+140
-133
lines changed

12 files changed

+140
-133
lines changed

Makefile

Lines changed: 78 additions & 78 deletions
Large diffs are not rendered by default.

cli/cmdlineparser.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,16 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
314314
}
315315
}
316316

317+
// Check configuration
318+
else if (std::strcmp(argv[i], "--check-config") == 0) {
319+
_settings->checkConfiguration = true;
320+
}
321+
322+
// Check library definitions
323+
else if (std::strcmp(argv[i], "--check-library") == 0) {
324+
_settings->checkLibrary = true;
325+
}
326+
317327
else if (std::strncmp(argv[i], "--enable=", 9) == 0) {
318328
const std::string errmsg = _settings->addEnabled(argv[i] + 9);
319329
if (!errmsg.empty()) {
@@ -328,14 +338,6 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
328338
}
329339
}
330340

331-
// --environment
332-
else if (std::strncmp(argv[i], "--environment=", 14) == 0) {
333-
if (!_settings->environment.load(argv[i]+14)) {
334-
PrintMessage("cppcheck: Failed to load environment file '" + std::string(argv[i]+14) + "'");
335-
return false;
336-
}
337-
}
338-
339341
// --error-exitcode=1
340342
else if (std::strncmp(argv[i], "--error-exitcode=", 17) == 0) {
341343
std::string temp = argv[i]+17;
@@ -478,6 +480,14 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
478480
}
479481
}
480482

483+
// --library
484+
else if (std::strncmp(argv[i], "--library=", 10) == 0) {
485+
if (!_settings->library.load(argv[i]+10)) {
486+
PrintMessage("cppcheck: Failed to load library file '" + std::string(argv[i]+10) + "'");
487+
return false;
488+
}
489+
}
490+
481491
// Report progress
482492
else if (std::strcmp(argv[i], "--report-progress") == 0) {
483493
_settings->reportProgress = true;
@@ -637,11 +647,6 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
637647
}
638648
#endif
639649

640-
// Check configuration
641-
else if (std::strcmp(argv[i], "--check-config") == 0) {
642-
_settings->checkConfiguration = true;
643-
}
644-
645650
// Specify platform
646651
else if (std::strncmp(argv[i], "--platform=", 11) == 0) {
647652
std::string platform(11+argv[i]);
@@ -755,6 +760,7 @@ void CmdLineParser::PrintHelp()
755760
" by providing an implementation for them.\n"
756761
" --check-config Check cppcheck configuration. The normal code\n"
757762
" analysis is disabled by this flag.\n"
763+
" --check-library Warn when library files have incomplete info.\n"
758764
" -D<ID> Define preprocessor symbol. Unless --max-configs or\n"
759765
" --force is used, Cppcheck will only check the given\n"
760766
" configuration when -D is used.\n"

lib/checkleakautovar.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void VarInfo::possibleUsageAll(const std::string &functionName)
7070
void CheckLeakAutoVar::leakError(const Token *tok, const std::string &varname, int type)
7171
{
7272
const CheckMemoryLeak checkmemleak(_tokenizer, _errorLogger, _settings);
73-
if (_settings->environment.isresource(type))
73+
if (_settings->library.isresource(type))
7474
checkmemleak.resourceLeakError(tok, varname);
7575
else
7676
checkmemleak.memleakError(tok, varname);
@@ -96,7 +96,7 @@ void CheckLeakAutoVar::deallocReturnError(const Token *tok, const std::string &v
9696

9797
void CheckLeakAutoVar::configurationInfo(const Token* tok, const std::string &functionName)
9898
{
99-
if (_settings->isEnabled("information") && _settings->experimental) {
99+
if (_settings->checkLibrary) {
100100
reportError(tok,
101101
Severity::information,
102102
"leakconfiguration",
@@ -232,7 +232,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
232232

233233
// allocation?
234234
if (Token::Match(tok->tokAt(2), "%type% (")) {
235-
int i = _settings->environment.alloc(tok->strAt(2));
235+
int i = _settings->library.alloc(tok->strAt(2));
236236
if (i > 0) {
237237
alloctype[tok->varId()] = i;
238238
}
@@ -255,7 +255,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
255255
if (innerTok->str() == ")")
256256
break;
257257
if (innerTok->str() == "(" && innerTok->previous()->isName()) {
258-
const int deallocId = _settings->environment.dealloc(tok->str());
258+
const int deallocId = _settings->library.dealloc(tok->str());
259259
functionCall(innerTok->previous(), varInfo, deallocId);
260260
innerTok = innerTok->link();
261261
}
@@ -335,7 +335,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
335335

336336
// Function call..
337337
else if (Token::Match(tok, "%type% (") && tok->str() != "return") {
338-
const int dealloc = _settings->environment.dealloc(tok->str());
338+
const int dealloc = _settings->library.dealloc(tok->str());
339339

340340
functionCall(tok, varInfo, dealloc);
341341

@@ -345,8 +345,8 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
345345
if (dealloc == NOALLOC && Token::simpleMatch(tok, ") ; }")) {
346346
const std::string &functionName(tok->link()->previous()->str());
347347
bool unknown = false;
348-
if (_settings->environment.ignore.find(functionName) == _settings->environment.ignore.end() &&
349-
_settings->environment.use.find(functionName) == _settings->environment.use.end() &&
348+
if (_settings->library.ignore.find(functionName) == _settings->library.ignore.end() &&
349+
_settings->library.use.find(functionName) == _settings->library.use.end() &&
350350
_tokenizer->IsScopeNoReturn(tok->tokAt(2), &unknown)) {
351351
if (unknown) {
352352
//const std::string &functionName(tok->link()->previous()->str());
@@ -385,7 +385,7 @@ void CheckLeakAutoVar::functionCall(const Token *tok, VarInfo *varInfo, const in
385385
std::map<unsigned int, std::string> &possibleUsage = varInfo->possibleUsage;
386386

387387
// Ignore function call?
388-
const bool ignore = bool(_settings->environment.ignore.find(tok->str()) != _settings->environment.ignore.end());
388+
const bool ignore = bool(_settings->library.ignore.find(tok->str()) != _settings->library.ignore.end());
389389

390390
if (ignore)
391391
return;

lib/checkmemoryleak.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2,
183183
return Dir;
184184

185185
// Does tok2 point on "g_malloc", "g_strdup", ..
186-
const int alloctype = settings1->environment.alloc(tok2->str());
186+
const int alloctype = settings1->library.alloc(tok2->str());
187187
if (alloctype > 0)
188-
return Environment::ismemory(alloctype) ? OtherMem : OtherRes;
188+
return Library::ismemory(alloctype) ? OtherMem : OtherRes;
189189
}
190190

191191
while (Token::Match(tok2,"%type%|%var% ::|. %type%"))
@@ -272,9 +272,9 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType(const Token *tok
272272

273273
// Does tok2 point on "g_free", etc ..
274274
if (Token::Match(tok, "%type% ( %varid% )", varid)) {
275-
const int dealloctype = settings1->environment.dealloc(tok->str());
275+
const int dealloctype = settings1->library.dealloc(tok->str());
276276
if (dealloctype > 0)
277-
return Environment::ismemory(dealloctype) ? OtherMem : OtherRes;
277+
return Library::ismemory(dealloctype) ? OtherMem : OtherRes;
278278
}
279279

280280
return No;
@@ -313,9 +313,9 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType(const Token *tok
313313
return Dir;
314314

315315
if (Token::Match(tok, ("%type% ( " + varname + " )").c_str())) {
316-
int type = settings1->environment.dealloc(tok->str());
316+
int type = settings1->library.dealloc(tok->str());
317317
if (type > 0)
318-
return Environment::ismemory(type) ? OtherMem : OtherRes;
318+
return Library::ismemory(type) ? OtherMem : OtherRes;
319319
}
320320

321321
return No;

lib/cppcheck.vcxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@
6060
<ClCompile Include="checkunusedfunctions.cpp" />
6161
<ClCompile Include="checkunusedvar.cpp" />
6262
<ClCompile Include="cppcheck.cpp" />
63-
<ClCompile Include="environment.cpp" />
6463
<ClCompile Include="errorlogger.cpp" />
6564
<ClCompile Include="executionpath.cpp" />
65+
<ClCompile Include="library.cpp" />
6666
<ClCompile Include="mathlib.cpp" />
6767
<ClCompile Include="path.cpp" />
6868
<ClCompile Include="preprocessor.cpp" />
@@ -103,9 +103,9 @@
103103
<ClInclude Include="checkunusedvar.h" />
104104
<ClInclude Include="config.h" />
105105
<ClInclude Include="cppcheck.h" />
106-
<ClInclude Include="environment.h" />
107106
<ClInclude Include="errorlogger.h" />
108107
<ClInclude Include="executionpath.h" />
108+
<ClInclude Include="library.h" />
109109
<ClInclude Include="mathlib.h" />
110110
<ClInclude Include="path.h" />
111111
<ClInclude Include="preprocessor.h" />
@@ -411,4 +411,4 @@
411411
</ItemDefinitionGroup>
412412
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
413413
<ImportGroup Label="ExtensionTargets" />
414-
</Project>
414+
</Project>

lib/cppcheck.vcxproj.filters

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
<ClCompile Include="checkassert.cpp">
123123
<Filter>Source Files</Filter>
124124
</ClCompile>
125-
<ClCompile Include="environment.cpp">
125+
<ClCompile Include="library.cpp">
126126
<Filter>Source Files</Filter>
127127
</ClCompile>
128128
<ClCompile Include="..\externals\tinyxml\tinyxml2.cpp">
@@ -260,4 +260,4 @@
260260
<ItemGroup>
261261
<ResourceCompile Include="version.rc" />
262262
</ItemGroup>
263-
</Project>
263+
</Project>

lib/lib.pri

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# no manual edits - this file is autogenerated by dmake
22

33
include($$PWD/pcrerules.pri)
4-
BASEPATH = ../externals/tinyxml/
5-
include($$PWD/../externals/tinyxml/tinyxml.pri)
6-
BASEPATH = ../lib/
74
INCLUDEPATH += ../externals/tinyxml
85
HEADERS += $${BASEPATH}check.h \
96
$${BASEPATH}check64bit.h \
@@ -30,9 +27,9 @@ HEADERS += $${BASEPATH}check.h \
3027
$${BASEPATH}checkunusedfunctions.h \
3128
$${BASEPATH}checkunusedvar.h \
3229
$${BASEPATH}cppcheck.h \
33-
$${BASEPATH}environment.h \
3430
$${BASEPATH}errorlogger.h \
3531
$${BASEPATH}executionpath.h \
32+
$${BASEPATH}library.h \
3633
$${BASEPATH}mathlib.h \
3734
$${BASEPATH}path.h \
3835
$${BASEPATH}preprocessor.h \
@@ -70,9 +67,9 @@ SOURCES += $${BASEPATH}check64bit.cpp \
7067
$${BASEPATH}checkunusedfunctions.cpp \
7168
$${BASEPATH}checkunusedvar.cpp \
7269
$${BASEPATH}cppcheck.cpp \
73-
$${BASEPATH}environment.cpp \
7470
$${BASEPATH}errorlogger.cpp \
7571
$${BASEPATH}executionpath.cpp \
72+
$${BASEPATH}library.cpp \
7673
$${BASEPATH}mathlib.cpp \
7774
$${BASEPATH}path.cpp \
7875
$${BASEPATH}preprocessor.cpp \
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
#include "environment.h"
19+
#include "library.h"
2020
#include "tinyxml2.h"
2121

22-
Environment::Environment() : allocid(0)
22+
Library::Library() : allocid(0)
2323
{
2424
while (!ismemory(++allocid));
2525
_alloc["malloc"] = allocid;
@@ -33,14 +33,14 @@ Environment::Environment() : allocid(0)
3333
_dealloc["fclose"] = allocid;
3434
}
3535

36-
Environment::Environment(const Environment &env) : use(env.use), ignore(env.ignore), noreturn(env.noreturn), allocid(env.allocid), _alloc(env._alloc), _dealloc(env._dealloc)
36+
Library::Library(const Library &lib) : use(lib.use), ignore(lib.ignore), noreturn(lib.noreturn), allocid(lib.allocid), _alloc(lib._alloc), _dealloc(lib._dealloc)
3737
{
3838

3939
}
4040

41-
Environment::~Environment() { }
41+
Library::~Library() { }
4242

43-
bool Environment::load(const char path[])
43+
bool Library::load(const char path[])
4444
{
4545
tinyxml2::XMLDocument doc;
4646

lib/environment.h renamed to lib/library.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
#ifndef ENVIRONMENT_H
20-
#define ENVIRONMENT_H
19+
#ifndef libraryH
20+
#define libraryH
2121

2222
#include "config.h"
2323
#include <map>
@@ -28,13 +28,13 @@
2828
/// @{
2929

3030
/**
31-
* @brief Environment definitions handling
31+
* @brief Library definitions handling
3232
*/
33-
class CPPCHECKLIB Environment {
33+
class CPPCHECKLIB Library {
3434
public:
35-
Environment();
36-
Environment(const Environment &);
37-
~Environment();
35+
Library();
36+
Library(const Library &);
37+
~Library();
3838

3939
bool load(const char path[]);
4040

@@ -75,4 +75,4 @@ class CPPCHECKLIB Environment {
7575

7676
/// @}
7777

78-
#endif // PATH_H_INCLUDED
78+
#endif // libraryH

lib/settings.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ Settings::Settings()
3939
_maxConfigs(12),
4040
enforcedLang(None),
4141
reportProgress(false),
42-
checkConfiguration(false)
42+
checkConfiguration(false),
43+
checkLibrary(false)
4344
{
4445
// This assumes the code you are checking is for the same architecture this is compiled on.
4546
#if defined(_WIN64)

0 commit comments

Comments
 (0)