Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion addons/naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ def validate_regex(expr):


RE_VARNAME = None
RE_CONSTNAME = None
RE_PRIVATE_MEMBER_VARIABLE = None
RE_FUNCTIONNAME = None
for arg in sys.argv[1:]:
if arg[:6] == '--var=':
RE_VARNAME = arg[6:]
validate_regex(RE_VARNAME)
elif arg.startswith('--const='):
RE_CONSTNAME = arg[arg.find('=')+1:]
validate_regex(RE_CONSTNAME)
elif arg.startswith('--private-member-variable='):
RE_PRIVATE_MEMBER_VARIABLE = arg[arg.find('=')+1:]
validate_regex(RE_PRIVATE_MEMBER_VARIABLE)
Expand All @@ -49,11 +53,22 @@ def reportError(token, severity, msg, errorId):
print('Checking ' + arg + ', config "' + cfg.name + '"...')
if RE_VARNAME:
for var in cfg.variables:
if var.nameToken:
if var.access == 'Private':
continue
if var.nameToken and not var.isConst:
res = re.match(RE_VARNAME, var.nameToken.str)
if not res:
reportError(var.typeStartToken, 'style', 'Variable ' +
var.nameToken.str + ' violates naming convention', 'varname')
if RE_CONSTNAME:
for var in cfg.variables:
if var.access == 'Private':
continue
if var.nameToken and var.isConst:
res = re.match(RE_CONSTNAME, var.nameToken.str)
if not res:
reportError(var.typeStartToken, 'style', 'Constant ' +
var.nameToken.str + ' violates naming convention', 'constname')
if RE_PRIVATE_MEMBER_VARIABLE:
for var in cfg.variables:
if (var.access is None) or var.access != 'Private':
Expand Down
50 changes: 25 additions & 25 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,53 +44,53 @@
#include <tinyxml2.h>
#endif

static void addFilesToList(const std::string& FileList, std::vector<std::string>& PathNames)
static void addFilesToList(const std::string& fileList, std::vector<std::string>& pathNames)
{
// To keep things initially simple, if the file can't be opened, just be silent and move on.
std::istream *Files;
std::ifstream Infile;
if (FileList == "-") { // read from stdin
Files = &std::cin;
std::istream *files;
std::ifstream infile;
if (fileList == "-") { // read from stdin
files = &std::cin;
} else {
Infile.open(FileList);
Files = &Infile;
infile.open(fileList);
files = &infile;
}
if (Files && *Files) {
std::string FileName;
while (std::getline(*Files, FileName)) { // next line
if (!FileName.empty()) {
PathNames.push_back(FileName);
if (files && *files) {
std::string fileName;
while (std::getline(*files, fileName)) { // next line
if (!fileName.empty()) {
pathNames.push_back(fileName);
}
}
}
}

static bool addIncludePathsToList(const std::string& FileList, std::list<std::string>* PathNames)
static bool addIncludePathsToList(const std::string& fileList, std::list<std::string>* pathNames)
{
std::ifstream Files(FileList);
if (Files) {
std::string PathName;
while (std::getline(Files, PathName)) { // next line
if (!PathName.empty()) {
PathName = Path::removeQuotationMarks(PathName);
PathName = Path::fromNativeSeparators(PathName);
std::ifstream files(fileList);
if (files) {
std::string pathName;
while (std::getline(files, pathName)) { // next line
if (!pathName.empty()) {
pathName = Path::removeQuotationMarks(pathName);
pathName = Path::fromNativeSeparators(pathName);

// If path doesn't end with / or \, add it
if (!endsWith(PathName, '/'))
PathName += '/';
if (!endsWith(pathName, '/'))
pathName += '/';

PathNames->push_back(PathName);
pathNames->push_back(pathName);
}
}
return true;
}
return false;
}

static bool addPathsToSet(const std::string& FileName, std::set<std::string>* set)
static bool addPathsToSet(const std::string& fileName, std::set<std::string>* set)
{
std::list<std::string> templist;
if (!addIncludePathsToList(FileName, &templist))
if (!addIncludePathsToList(fileName, &templist))
return false;
set->insert(templist.begin(), templist.end());
return true;
Expand Down
14 changes: 7 additions & 7 deletions cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ void CppCheckExecutor::setSettings(const Settings &settings)
* \return size of array
* */
template<typename T, int size>
std::size_t GetArrayLength(const T(&)[size])
std::size_t getArrayLength(const T(&)[size])
{
return size;
}
Expand All @@ -228,7 +228,7 @@ static void print_stacktrace(FILE* output, bool demangling, int maxdepth, bool l
#define ADDRESSDISPLAYLENGTH ((sizeof(long)==8)?12:8)
const int fd = fileno(output);
void *callstackArray[32]= {nullptr}; // the less resources the better...
const int currentdepth = backtrace(callstackArray, (int)GetArrayLength(callstackArray));
const int currentdepth = backtrace(callstackArray, (int)getArrayLength(callstackArray));
const int offset=2; // some entries on top are within our own exception handling code or libc
if (maxdepth<0)
maxdepth=currentdepth-offset;
Expand Down Expand Up @@ -256,7 +256,7 @@ static void print_stacktrace(FILE* output, bool demangling, int maxdepth, bool l
char input_buffer[1024]= {0};
strncpy(input_buffer, firstBracketName+1, plus-firstBracketName-1);
char output_buffer[2048]= {0};
size_t length = GetArrayLength(output_buffer);
size_t length = getArrayLength(output_buffer);
int status=0;
// We're violating the specification - passing stack address instead of malloc'ed heap.
// Benefit is that no further heap is required, while there is sufficient stack...
Expand Down Expand Up @@ -539,7 +539,7 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
namespace {
const ULONG maxnamelength = 512;
struct IMAGEHLP_SYMBOL64_EXT : public IMAGEHLP_SYMBOL64 {
TCHAR NameExt[maxnamelength]; // actually no need to worry about character encoding here
TCHAR nameExt[maxnamelength]; // actually no need to worry about character encoding here
};
typedef BOOL (WINAPI *fpStackWalk64)(DWORD, HANDLE, HANDLE, LPSTACKFRAME64, PVOID, PREAD_PROCESS_MEMORY_ROUTINE64, PFUNCTION_TABLE_ACCESS_ROUTINE64, PGET_MODULE_BASE_ROUTINE64, PTRANSLATE_ADDRESS_ROUTINE64);
fpStackWalk64 pStackWalk64;
Expand Down Expand Up @@ -574,7 +574,7 @@ namespace {
}


void PrintCallstack(FILE* outputFile, PEXCEPTION_POINTERS ex)
void printCallstack(FILE* outputFile, PEXCEPTION_POINTERS ex)
{
if (!loadDbgHelp())
return;
Expand Down Expand Up @@ -628,7 +628,7 @@ namespace {
break;
pSymGetSymFromAddr64(hProcess, (ULONG64)stack.AddrPC.Offset, &displacement, &symbol);
TCHAR undname[maxnamelength]= {0};
pUnDecorateSymbolName((const TCHAR*)symbol.Name, (PTSTR)undname, (DWORD)GetArrayLength(undname), UNDNAME_COMPLETE);
pUnDecorateSymbolName((const TCHAR*)symbol.Name, (PTSTR)undname, (DWORD)getArrayLength(undname), UNDNAME_COMPLETE);
if (beyond_main>=0)
++beyond_main;
if (_tcscmp(undname, _T("main"))==0)
Expand Down Expand Up @@ -751,7 +751,7 @@ namespace {
break;
}
fputc('\n', outputFile);
PrintCallstack(outputFile, ex);
printCallstack(outputFile, ex);
fflush(outputFile);
return EXCEPTION_EXECUTE_HANDLER;
}
Expand Down
14 changes: 7 additions & 7 deletions cli/filelister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
// When compiling Unicode targets WinAPI automatically uses *W Unicode versions
// of called functions. Thus, we explicitly call *A versions of the functions.

static BOOL MyIsDirectory(const std::string& path)
static BOOL myIsDirectory(const std::string& path)
{
#ifdef __BORLANDC__
return (GetFileAttributes(path.c_str()) & FILE_ATTRIBUTE_DIRECTORY);
Expand All @@ -50,13 +50,13 @@ static BOOL MyIsDirectory(const std::string& path)
#endif
}

static HANDLE MyFindFirstFile(const std::string& path, LPWIN32_FIND_DATAA findData)
static HANDLE myFindFirstFile(const std::string& path, LPWIN32_FIND_DATAA findData)
{
HANDLE hFind = FindFirstFileA(path.c_str(), findData);
return hFind;
}

static BOOL MyFileExists(const std::string& path)
static BOOL myFileExists(const std::string& path)
{
#ifdef __BORLANDC__
DWORD fa = GetFileAttributes(path.c_str());
Expand Down Expand Up @@ -86,7 +86,7 @@ void FileLister::addFiles(std::map<std::string, std::size_t> &files, const std::
std::string searchPattern = cleanedPath;

// The user wants to check all files in a dir
const bool checkAllFilesInDir = (MyIsDirectory(cleanedPath) != FALSE);
const bool checkAllFilesInDir = (myIsDirectory(cleanedPath) != FALSE);

if (checkAllFilesInDir) {
const char c = cleanedPath.back();
Expand All @@ -111,7 +111,7 @@ void FileLister::addFiles(std::map<std::string, std::size_t> &files, const std::
}

WIN32_FIND_DATAA ffd;
HANDLE hFind = MyFindFirstFile(searchPattern, &ffd);
HANDLE hFind = myFindFirstFile(searchPattern, &ffd);
if (INVALID_HANDLE_VALUE == hFind)
return;

Expand Down Expand Up @@ -152,12 +152,12 @@ void FileLister::addFiles(std::map<std::string, std::size_t> &files, const std::

bool FileLister::isDirectory(const std::string &path)
{
return (MyIsDirectory(path) != FALSE);
return (myIsDirectory(path) != FALSE);
}

bool FileLister::fileExists(const std::string &path)
{
return (MyFileExists(path) != FALSE);
return (myFileExists(path) != FALSE);
}


Expand Down
8 changes: 4 additions & 4 deletions gui/checkthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ void CheckThread::runAddonsAndTools(const ImportProject::FileSettings *fileSetti
continue;

QStringList args;
for (std::list<std::string>::const_iterator I = fileSettings->includePaths.begin(); I != fileSettings->includePaths.end(); ++I)
args << ("-I" + QString::fromStdString(*I));
for (std::list<std::string>::const_iterator incIt = fileSettings->includePaths.begin(); incIt != fileSettings->includePaths.end(); ++incIt)
args << ("-I" + QString::fromStdString(*incIt));
for (std::list<std::string>::const_iterator i = fileSettings->systemIncludePaths.begin(); i != fileSettings->systemIncludePaths.end(); ++i)
args << "-isystem" << QString::fromStdString(*i);
foreach (QString D, QString::fromStdString(fileSettings->defines).split(";")) {
args << ("-D" + D);
foreach (QString def, QString::fromStdString(fileSettings->defines).split(";")) {
args << ("-D" + def);
}
foreach (const std::string& U, fileSettings->undefs) {
args << QString::fromStdString("-U" + U);
Expand Down
8 changes: 4 additions & 4 deletions lib/checkfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,16 +415,16 @@ void CheckFunctions::checkLibraryMatchFunctions()
if (!mSettings->checkLibrary || !mSettings->isEnabled(Settings::INFORMATION))
return;

bool New = false;
bool insideNew = false;
for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) {
if (!tok->scope() || !tok->scope()->isExecutable())
continue;

if (tok->str() == "new")
New = true;
insideNew = true;
else if (tok->str() == ";")
New = false;
else if (New)
insideNew = false;
else if (insideNew)
continue;

if (!Token::Match(tok, "%name% (") || Token::Match(tok, "asm|sizeof|catch"))
Expand Down
2 changes: 1 addition & 1 deletion lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
if (allocation.status == VarInfo::NOALLOC && Token::simpleMatch(tok, ") ; }")) {
const std::string &functionName(tok->link()->previous()->str());
bool unknown = false;
if (mTokenizer->IsScopeNoReturn(tok->tokAt(2), &unknown)) {
if (mTokenizer->isScopeNoReturn(tok->tokAt(2), &unknown)) {
if (!unknown)
varInfo->clear();
else if (!mSettings->library.isLeakIgnore(functionName) && !mSettings->library.isUse(functionName))
Expand Down
26 changes: 13 additions & 13 deletions lib/checkmemoryleak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ void CheckMemoryLeakInFunction::checkReallocUsage()
if (Token::simpleMatch(tokEndRealloc->next(), "; if (") &&
notvar(tokEndRealloc->tokAt(3)->astOperand2(), tok->varId())) {
const Token* tokEndBrace = tokEndRealloc->linkAt(3)->linkAt(1);
if (tokEndBrace && mTokenizer->IsScopeNoReturn(tokEndBrace))
if (tokEndBrace && mTokenizer->isScopeNoReturn(tokEndBrace))
continue;
}

Expand Down Expand Up @@ -606,8 +606,8 @@ void CheckMemoryLeakInClass::variable(const Scope *scope, const Token *tokVarnam
const std::string& classname = scope->className;

// Check if member variable has been allocated and deallocated..
CheckMemoryLeak::AllocType Alloc = CheckMemoryLeak::No;
CheckMemoryLeak::AllocType Dealloc = CheckMemoryLeak::No;
CheckMemoryLeak::AllocType memberAlloc = CheckMemoryLeak::No;
CheckMemoryLeak::AllocType memberDealloc = CheckMemoryLeak::No;

bool allocInConstructor = false;
bool deallocInDestructor = false;
Expand All @@ -619,7 +619,7 @@ void CheckMemoryLeakInClass::variable(const Scope *scope, const Token *tokVarnam
if (!func.hasBody()) {
if (destructor) { // implementation for destructor is not seen => assume it deallocates all variables properly
deallocInDestructor = true;
Dealloc = CheckMemoryLeak::Many;
memberDealloc = CheckMemoryLeak::Many;
}
continue;
}
Expand Down Expand Up @@ -652,16 +652,16 @@ void CheckMemoryLeakInClass::variable(const Scope *scope, const Token *tokVarnam
if (constructor)
allocInConstructor = true;

if (Alloc != No && Alloc != alloc)
if (memberAlloc != No && memberAlloc != alloc)
alloc = CheckMemoryLeak::Many;

if (alloc != CheckMemoryLeak::Many && Dealloc != CheckMemoryLeak::No && Dealloc != CheckMemoryLeak::Many && Dealloc != alloc) {
if (alloc != CheckMemoryLeak::Many && memberDealloc != CheckMemoryLeak::No && memberDealloc != CheckMemoryLeak::Many && memberDealloc != alloc) {
std::list<const Token *> callstack;
callstack.push_back(tok);
mismatchAllocDealloc(callstack, classname + "::" + varname);
}

Alloc = alloc;
memberAlloc = alloc;
}
}

Expand All @@ -679,16 +679,16 @@ void CheckMemoryLeakInClass::variable(const Scope *scope, const Token *tokVarnam
deallocInDestructor = true;

// several types of allocation/deallocation?
if (Dealloc != CheckMemoryLeak::No && Dealloc != dealloc)
if (memberDealloc != CheckMemoryLeak::No && memberDealloc != dealloc)
dealloc = CheckMemoryLeak::Many;

if (dealloc != CheckMemoryLeak::Many && Alloc != CheckMemoryLeak::No && Alloc != Many && Alloc != dealloc) {
if (dealloc != CheckMemoryLeak::Many && memberAlloc != CheckMemoryLeak::No && memberAlloc != Many && memberAlloc != dealloc) {
std::list<const Token *> callstack;
callstack.push_back(tok);
mismatchAllocDealloc(callstack, classname + "::" + varname);
}

Dealloc = dealloc;
memberDealloc = dealloc;
}

// Function call .. possible deallocation
Expand All @@ -702,9 +702,9 @@ void CheckMemoryLeakInClass::variable(const Scope *scope, const Token *tokVarnam
}

if (allocInConstructor && !deallocInDestructor) {
unsafeClassError(tokVarname, classname, classname + "::" + varname /*, Alloc*/);
} else if (Alloc != CheckMemoryLeak::No && Dealloc == CheckMemoryLeak::No) {
unsafeClassError(tokVarname, classname, classname + "::" + varname /*, Alloc*/);
unsafeClassError(tokVarname, classname, classname + "::" + varname /*, memberAlloc*/);
} else if (memberAlloc != CheckMemoryLeak::No && memberDealloc == CheckMemoryLeak::No) {
unsafeClassError(tokVarname, classname, classname + "::" + varname /*, memberAlloc*/);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,13 @@ void CheckOther::checkSuspiciousSemicolon()
if (Token::simpleMatch(scope.bodyStart, "{ ; } {") &&
scope.bodyStart->previous()->linenr() == scope.bodyStart->tokAt(2)->linenr()
&& scope.bodyStart->linenr()+1 >= scope.bodyStart->tokAt(3)->linenr()) {
SuspiciousSemicolonError(scope.classDef);
suspiciousSemicolonError(scope.classDef);
}
}
}
}

void CheckOther::SuspiciousSemicolonError(const Token* tok)
void CheckOther::suspiciousSemicolonError(const Token* tok)
{
reportError(tok, Severity::warning, "suspiciousSemicolon",
"Suspicious use of ; at the end of '" + (tok ? tok->str() : std::string()) + "' statement.", CWE398, true);
Expand Down
Loading