CLI,LIB: Added --std setting for GTK
This commit is contained in:
parent
ba23b65179
commit
6b2bab535b
|
@ -478,6 +478,8 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
||||||
// --std
|
// --std
|
||||||
else if (std::strcmp(argv[i], "--std=posix") == 0) {
|
else if (std::strcmp(argv[i], "--std=posix") == 0) {
|
||||||
_settings->standards.posix = true;
|
_settings->standards.posix = true;
|
||||||
|
} else if (std::strcmp(argv[i], "--std=gtk") == 0) {
|
||||||
|
_settings->standards.gtk = true;
|
||||||
} else if (std::strcmp(argv[i], "--std=c89") == 0) {
|
} else if (std::strcmp(argv[i], "--std=c89") == 0) {
|
||||||
_settings->standards.c = Standards::C89;
|
_settings->standards.c = Standards::C89;
|
||||||
} else if (std::strcmp(argv[i], "--std=c99") == 0) {
|
} else if (std::strcmp(argv[i], "--std=c99") == 0) {
|
||||||
|
@ -863,6 +865,8 @@ void CmdLineParser::PrintHelp()
|
||||||
#endif
|
#endif
|
||||||
" --std=<id> Set standard.\n"
|
" --std=<id> Set standard.\n"
|
||||||
" The available options are:\n"
|
" The available options are:\n"
|
||||||
|
" * gtk\n"
|
||||||
|
" GTK code\n"
|
||||||
" * posix\n"
|
" * posix\n"
|
||||||
" POSIX compatible code\n"
|
" POSIX compatible code\n"
|
||||||
" * c89\n"
|
" * c89\n"
|
||||||
|
|
|
@ -149,6 +149,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2,
|
||||||
return Malloc;
|
return Malloc;
|
||||||
|
|
||||||
// Does tok2 point on "g_malloc", "g_strdup", ..
|
// Does tok2 point on "g_malloc", "g_strdup", ..
|
||||||
|
if (standards.gtk) {
|
||||||
static const char * const gmallocfunc[] = {
|
static const char * const gmallocfunc[] = {
|
||||||
"g_new",
|
"g_new",
|
||||||
"g_new0",
|
"g_new0",
|
||||||
|
@ -166,6 +167,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2,
|
||||||
if (tok2->str() == gmallocfunc[i])
|
if (tok2->str() == gmallocfunc[i])
|
||||||
return gMalloc;
|
return gMalloc;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Token::Match(tok2, "new struct| %type% [;()]") ||
|
if (Token::Match(tok2, "new struct| %type% [;()]") ||
|
||||||
Token::Match(tok2, "new ( std :: nothrow ) struct| %type% [;()]") ||
|
Token::Match(tok2, "new ( std :: nothrow ) struct| %type% [;()]") ||
|
||||||
|
@ -180,6 +182,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2,
|
||||||
if (Token::Match(tok2, "fopen|tmpfile|g_fopen ("))
|
if (Token::Match(tok2, "fopen|tmpfile|g_fopen ("))
|
||||||
return File;
|
return File;
|
||||||
|
|
||||||
|
if (standards.posix) {
|
||||||
if (Token::Match(tok2, "open|openat|creat|mkstemp|mkostemp (")) {
|
if (Token::Match(tok2, "open|openat|creat|mkstemp|mkostemp (")) {
|
||||||
// simple sanity check of function parameters..
|
// simple sanity check of function parameters..
|
||||||
// TODO: Make such check for all these functions
|
// TODO: Make such check for all these functions
|
||||||
|
@ -192,6 +195,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2,
|
||||||
return No;
|
return No;
|
||||||
return Fd;
|
return Fd;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Token::simpleMatch(tok2, "popen ("))
|
if (Token::simpleMatch(tok2, "popen ("))
|
||||||
return Pipe;
|
return Pipe;
|
||||||
|
@ -220,11 +224,6 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2,
|
||||||
return functionReturnType(func, callstack);
|
return functionReturnType(func, callstack);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isPosixAllocationType(const CheckMemoryLeak::AllocType allocType)
|
|
||||||
{
|
|
||||||
return (allocType == CheckMemoryLeak::Fd || allocType == CheckMemoryLeak::Pipe || allocType == CheckMemoryLeak::Dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
CheckMemoryLeak::AllocType CheckMemoryLeak::getReallocationType(const Token *tok2, unsigned int varid) const
|
CheckMemoryLeak::AllocType CheckMemoryLeak::getReallocationType(const Token *tok2, unsigned int varid) const
|
||||||
{
|
{
|
||||||
|
@ -273,14 +272,17 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType(const Token *tok
|
||||||
Token::Match(tok, "realloc ( %varid% , 0 ) ;", varid))
|
Token::Match(tok, "realloc ( %varid% , 0 ) ;", varid))
|
||||||
return Malloc;
|
return Malloc;
|
||||||
|
|
||||||
|
if (standards.gtk) {
|
||||||
if (Token::Match(tok, "g_free ( %varid% ) ;", varid) ||
|
if (Token::Match(tok, "g_free ( %varid% ) ;", varid) ||
|
||||||
Token::Match(tok, "g_free ( %varid% -", varid))
|
Token::Match(tok, "g_free ( %varid% -", varid))
|
||||||
return gMalloc;
|
return gMalloc;
|
||||||
|
}
|
||||||
|
|
||||||
if (Token::Match(tok, "fclose ( %varid% )", varid) ||
|
if (Token::Match(tok, "fclose ( %varid% )", varid) ||
|
||||||
Token::simpleMatch(tok, "fcloseall ( )"))
|
Token::simpleMatch(tok, "fcloseall ( )"))
|
||||||
return File;
|
return File;
|
||||||
|
|
||||||
|
if (standards.posix) {
|
||||||
if (Token::Match(tok, "close ( %varid% )", varid))
|
if (Token::Match(tok, "close ( %varid% )", varid))
|
||||||
return Fd;
|
return Fd;
|
||||||
|
|
||||||
|
@ -289,6 +291,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType(const Token *tok
|
||||||
|
|
||||||
if (Token::Match(tok, "closedir ( %varid% )", varid))
|
if (Token::Match(tok, "closedir ( %varid% )", varid))
|
||||||
return Dir;
|
return Dir;
|
||||||
|
}
|
||||||
|
|
||||||
return No;
|
return No;
|
||||||
}
|
}
|
||||||
|
@ -887,9 +890,6 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPosixAllocationType(alloc) && !_settings->standards.posix)
|
|
||||||
alloc = CheckMemoryLeak::No;
|
|
||||||
|
|
||||||
// don't check classes..
|
// don't check classes..
|
||||||
if (alloc == CheckMemoryLeak::New) {
|
if (alloc == CheckMemoryLeak::New) {
|
||||||
if (Token::Match(tok->tokAt(2), "new struct| %type% [(;]")) {
|
if (Token::Match(tok->tokAt(2), "new struct| %type% [(;]")) {
|
||||||
|
@ -979,9 +979,6 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
|
||||||
|
|
||||||
AllocType dealloc = getDeallocationType(tok, varid);
|
AllocType dealloc = getDeallocationType(tok, varid);
|
||||||
|
|
||||||
if (isPosixAllocationType(dealloc) && !_settings->standards.posix)
|
|
||||||
dealloc = CheckMemoryLeak::No;
|
|
||||||
|
|
||||||
if (dealloc != No && tok->str() == "fcloseall" && alloctype != dealloc)
|
if (dealloc != No && tok->str() == "fcloseall" && alloctype != dealloc)
|
||||||
//TODO: this assignment is redundant, should be fixed
|
//TODO: this assignment is redundant, should be fixed
|
||||||
/*dealloc = No*/;
|
/*dealloc = No*/;
|
||||||
|
|
|
@ -33,11 +33,14 @@ struct Standards {
|
||||||
/** C++ code standard */
|
/** C++ code standard */
|
||||||
enum cppstd_t { CPP03, CPP11 } cpp;
|
enum cppstd_t { CPP03, CPP11 } cpp;
|
||||||
|
|
||||||
|
/** Code is gtk */
|
||||||
|
bool gtk;
|
||||||
|
|
||||||
/** Code is posix */
|
/** Code is posix */
|
||||||
bool posix;
|
bool posix;
|
||||||
|
|
||||||
/** This constructor clear all the variables **/
|
/** This constructor clear all the variables **/
|
||||||
Standards() : c(C11), cpp(CPP11), posix(false) {}
|
Standards() : c(C11), cpp(CPP11), gtk(false), posix(false) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
|
@ -44,13 +44,16 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
settings.standards.gtk = true;
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
tokenizer.tokenize(istr, "test.cpp");
|
||||||
|
|
||||||
return ((const CheckMemoryLeak *)0)->functionReturnType(&tokenizer.getSymbolDatabase()->scopeList.front().functionList.front());
|
CheckMemoryLeak c(&tokenizer, this, settings.standards);
|
||||||
|
|
||||||
|
return c.functionReturnType(&tokenizer.getSymbolDatabase()->scopeList.front().functionList.front());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testFunctionReturnType() {
|
void testFunctionReturnType() {
|
||||||
|
@ -368,6 +371,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
settings.standards.gtk = true;
|
||||||
settings.standards.posix = true;
|
settings.standards.posix = true;
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
|
|
Loading…
Reference in New Issue