Fix ticket #80 (refactoring: classes ErrorMessage and ErrorLogger), note that errormessage and errorlogger were merged, errormessage.* is no more.
This commit is contained in:
parent
e572cb3c1d
commit
fb3c81dcd9
50
Makefile
50
Makefile
|
@ -13,7 +13,7 @@ OBJECTS = src/checkbufferoverrun.o \
|
||||||
src/checkother.o \
|
src/checkother.o \
|
||||||
src/cppcheck.o \
|
src/cppcheck.o \
|
||||||
src/cppcheckexecutor.o \
|
src/cppcheckexecutor.o \
|
||||||
src/errormessage.o \
|
src/errorlogger.o \
|
||||||
src/filelister.o \
|
src/filelister.o \
|
||||||
src/main.o \
|
src/main.o \
|
||||||
src/preprocessor.o \
|
src/preprocessor.o \
|
||||||
|
@ -52,7 +52,7 @@ TESTOBJ = test/testbufferoverrun.o \
|
||||||
src/checkother.o \
|
src/checkother.o \
|
||||||
src/cppcheck.o \
|
src/cppcheck.o \
|
||||||
src/cppcheckexecutor.o \
|
src/cppcheckexecutor.o \
|
||||||
src/errormessage.o \
|
src/errorlogger.o \
|
||||||
src/filelister.o \
|
src/filelister.o \
|
||||||
src/preprocessor.o \
|
src/preprocessor.o \
|
||||||
src/settings.o \
|
src/settings.o \
|
||||||
|
@ -91,40 +91,40 @@ install: cppcheck
|
||||||
|
|
||||||
###### Build
|
###### Build
|
||||||
|
|
||||||
src/checkbufferoverrun.o: src/checkbufferoverrun.cpp src/checkbufferoverrun.h src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/errormessage.h
|
src/checkbufferoverrun.o: src/checkbufferoverrun.cpp src/checkbufferoverrun.h src/tokenize.h src/settings.h src/errorlogger.h src/token.h
|
||||||
g++ $(CXXFLAGS) -c -o src/checkbufferoverrun.o src/checkbufferoverrun.cpp
|
g++ $(CXXFLAGS) -c -o src/checkbufferoverrun.o src/checkbufferoverrun.cpp
|
||||||
|
|
||||||
src/checkclass.o: src/checkclass.cpp src/checkclass.h src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/errormessage.h
|
src/checkclass.o: src/checkclass.cpp src/checkclass.h src/tokenize.h src/settings.h src/errorlogger.h src/token.h
|
||||||
g++ $(CXXFLAGS) -c -o src/checkclass.o src/checkclass.cpp
|
g++ $(CXXFLAGS) -c -o src/checkclass.o src/checkclass.cpp
|
||||||
|
|
||||||
src/checkdangerousfunctions.o: src/checkdangerousfunctions.cpp src/checkdangerousfunctions.h src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/errormessage.h
|
src/checkdangerousfunctions.o: src/checkdangerousfunctions.cpp src/checkdangerousfunctions.h src/tokenize.h src/settings.h src/errorlogger.h src/token.h
|
||||||
g++ $(CXXFLAGS) -c -o src/checkdangerousfunctions.o src/checkdangerousfunctions.cpp
|
g++ $(CXXFLAGS) -c -o src/checkdangerousfunctions.o src/checkdangerousfunctions.cpp
|
||||||
|
|
||||||
src/checkfunctionusage.o: src/checkfunctionusage.cpp src/checkfunctionusage.h src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/errormessage.h
|
src/checkfunctionusage.o: src/checkfunctionusage.cpp src/checkfunctionusage.h src/tokenize.h src/settings.h src/errorlogger.h src/token.h
|
||||||
g++ $(CXXFLAGS) -c -o src/checkfunctionusage.o src/checkfunctionusage.cpp
|
g++ $(CXXFLAGS) -c -o src/checkfunctionusage.o src/checkfunctionusage.cpp
|
||||||
|
|
||||||
src/checkheaders.o: src/checkheaders.cpp src/checkheaders.h src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/filelister.h
|
src/checkheaders.o: src/checkheaders.cpp src/checkheaders.h src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/filelister.h
|
||||||
g++ $(CXXFLAGS) -c -o src/checkheaders.o src/checkheaders.cpp
|
g++ $(CXXFLAGS) -c -o src/checkheaders.o src/checkheaders.cpp
|
||||||
|
|
||||||
src/checkmemoryleak.o: src/checkmemoryleak.cpp src/checkmemoryleak.h src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/errormessage.h
|
src/checkmemoryleak.o: src/checkmemoryleak.cpp src/checkmemoryleak.h src/tokenize.h src/settings.h src/errorlogger.h src/token.h
|
||||||
g++ $(CXXFLAGS) -c -o src/checkmemoryleak.o src/checkmemoryleak.cpp
|
g++ $(CXXFLAGS) -c -o src/checkmemoryleak.o src/checkmemoryleak.cpp
|
||||||
|
|
||||||
src/checkother.o: src/checkother.cpp src/checkother.h src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/errormessage.h
|
src/checkother.o: src/checkother.cpp src/checkother.h src/tokenize.h src/settings.h src/errorlogger.h src/token.h
|
||||||
g++ $(CXXFLAGS) -c -o src/checkother.o src/checkother.cpp
|
g++ $(CXXFLAGS) -c -o src/checkother.o src/checkother.cpp
|
||||||
|
|
||||||
src/cppcheck.o: src/cppcheck.cpp src/cppcheck.h src/settings.h src/errorlogger.h src/checkfunctionusage.h src/tokenize.h src/token.h src/preprocessor.h src/checkmemoryleak.h src/checkbufferoverrun.h src/checkdangerousfunctions.h src/checkclass.h src/checkheaders.h src/checkother.h src/filelister.h src/errormessage.h
|
src/cppcheck.o: src/cppcheck.cpp src/cppcheck.h src/settings.h src/errorlogger.h src/checkfunctionusage.h src/tokenize.h src/token.h src/preprocessor.h src/checkmemoryleak.h src/checkbufferoverrun.h src/checkdangerousfunctions.h src/checkclass.h src/checkheaders.h src/checkother.h src/filelister.h
|
||||||
g++ $(CXXFLAGS) -c -o src/cppcheck.o src/cppcheck.cpp
|
g++ $(CXXFLAGS) -c -o src/cppcheck.o src/cppcheck.cpp
|
||||||
|
|
||||||
src/cppcheckexecutor.o: src/cppcheckexecutor.cpp src/cppcheckexecutor.h src/errorlogger.h src/cppcheck.h src/settings.h src/checkfunctionusage.h src/tokenize.h src/token.h
|
src/cppcheckexecutor.o: src/cppcheckexecutor.cpp src/cppcheckexecutor.h src/errorlogger.h src/settings.h src/cppcheck.h src/checkfunctionusage.h src/tokenize.h src/token.h
|
||||||
g++ $(CXXFLAGS) -c -o src/cppcheckexecutor.o src/cppcheckexecutor.cpp
|
g++ $(CXXFLAGS) -c -o src/cppcheckexecutor.o src/cppcheckexecutor.cpp
|
||||||
|
|
||||||
src/errormessage.o: src/errormessage.cpp src/errormessage.h src/settings.h src/errorlogger.h src/tokenize.h src/token.h
|
src/errorlogger.o: src/errorlogger.cpp src/errorlogger.h src/settings.h src/tokenize.h src/token.h
|
||||||
g++ $(CXXFLAGS) -c -o src/errormessage.o src/errormessage.cpp
|
g++ $(CXXFLAGS) -c -o src/errorlogger.o src/errorlogger.cpp
|
||||||
|
|
||||||
src/filelister.o: src/filelister.cpp src/filelister.h
|
src/filelister.o: src/filelister.cpp src/filelister.h
|
||||||
g++ $(CXXFLAGS) -c -o src/filelister.o src/filelister.cpp
|
g++ $(CXXFLAGS) -c -o src/filelister.o src/filelister.cpp
|
||||||
|
|
||||||
src/main.o: src/main.cpp src/cppcheckexecutor.h src/errorlogger.h
|
src/main.o: src/main.cpp src/cppcheckexecutor.h src/errorlogger.h src/settings.h
|
||||||
g++ $(CXXFLAGS) -c -o src/main.o src/main.cpp
|
g++ $(CXXFLAGS) -c -o src/main.o src/main.cpp
|
||||||
|
|
||||||
src/preprocessor.o: src/preprocessor.cpp src/preprocessor.h src/tokenize.h src/settings.h src/errorlogger.h src/token.h
|
src/preprocessor.o: src/preprocessor.cpp src/preprocessor.h src/tokenize.h src/settings.h src/errorlogger.h src/token.h
|
||||||
|
@ -151,7 +151,7 @@ test/testclass.o: test/testclass.cpp src/tokenize.h src/settings.h src/errorlogg
|
||||||
test/testconstructors.o: test/testconstructors.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/checkclass.h test/testsuite.h
|
test/testconstructors.o: test/testconstructors.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/checkclass.h test/testsuite.h
|
||||||
g++ $(CXXFLAGS) -c -o test/testconstructors.o test/testconstructors.cpp
|
g++ $(CXXFLAGS) -c -o test/testconstructors.o test/testconstructors.cpp
|
||||||
|
|
||||||
test/testcppcheck.o: test/testcppcheck.cpp test/testsuite.h src/errorlogger.h src/cppcheck.h src/settings.h src/checkfunctionusage.h src/tokenize.h src/token.h
|
test/testcppcheck.o: test/testcppcheck.cpp test/testsuite.h src/errorlogger.h src/settings.h src/cppcheck.h src/checkfunctionusage.h src/tokenize.h src/token.h
|
||||||
g++ $(CXXFLAGS) -c -o test/testcppcheck.o test/testcppcheck.cpp
|
g++ $(CXXFLAGS) -c -o test/testcppcheck.o test/testcppcheck.cpp
|
||||||
|
|
||||||
test/testdangerousfunctions.o: test/testdangerousfunctions.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/checkdangerousfunctions.h test/testsuite.h
|
test/testdangerousfunctions.o: test/testdangerousfunctions.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/checkdangerousfunctions.h test/testsuite.h
|
||||||
|
@ -160,13 +160,13 @@ test/testdangerousfunctions.o: test/testdangerousfunctions.cpp src/tokenize.h sr
|
||||||
test/testdivision.o: test/testdivision.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/checkother.h test/testsuite.h
|
test/testdivision.o: test/testdivision.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/checkother.h test/testsuite.h
|
||||||
g++ $(CXXFLAGS) -c -o test/testdivision.o test/testdivision.cpp
|
g++ $(CXXFLAGS) -c -o test/testdivision.o test/testdivision.cpp
|
||||||
|
|
||||||
test/testfilelister.o: test/testfilelister.cpp test/testsuite.h src/errorlogger.h src/filelister.h
|
test/testfilelister.o: test/testfilelister.cpp test/testsuite.h src/errorlogger.h src/settings.h src/filelister.h
|
||||||
g++ $(CXXFLAGS) -c -o test/testfilelister.o test/testfilelister.cpp
|
g++ $(CXXFLAGS) -c -o test/testfilelister.o test/testfilelister.cpp
|
||||||
|
|
||||||
test/testfunctionusage.o: test/testfunctionusage.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h test/testsuite.h src/checkfunctionusage.h
|
test/testfunctionusage.o: test/testfunctionusage.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h test/testsuite.h src/checkfunctionusage.h
|
||||||
g++ $(CXXFLAGS) -c -o test/testfunctionusage.o test/testfunctionusage.cpp
|
g++ $(CXXFLAGS) -c -o test/testfunctionusage.o test/testfunctionusage.cpp
|
||||||
|
|
||||||
test/testincompletestatement.o: test/testincompletestatement.cpp test/testsuite.h src/errorlogger.h src/tokenize.h src/settings.h src/token.h src/checkother.h
|
test/testincompletestatement.o: test/testincompletestatement.cpp test/testsuite.h src/errorlogger.h src/settings.h src/tokenize.h src/token.h src/checkother.h
|
||||||
g++ $(CXXFLAGS) -c -o test/testincompletestatement.o test/testincompletestatement.cpp
|
g++ $(CXXFLAGS) -c -o test/testincompletestatement.o test/testincompletestatement.cpp
|
||||||
|
|
||||||
test/testmemleak.o: test/testmemleak.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/checkmemoryleak.h test/testsuite.h
|
test/testmemleak.o: test/testmemleak.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/checkmemoryleak.h test/testsuite.h
|
||||||
|
@ -178,34 +178,34 @@ test/testmemleakmp.o: test/testmemleakmp.cpp src/tokenize.h src/settings.h src/e
|
||||||
test/testother.o: test/testother.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/checkother.h test/testsuite.h
|
test/testother.o: test/testother.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/checkother.h test/testsuite.h
|
||||||
g++ $(CXXFLAGS) -c -o test/testother.o test/testother.cpp
|
g++ $(CXXFLAGS) -c -o test/testother.o test/testother.cpp
|
||||||
|
|
||||||
test/testpreprocessor.o: test/testpreprocessor.cpp test/testsuite.h src/errorlogger.h src/preprocessor.h
|
test/testpreprocessor.o: test/testpreprocessor.cpp test/testsuite.h src/errorlogger.h src/settings.h src/preprocessor.h
|
||||||
g++ $(CXXFLAGS) -c -o test/testpreprocessor.o test/testpreprocessor.cpp
|
g++ $(CXXFLAGS) -c -o test/testpreprocessor.o test/testpreprocessor.cpp
|
||||||
|
|
||||||
test/testredundantif.o: test/testredundantif.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/checkother.h test/testsuite.h
|
test/testredundantif.o: test/testredundantif.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/checkother.h test/testsuite.h
|
||||||
g++ $(CXXFLAGS) -c -o test/testredundantif.o test/testredundantif.cpp
|
g++ $(CXXFLAGS) -c -o test/testredundantif.o test/testredundantif.cpp
|
||||||
|
|
||||||
test/testrunner.o: test/testrunner.cpp test/testsuite.h src/errorlogger.h
|
test/testrunner.o: test/testrunner.cpp test/testsuite.h src/errorlogger.h src/settings.h
|
||||||
g++ $(CXXFLAGS) -c -o test/testrunner.o test/testrunner.cpp
|
g++ $(CXXFLAGS) -c -o test/testrunner.o test/testrunner.cpp
|
||||||
|
|
||||||
test/testsimplifytokens.o: test/testsimplifytokens.cpp test/testsuite.h src/errorlogger.h src/tokenize.h src/settings.h src/token.h
|
test/testsimplifytokens.o: test/testsimplifytokens.cpp test/testsuite.h src/errorlogger.h src/settings.h src/tokenize.h src/token.h
|
||||||
g++ $(CXXFLAGS) -c -o test/testsimplifytokens.o test/testsimplifytokens.cpp
|
g++ $(CXXFLAGS) -c -o test/testsimplifytokens.o test/testsimplifytokens.cpp
|
||||||
|
|
||||||
test/testsuite.o: test/testsuite.cpp test/testsuite.h src/errorlogger.h
|
test/testsuite.o: test/testsuite.cpp test/testsuite.h src/errorlogger.h src/settings.h
|
||||||
g++ $(CXXFLAGS) -c -o test/testsuite.o test/testsuite.cpp
|
g++ $(CXXFLAGS) -c -o test/testsuite.o test/testsuite.cpp
|
||||||
|
|
||||||
test/testtoken.o: test/testtoken.cpp test/testsuite.h src/errorlogger.h src/token.h
|
test/testtoken.o: test/testtoken.cpp test/testsuite.h src/errorlogger.h src/settings.h src/token.h
|
||||||
g++ $(CXXFLAGS) -c -o test/testtoken.o test/testtoken.cpp
|
g++ $(CXXFLAGS) -c -o test/testtoken.o test/testtoken.cpp
|
||||||
|
|
||||||
test/testtokenize.o: test/testtokenize.cpp test/testsuite.h src/errorlogger.h src/tokenize.h src/settings.h src/token.h
|
test/testtokenize.o: test/testtokenize.cpp test/testsuite.h src/errorlogger.h src/settings.h src/tokenize.h src/token.h
|
||||||
g++ $(CXXFLAGS) -c -o test/testtokenize.o test/testtokenize.cpp
|
g++ $(CXXFLAGS) -c -o test/testtokenize.o test/testtokenize.cpp
|
||||||
|
|
||||||
test/testunusedprivfunc.o: test/testunusedprivfunc.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/checkclass.h test/testsuite.h
|
test/testunusedprivfunc.o: test/testunusedprivfunc.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/checkclass.h test/testsuite.h
|
||||||
g++ $(CXXFLAGS) -c -o test/testunusedprivfunc.o test/testunusedprivfunc.cpp
|
g++ $(CXXFLAGS) -c -o test/testunusedprivfunc.o test/testunusedprivfunc.cpp
|
||||||
|
|
||||||
test/testunusedvar.o: test/testunusedvar.cpp test/testsuite.h src/errorlogger.h src/tokenize.h src/settings.h src/token.h src/checkother.h
|
test/testunusedvar.o: test/testunusedvar.cpp test/testsuite.h src/errorlogger.h src/settings.h src/tokenize.h src/token.h src/checkother.h
|
||||||
g++ $(CXXFLAGS) -c -o test/testunusedvar.o test/testunusedvar.cpp
|
g++ $(CXXFLAGS) -c -o test/testunusedvar.o test/testunusedvar.cpp
|
||||||
|
|
||||||
src/errormessage.h: tools/errmsg
|
src/errorlogger.h: tools/errmsg
|
||||||
tools/errmsg
|
tools/errmsg
|
||||||
mv errormessage.h src/
|
mv errorlogger.h src/
|
||||||
|
|
||||||
|
|
|
@ -49,8 +49,6 @@
|
||||||
<Unit filename="src/cppcheckexecutor.cpp" />
|
<Unit filename="src/cppcheckexecutor.cpp" />
|
||||||
<Unit filename="src/cppcheckexecutor.h" />
|
<Unit filename="src/cppcheckexecutor.h" />
|
||||||
<Unit filename="src/errorlogger.h" />
|
<Unit filename="src/errorlogger.h" />
|
||||||
<Unit filename="src/errormessage.cpp" />
|
|
||||||
<Unit filename="src/errormessage.h" />
|
|
||||||
<Unit filename="src/filelister.cpp" />
|
<Unit filename="src/filelister.cpp" />
|
||||||
<Unit filename="src/filelister.h" />
|
<Unit filename="src/filelister.h" />
|
||||||
<Unit filename="src/main.cpp" />
|
<Unit filename="src/main.cpp" />
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "checkbufferoverrun.h"
|
#include "checkbufferoverrun.h"
|
||||||
#include "errormessage.h"
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -52,7 +51,7 @@ CheckBufferOverrunClass::~CheckBufferOverrunClass()
|
||||||
void CheckBufferOverrunClass::arrayIndexOutOfBounds(const Token *tok)
|
void CheckBufferOverrunClass::arrayIndexOutOfBounds(const Token *tok)
|
||||||
{
|
{
|
||||||
_callStack.push_back(tok);
|
_callStack.push_back(tok);
|
||||||
ErrorMessage::arrayIndexOutOfBounds(_errorLogger, _tokenizer, _callStack);
|
_errorLogger->arrayIndexOutOfBounds(_tokenizer, _callStack);
|
||||||
_callStack.pop_back();
|
_callStack.pop_back();
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -154,7 +153,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
|
||||||
const char *num = tok->strAt(6);
|
const char *num = tok->strAt(6);
|
||||||
if (std::atoi(num) > total_size)
|
if (std::atoi(num) > total_size)
|
||||||
{
|
{
|
||||||
ErrorMessage::bufferOverrun(_errorLogger, _tokenizer, tok);
|
_errorLogger->bufferOverrun(_tokenizer, tok);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
@ -168,7 +167,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
|
||||||
const char *num = tok->strAt(varc + 6);
|
const char *num = tok->strAt(varc + 6);
|
||||||
if (std::atoi(num) > total_size)
|
if (std::atoi(num) > total_size)
|
||||||
{
|
{
|
||||||
ErrorMessage::bufferOverrun(_errorLogger, _tokenizer, tok);
|
_errorLogger->bufferOverrun(_tokenizer, tok);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
@ -227,7 +226,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
|
||||||
|
|
||||||
if (Token::Match(tok2, pattern.str().c_str()))
|
if (Token::Match(tok2, pattern.str().c_str()))
|
||||||
{
|
{
|
||||||
ErrorMessage::bufferOverrun(_errorLogger, _tokenizer, tok2);
|
_errorLogger->bufferOverrun(_tokenizer, tok2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,7 +249,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
|
||||||
}
|
}
|
||||||
if (len > 2 && len >= (int)size + 2)
|
if (len > 2 && len >= (int)size + 2)
|
||||||
{
|
{
|
||||||
ErrorMessage::bufferOverrun(_errorLogger, _tokenizer, tok);
|
_errorLogger->bufferOverrun(_tokenizer, tok);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -276,7 +275,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
|
||||||
}
|
}
|
||||||
if (len > (int)size)
|
if (len > (int)size)
|
||||||
{
|
{
|
||||||
ErrorMessage::bufferOverrun(_errorLogger, _tokenizer, tok);
|
_errorLogger->bufferOverrun(_tokenizer, tok);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,7 +284,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
|
||||||
{
|
{
|
||||||
int n = std::atoi(tok->strAt(4));
|
int n = std::atoi(tok->strAt(4));
|
||||||
if (n > size)
|
if (n > size)
|
||||||
ErrorMessage::outOfBounds(_errorLogger, _tokenizer, tok->tokAt(4), "snprintf size");
|
_errorLogger->outOfBounds(_tokenizer, tok->tokAt(4), "snprintf size");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,6 @@
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
#include "checkclass.h"
|
#include "checkclass.h"
|
||||||
|
|
||||||
#include "errormessage.h"
|
|
||||||
|
|
||||||
#include <locale>
|
#include <locale>
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
@ -381,13 +379,13 @@ void CheckClass::constructors()
|
||||||
if (! constructor_token)
|
if (! constructor_token)
|
||||||
{
|
{
|
||||||
// If "--style" has been given, give a warning
|
// If "--style" has been given, give a warning
|
||||||
if (ErrorMessage::noConstructor(_settings))
|
if (ErrorLogger::noConstructor(_settings))
|
||||||
{
|
{
|
||||||
// If the class has member variables there should be an constructor
|
// If the class has member variables there should be an constructor
|
||||||
struct VAR *varlist = ClassChecking_GetVarList(tok1);
|
struct VAR *varlist = ClassChecking_GetVarList(tok1);
|
||||||
if (varlist)
|
if (varlist)
|
||||||
{
|
{
|
||||||
ErrorMessage::noConstructor(_errorLogger, _tokenizer, tok1, classNameToken->str());
|
_errorLogger->noConstructor(_tokenizer, tok1, classNameToken->str());
|
||||||
}
|
}
|
||||||
// Delete the varlist..
|
// Delete the varlist..
|
||||||
while (varlist)
|
while (varlist)
|
||||||
|
@ -446,7 +444,7 @@ void CheckClass::CheckConstructors(const Token *tok1, struct VAR *varlist, const
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// It's non-static and it's not initialized => error
|
// It's non-static and it's not initialized => error
|
||||||
ErrorMessage::uninitVar(_errorLogger, _tokenizer, constructor_token, className, var->name);
|
_errorLogger->uninitVar(_tokenizer, constructor_token, className, var->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (struct VAR *var = varlist; var; var = var->next)
|
for (struct VAR *var = varlist; var; var = var->next)
|
||||||
|
@ -577,7 +575,7 @@ void CheckClass::privateFunctions()
|
||||||
const std::string _pattern("return|(|)|,|= " + FuncList.front()->str());
|
const std::string _pattern("return|(|)|,|= " + FuncList.front()->str());
|
||||||
if (!Token::findmatch(_tokenizer->tokens(), _pattern.c_str()))
|
if (!Token::findmatch(_tokenizer->tokens(), _pattern.c_str()))
|
||||||
{
|
{
|
||||||
ErrorMessage::unusedPrivateFunction(_errorLogger, _tokenizer, FuncList.front(), classname, FuncList.front()->str());
|
_errorLogger->unusedPrivateFunction(_tokenizer, FuncList.front(), classname, FuncList.front()->str());
|
||||||
}
|
}
|
||||||
FuncList.pop_front();
|
FuncList.pop_front();
|
||||||
}
|
}
|
||||||
|
@ -617,7 +615,7 @@ void CheckClass::noMemset()
|
||||||
const std::string pattern1(std::string("class ") + type);
|
const std::string pattern1(std::string("class ") + type);
|
||||||
if (Token::findmatch(_tokenizer->tokens(), pattern1.c_str()))
|
if (Token::findmatch(_tokenizer->tokens(), pattern1.c_str()))
|
||||||
{
|
{
|
||||||
ErrorMessage::memsetClass(_errorLogger, _tokenizer, tok, tok->str());
|
_errorLogger->memsetClass(_tokenizer, tok, tok->str());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -630,7 +628,7 @@ void CheckClass::noMemset()
|
||||||
|
|
||||||
if (Token::Match(tstruct, "std :: %type% %var% ;"))
|
if (Token::Match(tstruct, "std :: %type% %var% ;"))
|
||||||
{
|
{
|
||||||
ErrorMessage::memsetStruct(_errorLogger, _tokenizer, tok, tok->str(), tstruct->strAt(2));
|
_errorLogger->memsetStruct(_tokenizer, tok, tok->str(), tstruct->strAt(2));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -650,7 +648,7 @@ void CheckClass::operatorEq()
|
||||||
const Token *tok = Token::findmatch(_tokenizer->tokens(), "void operator = (");
|
const Token *tok = Token::findmatch(_tokenizer->tokens(), "void operator = (");
|
||||||
if (tok)
|
if (tok)
|
||||||
{
|
{
|
||||||
ErrorMessage::operatorEq(_errorLogger, _tokenizer, tok);
|
_errorLogger->operatorEq(_tokenizer, tok);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -731,14 +729,14 @@ void CheckClass::virtualDestructor()
|
||||||
base = Token::findmatch(_tokenizer->tokens(), (std::string("class ") + baseName[0] + " :|{").c_str());
|
base = Token::findmatch(_tokenizer->tokens(), (std::string("class ") + baseName[0] + " :|{").c_str());
|
||||||
if (base)
|
if (base)
|
||||||
{
|
{
|
||||||
ErrorMessage::virtualDestructor(_errorLogger, _tokenizer, base, baseName[0], derivedClass->str());
|
_errorLogger->virtualDestructor(_tokenizer, base, baseName[0], derivedClass->str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// There is a destructor. Check that it's virtual..
|
// There is a destructor. Check that it's virtual..
|
||||||
else if (base->str() != "virtual")
|
else if (base->str() != "virtual")
|
||||||
{
|
{
|
||||||
ErrorMessage::virtualDestructor(_errorLogger, _tokenizer, base, baseName[0], derivedClass->str());
|
_errorLogger->virtualDestructor(_tokenizer, base, baseName[0], derivedClass->str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "checkdangerousfunctions.h"
|
#include "checkdangerousfunctions.h"
|
||||||
#include "errormessage.h"
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
#include "checkfunctionusage.h"
|
#include "checkfunctionusage.h"
|
||||||
#include "errormessage.h"
|
|
||||||
#include "tokenize.h"
|
#include "tokenize.h"
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -158,7 +157,7 @@ void CheckFunctionUsage::check()
|
||||||
filename = "";
|
filename = "";
|
||||||
else
|
else
|
||||||
filename = func.filename;
|
filename = func.filename;
|
||||||
ErrorMessage::unusedFunction(_errorLogger, filename, it->first);
|
_errorLogger->unusedFunction(filename, it->first);
|
||||||
}
|
}
|
||||||
else if (! func.usedOtherFile)
|
else if (! func.usedOtherFile)
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
|
|
||||||
#include "checkmemoryleak.h"
|
#include "checkmemoryleak.h"
|
||||||
#include "errormessage.h"
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
@ -297,11 +296,11 @@ void CheckMemoryLeakClass::MemoryLeak(const Token *tok, const char varname[], Al
|
||||||
{
|
{
|
||||||
if (alloctype == CheckMemoryLeakClass::FOPEN ||
|
if (alloctype == CheckMemoryLeakClass::FOPEN ||
|
||||||
alloctype == CheckMemoryLeakClass::POPEN)
|
alloctype == CheckMemoryLeakClass::POPEN)
|
||||||
ErrorMessage::resourceLeak(_errorLogger, _tokenizer, tok, varname);
|
_errorLogger->resourceLeak(_tokenizer, tok, varname);
|
||||||
else if (all)
|
else if (all)
|
||||||
ErrorMessage::memleakall(_errorLogger, _tokenizer, tok, varname);
|
_errorLogger->memleakall(_tokenizer, tok, varname);
|
||||||
else
|
else
|
||||||
ErrorMessage::memleak(_errorLogger, _tokenizer, tok, varname);
|
_errorLogger->memleak(_tokenizer, tok, varname);
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -395,7 +394,7 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
|
||||||
Token::Match(tok->tokAt(2), "malloc ( %num% )") &&
|
Token::Match(tok->tokAt(2), "malloc ( %num% )") &&
|
||||||
(std::atoi(tok->strAt(4)) % sz) != 0)
|
(std::atoi(tok->strAt(4)) % sz) != 0)
|
||||||
{
|
{
|
||||||
ErrorMessage::mismatchSize(_errorLogger, _tokenizer, tok->tokAt(4), tok->strAt(4));
|
_errorLogger->mismatchSize(_tokenizer, tok->tokAt(4), tok->strAt(4));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (alloc == No)
|
if (alloc == No)
|
||||||
|
@ -435,7 +434,7 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
|
||||||
if (alloc != Many && dealloctype != No && dealloctype != Many && dealloctype != alloc)
|
if (alloc != Many && dealloctype != No && dealloctype != Many && dealloctype != alloc)
|
||||||
{
|
{
|
||||||
callstack.push_back(tok);
|
callstack.push_back(tok);
|
||||||
ErrorMessage::mismatchAllocDealloc(_errorLogger, _tokenizer, callstack, varname);
|
_errorLogger->mismatchAllocDealloc(_tokenizer, callstack, varname);
|
||||||
callstack.pop_back();
|
callstack.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -482,7 +481,7 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
|
||||||
if (dealloc != Many && alloctype != No && alloctype != Many && alloctype != dealloc)
|
if (dealloc != Many && alloctype != No && alloctype != Many && alloctype != dealloc)
|
||||||
{
|
{
|
||||||
callstack.push_back(tok);
|
callstack.push_back(tok);
|
||||||
ErrorMessage::mismatchAllocDealloc(_errorLogger, _tokenizer, callstack, varname);
|
_errorLogger->mismatchAllocDealloc(_tokenizer, callstack, varname);
|
||||||
callstack.pop_back();
|
callstack.pop_back();
|
||||||
}
|
}
|
||||||
dealloctype = dealloc;
|
dealloctype = dealloc;
|
||||||
|
@ -1188,7 +1187,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope(const Token *Tok1, const c
|
||||||
}
|
}
|
||||||
if ((result = Token::findmatch(tok, "dealloc [;{}] use|use_ ;")) != NULL)
|
if ((result = Token::findmatch(tok, "dealloc [;{}] use|use_ ;")) != NULL)
|
||||||
{
|
{
|
||||||
ErrorMessage::deallocuse(_errorLogger, _tokenizer, result->tokAt(2), varname);
|
_errorLogger->deallocuse(_tokenizer, result->tokAt(2), varname);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace "&use" with "use". Replace "use_" with ";"
|
// Replace "&use" with "use". Replace "use_" with ";"
|
||||||
|
@ -1252,7 +1251,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope(const Token *Tok1, const c
|
||||||
|
|
||||||
else if ((result = Token::findmatch(tok, "dealloc ; dealloc ;")) != NULL)
|
else if ((result = Token::findmatch(tok, "dealloc ; dealloc ;")) != NULL)
|
||||||
{
|
{
|
||||||
ErrorMessage::deallocDealloc(_errorLogger, _tokenizer, result->tokAt(2), varname);
|
_errorLogger->deallocDealloc(_tokenizer, result->tokAt(2), varname);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (! Token::findmatch(tok, "dealloc") &&
|
else if (! Token::findmatch(tok, "dealloc") &&
|
||||||
|
@ -1490,7 +1489,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_Variable(const std::vect
|
||||||
if (alloc != Many && Dealloc != No && Dealloc != Many && Dealloc != alloc)
|
if (alloc != Many && Dealloc != No && Dealloc != Many && Dealloc != alloc)
|
||||||
{
|
{
|
||||||
callstack.push_back(tok);
|
callstack.push_back(tok);
|
||||||
ErrorMessage::mismatchAllocDealloc(_errorLogger, _tokenizer, callstack, FullVariableName.str());
|
_errorLogger->mismatchAllocDealloc(_tokenizer, callstack, FullVariableName.str());
|
||||||
callstack.pop_back();
|
callstack.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1517,7 +1516,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_Variable(const std::vect
|
||||||
if (dealloc != Many && Alloc != No && Alloc != Many && Alloc != dealloc)
|
if (dealloc != Many && Alloc != No && Alloc != Many && Alloc != dealloc)
|
||||||
{
|
{
|
||||||
callstack.push_back(tok);
|
callstack.push_back(tok);
|
||||||
ErrorMessage::mismatchAllocDealloc(_errorLogger, _tokenizer, callstack, FullVariableName.str());
|
_errorLogger->mismatchAllocDealloc(_tokenizer, callstack, FullVariableName.str());
|
||||||
callstack.pop_back();
|
callstack.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
#include "checkother.h"
|
#include "checkother.h"
|
||||||
#include "errormessage.h"
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
@ -62,7 +61,7 @@ void CheckOther::WarningOldStylePointerCast()
|
||||||
if (!Token::findmatch(_tokenizer->tokens(), pattern.c_str()))
|
if (!Token::findmatch(_tokenizer->tokens(), pattern.c_str()))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ErrorMessage::cstyleCast(_errorLogger, _tokenizer, tok);
|
_errorLogger->cstyleCast(_tokenizer, tok);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +142,7 @@ void CheckOther::WarningRedundantCode()
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
ErrorMessage::redundantIfDelete0(_errorLogger, _tokenizer, tok);
|
_errorLogger->redundantIfDelete0(_tokenizer, tok);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,7 +178,7 @@ void CheckOther::redundantCondition2()
|
||||||
var2->str() == var3->str() &&
|
var2->str() == var3->str() &&
|
||||||
any1->str() == any2->str())
|
any1->str() == any2->str())
|
||||||
{
|
{
|
||||||
ErrorMessage::redundantIfRemove(_errorLogger, _tokenizer, tok);
|
_errorLogger->redundantIfRemove(_tokenizer, tok);
|
||||||
}
|
}
|
||||||
|
|
||||||
tok = Token::findmatch(tok->next(), pattern);
|
tok = Token::findmatch(tok->next(), pattern);
|
||||||
|
@ -196,7 +195,7 @@ void CheckOther::redundantCondition2()
|
||||||
|
|
||||||
void CheckOther::WarningIf()
|
void CheckOther::WarningIf()
|
||||||
{
|
{
|
||||||
if (ErrorMessage::ifNoAction(_settings))
|
if (ErrorLogger::ifNoAction(_settings))
|
||||||
{
|
{
|
||||||
// Search for 'if (condition);'
|
// Search for 'if (condition);'
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||||
|
@ -217,7 +216,7 @@ void CheckOther::WarningIf()
|
||||||
{
|
{
|
||||||
if (Token::Match(tok2, ") ; !!else"))
|
if (Token::Match(tok2, ") ; !!else"))
|
||||||
{
|
{
|
||||||
ErrorMessage::ifNoAction(_errorLogger, _tokenizer, tok);
|
_errorLogger->ifNoAction(_tokenizer, tok);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -226,7 +225,7 @@ void CheckOther::WarningIf()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ErrorMessage::conditionAlwaysTrueFalse(_settings))
|
if (ErrorLogger::conditionAlwaysTrueFalse(_settings))
|
||||||
{
|
{
|
||||||
// Search for 'a=b; if (a==b)'
|
// Search for 'a=b; if (a==b)'
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||||
|
@ -280,7 +279,7 @@ void CheckOther::WarningIf()
|
||||||
if (strcmp(cond, p[i]) == 0)
|
if (strcmp(cond, p[i]) == 0)
|
||||||
b = (i < 3);
|
b = (i < 3);
|
||||||
}
|
}
|
||||||
ErrorMessage::conditionAlwaysTrueFalse(_errorLogger, _tokenizer, tok->tokAt(4), b ? "True" : "False");
|
_errorLogger->conditionAlwaysTrueFalse(_tokenizer, tok->tokAt(4), b ? "True" : "False");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -320,7 +319,7 @@ void CheckOther::InvalidFunctionUsage()
|
||||||
int radix = std::atoi(tok2->strAt(1));
|
int radix = std::atoi(tok2->strAt(1));
|
||||||
if (!(radix == 0 || (radix >= 2 && radix <= 36)))
|
if (!(radix == 0 || (radix >= 2 && radix <= 36)))
|
||||||
{
|
{
|
||||||
ErrorMessage::dangerousUsageStrtol(_errorLogger, _tokenizer, tok2);
|
_errorLogger->dangerousUsageStrtol(_tokenizer, tok2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -363,7 +362,7 @@ void CheckOther::InvalidFunctionUsage()
|
||||||
}
|
}
|
||||||
else if (parlevel == 0 && Token::Match(tok2, ", %varid% [,)]", varid))
|
else if (parlevel == 0 && Token::Match(tok2, ", %varid% [,)]", varid))
|
||||||
{
|
{
|
||||||
ErrorMessage::sprintfOverlappingData(_errorLogger, _tokenizer, tok2->next(), tok2->next()->str());
|
_errorLogger->sprintfOverlappingData(_tokenizer, tok2->next(), tok2->next()->str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -394,7 +393,7 @@ void CheckOther::CheckUnsignedDivision()
|
||||||
|
|
||||||
else if (!Token::Match(tok, "[).]") && Token::Match(tok->next(), "%var% / %var%"))
|
else if (!Token::Match(tok, "[).]") && Token::Match(tok->next(), "%var% / %var%"))
|
||||||
{
|
{
|
||||||
if (ErrorMessage::udivWarning(_settings))
|
if (ErrorLogger::udivWarning(_settings))
|
||||||
{
|
{
|
||||||
const char *varname1 = tok->strAt(1);
|
const char *varname1 = tok->strAt(1);
|
||||||
const char *varname2 = tok->strAt(3);
|
const char *varname2 = tok->strAt(3);
|
||||||
|
@ -404,33 +403,33 @@ void CheckOther::CheckUnsignedDivision()
|
||||||
if (sign1 && sign2 && sign1 != sign2)
|
if (sign1 && sign2 && sign1 != sign2)
|
||||||
{
|
{
|
||||||
// One of the operands are signed, the other is unsigned..
|
// One of the operands are signed, the other is unsigned..
|
||||||
ErrorMessage::udivWarning(_errorLogger, _tokenizer, tok->next());
|
_errorLogger->udivWarning(_tokenizer, tok->next());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (!Token::Match(tok, "[).]") && Token::Match(tok->next(), "%var% / - %num%"))
|
else if (!Token::Match(tok, "[).]") && Token::Match(tok->next(), "%var% / - %num%"))
|
||||||
{
|
{
|
||||||
if (ErrorMessage::udivError())
|
if (ErrorLogger::udivError())
|
||||||
{
|
{
|
||||||
const char *varname1 = tok->strAt(1);
|
const char *varname1 = tok->strAt(1);
|
||||||
char sign1 = varsign[varname1];
|
char sign1 = varsign[varname1];
|
||||||
if (sign1 == 'u')
|
if (sign1 == 'u')
|
||||||
{
|
{
|
||||||
ErrorMessage::udivError(_errorLogger, _tokenizer, tok->next());
|
_errorLogger->udivError(_tokenizer, tok->next());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (Token::Match(tok, "[([=*/+-] - %num% / %var%"))
|
else if (Token::Match(tok, "[([=*/+-] - %num% / %var%"))
|
||||||
{
|
{
|
||||||
if (ErrorMessage::udivError())
|
if (ErrorLogger::udivError())
|
||||||
{
|
{
|
||||||
const char *varname2 = tok->strAt(4);
|
const char *varname2 = tok->strAt(4);
|
||||||
char sign2 = varsign[varname2];
|
char sign2 = varsign[varname2];
|
||||||
if (sign2 == 'u')
|
if (sign2 == 'u')
|
||||||
{
|
{
|
||||||
ErrorMessage::udivError(_errorLogger, _tokenizer, tok->next());
|
_errorLogger->udivError(_tokenizer, tok->next());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -588,7 +587,7 @@ void CheckOther::CheckVariableScope_LookupVar(const Token *tok1, const char varn
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warning if "used" is true
|
// Warning if "used" is true
|
||||||
ErrorMessage::variableScope(_errorLogger, _tokenizer, tok1, varname);
|
_errorLogger->variableScope(_tokenizer, tok1, varname);
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -603,7 +602,7 @@ void CheckOther::CheckConstantFunctionParameter()
|
||||||
{
|
{
|
||||||
if (Token::Match(tok, "[,(] const std :: %type% %var% [,)]"))
|
if (Token::Match(tok, "[,(] const std :: %type% %var% [,)]"))
|
||||||
{
|
{
|
||||||
ErrorMessage::passedByValue(_errorLogger, _tokenizer, tok, tok->strAt(5));
|
_errorLogger->passedByValue(_tokenizer, tok, tok->strAt(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (Token::Match(tok, "[,(] const %type% %var% [,)]"))
|
else if (Token::Match(tok, "[,(] const %type% %var% [,)]"))
|
||||||
|
@ -612,7 +611,7 @@ void CheckOther::CheckConstantFunctionParameter()
|
||||||
const std::string pattern(std::string("class|struct ") + tok->strAt(2));
|
const std::string pattern(std::string("class|struct ") + tok->strAt(2));
|
||||||
if (Token::findmatch(_tokenizer->tokens(), pattern.c_str()))
|
if (Token::findmatch(_tokenizer->tokens(), pattern.c_str()))
|
||||||
{
|
{
|
||||||
ErrorMessage::passedByValue(_errorLogger, _tokenizer, tok, tok->strAt(3));
|
_errorLogger->passedByValue(_tokenizer, tok, tok->strAt(3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -680,7 +679,7 @@ void CheckOther::CheckStructMemberUsage()
|
||||||
|
|
||||||
if (! used)
|
if (! used)
|
||||||
{
|
{
|
||||||
ErrorMessage::unusedStructMember(_errorLogger, _tokenizer, tok->next(), structname, varname);
|
_errorLogger->unusedStructMember(_tokenizer, tok->next(), structname, varname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -723,7 +722,7 @@ void CheckOther::CheckCharVariable()
|
||||||
std::string temp = "%var% [ " + tok->str() + " ]";
|
std::string temp = "%var% [ " + tok->str() + " ]";
|
||||||
if ((tok2->str() != ".") && Token::Match(tok2->next(), temp.c_str()))
|
if ((tok2->str() != ".") && Token::Match(tok2->next(), temp.c_str()))
|
||||||
{
|
{
|
||||||
ErrorMessage::charArrayIndex(_errorLogger, _tokenizer, tok2->next());
|
_errorLogger->charArrayIndex(_tokenizer, tok2->next());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -731,7 +730,7 @@ void CheckOther::CheckCharVariable()
|
||||||
std::string tempSecond = tok->str() + " [&|]";
|
std::string tempSecond = tok->str() + " [&|]";
|
||||||
if (Token::Match(tok2, tempFirst.c_str()) || Token::Match(tok2, tempSecond.c_str()))
|
if (Token::Match(tok2, tempFirst.c_str()) || Token::Match(tok2, tempSecond.c_str()))
|
||||||
{
|
{
|
||||||
ErrorMessage::charBitOp(_errorLogger, _tokenizer, tok2);
|
_errorLogger->charBitOp(_tokenizer, tok2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -765,12 +764,12 @@ void CheckOther::CheckIncompleteStatement()
|
||||||
|
|
||||||
if (Token::Match(tok, "[;{}] %str%") && !Token::Match(tok->tokAt(2), "[,}]"))
|
if (Token::Match(tok, "[;{}] %str%") && !Token::Match(tok->tokAt(2), "[,}]"))
|
||||||
{
|
{
|
||||||
ErrorMessage::constStatement(_errorLogger, _tokenizer, tok->next(), "string");
|
_errorLogger->constStatement(_tokenizer, tok->next(), "string");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Token::Match(tok, "[;{}] %num%") && !Token::Match(tok->tokAt(2), "[,}]"))
|
if (Token::Match(tok, "[;{}] %num%") && !Token::Match(tok->tokAt(2), "[,}]"))
|
||||||
{
|
{
|
||||||
ErrorMessage::constStatement(_errorLogger, _tokenizer, tok->next(), "numeric");
|
_errorLogger->constStatement(_tokenizer, tok->next(), "numeric");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -805,12 +804,12 @@ void CheckOther::strPlusChar()
|
||||||
// char constant..
|
// char constant..
|
||||||
const char *s = tok->strAt(3);
|
const char *s = tok->strAt(3);
|
||||||
if (*s == '\'')
|
if (*s == '\'')
|
||||||
ErrorMessage::strPlusChar(_errorLogger, _tokenizer, tok->next());
|
_errorLogger->strPlusChar(_tokenizer, tok->next());
|
||||||
|
|
||||||
// char variable..
|
// char variable..
|
||||||
unsigned int varid = tok->tokAt(3)->varId();
|
unsigned int varid = tok->tokAt(3)->varId();
|
||||||
if (varid > 0 && varid < 10000 && charVars[varid])
|
if (varid > 0 && varid < 10000 && charVars[varid])
|
||||||
ErrorMessage::strPlusChar(_errorLogger, _tokenizer, tok->next());
|
_errorLogger->strPlusChar(_tokenizer, tok->next());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -856,7 +855,7 @@ void CheckOther::returnPointerToStackData()
|
||||||
{
|
{
|
||||||
unsigned int varid = tok->next()->varId();
|
unsigned int varid = tok->next()->varId();
|
||||||
if (varid > 0 && std::find(arrayVar.begin(), arrayVar.end(), varid) != arrayVar.end())
|
if (varid > 0 && std::find(arrayVar.begin(), arrayVar.end(), varid) != arrayVar.end())
|
||||||
ErrorMessage::returnLocalVariable(_errorLogger, _tokenizer, tok);
|
_errorLogger->returnLocalVariable(_tokenizer, tok);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,6 @@
|
||||||
#include "checkfunctionusage.h"
|
#include "checkfunctionusage.h"
|
||||||
#include "filelister.h"
|
#include "filelister.h"
|
||||||
|
|
||||||
#include "errormessage.h"
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -325,7 +323,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
||||||
// The 'memset' function can do dangerous things if used wrong.
|
// The 'memset' function can do dangerous things if used wrong.
|
||||||
// Important: The checking doesn't work on simplified tokens list.
|
// Important: The checking doesn't work on simplified tokens list.
|
||||||
CheckClass checkClass(&_tokenizer, _settings, this);
|
CheckClass checkClass(&_tokenizer, _settings, this);
|
||||||
if (ErrorMessage::memsetClass())
|
if (ErrorLogger::memsetClass())
|
||||||
checkClass.noMemset();
|
checkClass.noMemset();
|
||||||
|
|
||||||
|
|
||||||
|
@ -333,11 +331,11 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
||||||
CheckOther checkOther(&_tokenizer, _settings, this);
|
CheckOther checkOther(&_tokenizer, _settings, this);
|
||||||
|
|
||||||
// Check for unsigned divisions where one operand is signed
|
// Check for unsigned divisions where one operand is signed
|
||||||
if (ErrorMessage::udivWarning(_settings) || ErrorMessage::udivError())
|
if (ErrorLogger::udivWarning(_settings) || ErrorLogger::udivError())
|
||||||
checkOther.CheckUnsignedDivision();
|
checkOther.CheckUnsignedDivision();
|
||||||
|
|
||||||
// Give warning when using char variable as array index
|
// Give warning when using char variable as array index
|
||||||
if (ErrorMessage::charArrayIndex(_settings) || ErrorMessage::charBitOp(_settings))
|
if (ErrorLogger::charArrayIndex(_settings) || ErrorLogger::charBitOp(_settings))
|
||||||
checkOther.CheckCharVariable();
|
checkOther.CheckCharVariable();
|
||||||
|
|
||||||
_tokenizer.simplifyTokenList();
|
_tokenizer.simplifyTokenList();
|
||||||
|
@ -353,23 +351,23 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
||||||
|
|
||||||
// Memory leak
|
// Memory leak
|
||||||
CheckMemoryLeakClass checkMemoryLeak(&_tokenizer, _settings, this);
|
CheckMemoryLeakClass checkMemoryLeak(&_tokenizer, _settings, this);
|
||||||
if (ErrorMessage::memleak() || ErrorMessage::mismatchAllocDealloc())
|
if (ErrorLogger::memleak() || ErrorLogger::mismatchAllocDealloc())
|
||||||
checkMemoryLeak.CheckMemoryLeak();
|
checkMemoryLeak.CheckMemoryLeak();
|
||||||
|
|
||||||
// Check that all class constructors are ok.
|
// Check that all class constructors are ok.
|
||||||
if (ErrorMessage::noConstructor(_settings) || ErrorMessage::uninitVar())
|
if (ErrorLogger::noConstructor(_settings) || ErrorLogger::uninitVar())
|
||||||
checkClass.constructors();
|
checkClass.constructors();
|
||||||
|
|
||||||
// Check that all base classes have virtual destructors
|
// Check that all base classes have virtual destructors
|
||||||
if (ErrorMessage::virtualDestructor())
|
if (ErrorLogger::virtualDestructor())
|
||||||
checkClass.virtualDestructor();
|
checkClass.virtualDestructor();
|
||||||
|
|
||||||
// Array index out of bounds / Buffer overruns..
|
// Array index out of bounds / Buffer overruns..
|
||||||
if (ErrorMessage::arrayIndexOutOfBounds(_settings) || ErrorMessage::bufferOverrun(_settings))
|
if (ErrorLogger::arrayIndexOutOfBounds(_settings) || ErrorLogger::bufferOverrun(_settings))
|
||||||
checkBufferOverrun.bufferOverrun();
|
checkBufferOverrun.bufferOverrun();
|
||||||
|
|
||||||
// Warning upon c-style pointer casts
|
// Warning upon c-style pointer casts
|
||||||
if (ErrorMessage::cstyleCast(_settings))
|
if (ErrorLogger::cstyleCast(_settings))
|
||||||
{
|
{
|
||||||
const char *ext = strrchr(FileName, '.');
|
const char *ext = strrchr(FileName, '.');
|
||||||
if (ext && strcmp(ext, ".cpp") == 0)
|
if (ext && strcmp(ext, ".cpp") == 0)
|
||||||
|
@ -377,45 +375,45 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (a) delete a;
|
// if (a) delete a;
|
||||||
if (ErrorMessage::redundantIfDelete0(_settings))
|
if (ErrorLogger::redundantIfDelete0(_settings))
|
||||||
checkOther.WarningRedundantCode();
|
checkOther.WarningRedundantCode();
|
||||||
|
|
||||||
// strtol and strtoul usage
|
// strtol and strtoul usage
|
||||||
if (ErrorMessage::dangerousUsageStrtol() ||
|
if (ErrorLogger::dangerousUsageStrtol() ||
|
||||||
ErrorMessage::sprintfOverlappingData())
|
ErrorLogger::sprintfOverlappingData())
|
||||||
checkOther.InvalidFunctionUsage();
|
checkOther.InvalidFunctionUsage();
|
||||||
|
|
||||||
// Check that all private functions are called.
|
// Check that all private functions are called.
|
||||||
if (ErrorMessage::unusedPrivateFunction(_settings))
|
if (ErrorLogger::unusedPrivateFunction(_settings))
|
||||||
checkClass.privateFunctions();
|
checkClass.privateFunctions();
|
||||||
|
|
||||||
// 'operator=' should return something..
|
// 'operator=' should return something..
|
||||||
if (ErrorMessage::operatorEq(_settings))
|
if (ErrorLogger::operatorEq(_settings))
|
||||||
checkClass.operatorEq();
|
checkClass.operatorEq();
|
||||||
|
|
||||||
// if (condition);
|
// if (condition);
|
||||||
if (ErrorMessage::ifNoAction(_settings) || ErrorMessage::conditionAlwaysTrueFalse(_settings))
|
if (ErrorLogger::ifNoAction(_settings) || ErrorLogger::conditionAlwaysTrueFalse(_settings))
|
||||||
checkOther.WarningIf();
|
checkOther.WarningIf();
|
||||||
|
|
||||||
// Unused struct members..
|
// Unused struct members..
|
||||||
if (ErrorMessage::unusedStructMember(_settings))
|
if (ErrorLogger::unusedStructMember(_settings))
|
||||||
checkOther.CheckStructMemberUsage();
|
checkOther.CheckStructMemberUsage();
|
||||||
|
|
||||||
// Check if a constant function parameter is passed by value
|
// Check if a constant function parameter is passed by value
|
||||||
if (ErrorMessage::passedByValue(_settings))
|
if (ErrorLogger::passedByValue(_settings))
|
||||||
checkOther.CheckConstantFunctionParameter();
|
checkOther.CheckConstantFunctionParameter();
|
||||||
|
|
||||||
// Variable scope (check if the scope could be limited)
|
// Variable scope (check if the scope could be limited)
|
||||||
if (ErrorMessage::variableScope())
|
if (ErrorLogger::variableScope())
|
||||||
checkOther.CheckVariableScope();
|
checkOther.CheckVariableScope();
|
||||||
|
|
||||||
// Check for various types of incomplete statements that could for example
|
// Check for various types of incomplete statements that could for example
|
||||||
// mean that an ';' has been added by accident
|
// mean that an ';' has been added by accident
|
||||||
if (ErrorMessage::constStatement(_settings))
|
if (ErrorLogger::constStatement(_settings))
|
||||||
checkOther.CheckIncompleteStatement();
|
checkOther.CheckIncompleteStatement();
|
||||||
|
|
||||||
// Unusual pointer arithmetic
|
// Unusual pointer arithmetic
|
||||||
if (ErrorMessage::strPlusChar())
|
if (ErrorLogger::strPlusChar())
|
||||||
checkOther.strPlusChar();
|
checkOther.strPlusChar();
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
|
@ -17,27 +17,26 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/
|
* along with this program. If not, see <http://www.gnu.org/licenses/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "errormessage.h"
|
|
||||||
#include "errorlogger.h"
|
#include "errorlogger.h"
|
||||||
#include "tokenize.h"
|
#include "tokenize.h"
|
||||||
#include "token.h"
|
#include "token.h"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
void ErrorMessage::_writemsg(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *tok, const char severity[], const std::string msg, const std::string &id)
|
void ErrorLogger::_writemsg(const Tokenizer *tokenizer, const Token *tok, const char severity[], const std::string msg, const std::string &id)
|
||||||
{
|
{
|
||||||
std::list<const Token *> callstack;
|
std::list<const Token *> callstack;
|
||||||
callstack.push_back(tok);
|
callstack.push_back(tok);
|
||||||
_writemsg(logger, tokenizer, callstack, severity, msg, id);
|
_writemsg(tokenizer, callstack, severity, msg, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ErrorMessage::_writemsg(ErrorLogger *logger, const Tokenizer *tokenizer, const std::list<const Token *> &callstack, const char severity[], const std::string msg, const std::string &id)
|
void ErrorLogger::_writemsg(const Tokenizer *tokenizer, const std::list<const Token *> &callstack, const char severity[], const std::string msg, const std::string &id)
|
||||||
{
|
{
|
||||||
// Todo.. callstack handling
|
// Todo.. callstack handling
|
||||||
const std::string &file(tokenizer->getFiles()->at(callstack.back()->fileIndex()));
|
const std::string &file(tokenizer->getFiles()->at(callstack.back()->fileIndex()));
|
||||||
std::ostringstream linenr;
|
std::ostringstream linenr;
|
||||||
linenr << callstack.back()->linenr();
|
linenr << callstack.back()->linenr();
|
||||||
logger->reportXml(file,
|
reportXml(file,
|
||||||
linenr.str(),
|
linenr.str(),
|
||||||
id,
|
id,
|
||||||
severity,
|
severity,
|
||||||
|
@ -46,11 +45,11 @@ void ErrorMessage::_writemsg(ErrorLogger *logger, const Tokenizer *tokenizer, co
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
for (std::list<const Token *>::const_iterator tok = callstack.begin(); tok != callstack.end(); ++tok)
|
for (std::list<const Token *>::const_iterator tok = callstack.begin(); tok != callstack.end(); ++tok)
|
||||||
ostr << (tok == callstack.begin() ? "" : " -> ") << tokenizer->fileLine(*tok);
|
ostr << (tok == callstack.begin() ? "" : " -> ") << tokenizer->fileLine(*tok);
|
||||||
logger->reportErr(ostr.str() + ": (" + severity + ") " + msg);
|
reportErr(ostr.str() + ": (" + severity + ") " + msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ErrorMessage::_writemsg(ErrorLogger *logger, const std::string msg, const std::string &id)
|
void ErrorLogger::_writemsg(const std::string msg, const std::string &id)
|
||||||
{
|
{
|
||||||
std::ostringstream xml;
|
std::ostringstream xml;
|
||||||
xml << "<error";
|
xml << "<error";
|
||||||
|
@ -58,5 +57,5 @@ void ErrorMessage::_writemsg(ErrorLogger *logger, const std::string msg, const s
|
||||||
xml << " msg=\"" << msg << "\"";
|
xml << " msg=\"" << msg << "\"";
|
||||||
xml << ">";
|
xml << ">";
|
||||||
|
|
||||||
logger->reportErr(msg);
|
reportErr(msg);
|
||||||
}
|
}
|
|
@ -17,10 +17,15 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/
|
* along with this program. If not, see <http://www.gnu.org/licenses/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef ERRORLOGGER_H
|
// THIS FILE IS GENERATED BY MACHINE, SEE ../tools/errmsg.cpp !
|
||||||
#define ERRORLOGGER_H
|
|
||||||
|
|
||||||
|
#ifndef errorloggerH
|
||||||
|
#define errorloggerH
|
||||||
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "settings.h"
|
||||||
|
class Token;
|
||||||
|
class Tokenizer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is an interface, which the class responsible of error logging
|
* This is an interface, which the class responsible of error logging
|
||||||
|
@ -29,6 +34,8 @@
|
||||||
class ErrorLogger
|
class ErrorLogger
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
ErrorLogger() { }
|
||||||
virtual ~ErrorLogger() { }
|
virtual ~ErrorLogger() { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,6 +65,326 @@ public:
|
||||||
* @param msg error message in plain text
|
* @param msg error message in plain text
|
||||||
*/
|
*/
|
||||||
virtual void reportXml(const std::string &file, const std::string &line, const std::string &id, const std::string &severity, const std::string &msg) = 0;
|
virtual void reportXml(const std::string &file, const std::string &line, const std::string &id, const std::string &severity, const std::string &msg) = 0;
|
||||||
};
|
|
||||||
|
|
||||||
#endif // #ifndef ERRORLOGGER_H
|
void arrayIndexOutOfBounds(const Tokenizer *tokenizer, const std::list<const Token *> &Location)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "all", "Array index out of bounds", "arrayIndexOutOfBounds");
|
||||||
|
}
|
||||||
|
static bool arrayIndexOutOfBounds(const Settings &s)
|
||||||
|
{
|
||||||
|
return s._showAll;
|
||||||
|
}
|
||||||
|
|
||||||
|
void bufferOverrun(const Tokenizer *tokenizer, const Token *Location)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "all", "Buffer overrun", "bufferOverrun");
|
||||||
|
}
|
||||||
|
static bool bufferOverrun(const Settings &s)
|
||||||
|
{
|
||||||
|
return s._showAll;
|
||||||
|
}
|
||||||
|
|
||||||
|
void outOfBounds(const Tokenizer *tokenizer, const Token *Location, const std::string &what)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "error", "" + what + " is out of bounds", "outOfBounds");
|
||||||
|
}
|
||||||
|
static bool outOfBounds()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void noConstructor(const Tokenizer *tokenizer, const Token *Location, const std::string &classname)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "style", "The class '" + classname + "' has no constructor", "noConstructor");
|
||||||
|
}
|
||||||
|
static bool noConstructor(const Settings &s)
|
||||||
|
{
|
||||||
|
return s._checkCodingStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void uninitVar(const Tokenizer *tokenizer, const Token *Location, const std::string &classname, const std::string &varname)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "error", "Uninitialized member variable '" + classname + "::" + varname + "'", "uninitVar");
|
||||||
|
}
|
||||||
|
static bool uninitVar()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void unusedPrivateFunction(const Tokenizer *tokenizer, const Token *Location, const std::string &classname, const std::string &funcname)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "style", "Unused private function '" + classname + "::" + funcname + "'", "unusedPrivateFunction");
|
||||||
|
}
|
||||||
|
static bool unusedPrivateFunction(const Settings &s)
|
||||||
|
{
|
||||||
|
return s._checkCodingStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void memsetClass(const Tokenizer *tokenizer, const Token *Location, const std::string &memfunc)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "error", "Using '" + memfunc + "' on class", "memsetClass");
|
||||||
|
}
|
||||||
|
static bool memsetClass()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void memsetStruct(const Tokenizer *tokenizer, const Token *Location, const std::string &memfunc, const std::string &classname)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "error", "Using '" + memfunc + "' on struct that contains a 'std::" + classname + "'", "memsetStruct");
|
||||||
|
}
|
||||||
|
static bool memsetStruct()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void operatorEq(const Tokenizer *tokenizer, const Token *Location)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "style", "'operator=' should return something", "operatorEq");
|
||||||
|
}
|
||||||
|
static bool operatorEq(const Settings &s)
|
||||||
|
{
|
||||||
|
return s._checkCodingStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void virtualDestructor(const Tokenizer *tokenizer, const Token *Location, const std::string &Base, const std::string &Derived)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "error", "Class " + Base + " which is inherited by class " + Derived + " does not have a virtual destructor", "virtualDestructor");
|
||||||
|
}
|
||||||
|
static bool virtualDestructor()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void unusedFunction(const std::string &filename, const std::string &funcname)
|
||||||
|
{
|
||||||
|
_writemsg("[" + filename + "]: The function '" + funcname + "' is never used", "unusedFunction");
|
||||||
|
}
|
||||||
|
static bool unusedFunction(const Settings &s)
|
||||||
|
{
|
||||||
|
return s._checkCodingStyle || s._showAll;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mismatchAllocDealloc(const Tokenizer *tokenizer, const std::list<const Token *> &Location, const std::string &varname)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "error", "Mismatching allocation and deallocation: " + varname + "", "mismatchAllocDealloc");
|
||||||
|
}
|
||||||
|
static bool mismatchAllocDealloc()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void memleak(const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "error", "Memory leak: " + varname + "", "memleak");
|
||||||
|
}
|
||||||
|
static bool memleak()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void memleakall(const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "all", "Memory leak: " + varname + "", "memleakall");
|
||||||
|
}
|
||||||
|
static bool memleakall(const Settings &s)
|
||||||
|
{
|
||||||
|
return s._showAll;
|
||||||
|
}
|
||||||
|
|
||||||
|
void resourceLeak(const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "error", "Resource leak: " + varname + "", "resourceLeak");
|
||||||
|
}
|
||||||
|
static bool resourceLeak()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void deallocDealloc(const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "error", "Deallocating a deallocated pointer: " + varname + "", "deallocDealloc");
|
||||||
|
}
|
||||||
|
static bool deallocDealloc()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void deallocuse(const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "error", "Using '" + varname + "' after it is deallocated / released", "deallocuse");
|
||||||
|
}
|
||||||
|
static bool deallocuse()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mismatchSize(const Tokenizer *tokenizer, const Token *Location, const std::string &sz)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "error", "The given size " + sz + " is mismatching", "mismatchSize");
|
||||||
|
}
|
||||||
|
static bool mismatchSize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cstyleCast(const Tokenizer *tokenizer, const Token *Location)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "style", "C-style pointer casting", "cstyleCast");
|
||||||
|
}
|
||||||
|
static bool cstyleCast(const Settings &s)
|
||||||
|
{
|
||||||
|
return s._checkCodingStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void redundantIfDelete0(const Tokenizer *tokenizer, const Token *Location)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "style", "Redundant condition. It is safe to deallocate a NULL pointer", "redundantIfDelete0");
|
||||||
|
}
|
||||||
|
static bool redundantIfDelete0(const Settings &s)
|
||||||
|
{
|
||||||
|
return s._checkCodingStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void redundantIfRemove(const Tokenizer *tokenizer, const Token *Location)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "style", "Redundant condition. The remove function in the STL will not do anything if element doesn't exist", "redundantIfRemove");
|
||||||
|
}
|
||||||
|
static bool redundantIfRemove(const Settings &s)
|
||||||
|
{
|
||||||
|
return s._checkCodingStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dangerousUsageStrtol(const Tokenizer *tokenizer, const Token *Location)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "error", "Invalid radix in call to strtol or strtoul. Must be 0 or 2-36", "dangerousUsageStrtol");
|
||||||
|
}
|
||||||
|
static bool dangerousUsageStrtol()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ifNoAction(const Tokenizer *tokenizer, const Token *Location)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "style", "Found redundant if condition - 'if (condition);'", "ifNoAction");
|
||||||
|
}
|
||||||
|
static bool ifNoAction(const Settings &s)
|
||||||
|
{
|
||||||
|
return s._checkCodingStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sprintfOverlappingData(const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "error", "Overlapping data buffer " + varname + "", "sprintfOverlappingData");
|
||||||
|
}
|
||||||
|
static bool sprintfOverlappingData()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void udivError(const Tokenizer *tokenizer, const Token *Location)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "error", "Unsigned division. The result will be wrong.", "udivError");
|
||||||
|
}
|
||||||
|
static bool udivError()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void udivWarning(const Tokenizer *tokenizer, const Token *Location)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "all style", "Warning: Division with signed and unsigned operators", "udivWarning");
|
||||||
|
}
|
||||||
|
static bool udivWarning(const Settings &s)
|
||||||
|
{
|
||||||
|
return s._checkCodingStyle || s._showAll;
|
||||||
|
}
|
||||||
|
|
||||||
|
void unusedStructMember(const Tokenizer *tokenizer, const Token *Location, const std::string &structname, const std::string &varname)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "style", "struct or union member '" + structname + "::" + varname + "' is never used", "unusedStructMember");
|
||||||
|
}
|
||||||
|
static bool unusedStructMember(const Settings &s)
|
||||||
|
{
|
||||||
|
return s._checkCodingStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void passedByValue(const Tokenizer *tokenizer, const Token *Location, const std::string &parname)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "style", "Function parameter '" + parname + "' is passed by value. It could be passed by reference instead.", "passedByValue");
|
||||||
|
}
|
||||||
|
static bool passedByValue(const Settings &s)
|
||||||
|
{
|
||||||
|
return s._checkCodingStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void constStatement(const Tokenizer *tokenizer, const Token *Location, const std::string &type)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "style", "Redundant code: Found a statement that begins with " + type + " constant", "constStatement");
|
||||||
|
}
|
||||||
|
static bool constStatement(const Settings &s)
|
||||||
|
{
|
||||||
|
return s._checkCodingStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void charArrayIndex(const Tokenizer *tokenizer, const Token *Location)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "style", "Warning - using char variable as array index", "charArrayIndex");
|
||||||
|
}
|
||||||
|
static bool charArrayIndex(const Settings &s)
|
||||||
|
{
|
||||||
|
return s._checkCodingStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void charBitOp(const Tokenizer *tokenizer, const Token *Location)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "style", "Warning - using char variable in bit operation", "charBitOp");
|
||||||
|
}
|
||||||
|
static bool charBitOp(const Settings &s)
|
||||||
|
{
|
||||||
|
return s._checkCodingStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void variableScope(const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "never", "The scope of the variable " + varname + " can be limited", "variableScope");
|
||||||
|
}
|
||||||
|
static bool variableScope()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void conditionAlwaysTrueFalse(const Tokenizer *tokenizer, const Token *Location, const std::string &truefalse)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "style", "Condition is always " + truefalse + "", "conditionAlwaysTrueFalse");
|
||||||
|
}
|
||||||
|
static bool conditionAlwaysTrueFalse(const Settings &s)
|
||||||
|
{
|
||||||
|
return s._checkCodingStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void strPlusChar(const Tokenizer *tokenizer, const Token *Location)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "error", "Unusual pointer arithmetic", "strPlusChar");
|
||||||
|
}
|
||||||
|
static bool strPlusChar()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void returnLocalVariable(const Tokenizer *tokenizer, const Token *Location)
|
||||||
|
{
|
||||||
|
_writemsg(tokenizer, Location, "error", "Returning pointer to local array variable", "returnLocalVariable");
|
||||||
|
}
|
||||||
|
static bool returnLocalVariable()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
void _writemsg(const Tokenizer *tokenizer, const Token *tok, const char severity[], const std::string msg, const std::string &id);
|
||||||
|
void _writemsg(const Tokenizer *tokenizer, const std::list<const Token *> &callstack, const char severity[], const std::string msg, const std::string &id);
|
||||||
|
void _writemsg(const std::string msg, const std::string &id);
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,354 +0,0 @@
|
||||||
/*
|
|
||||||
* Cppcheck - A tool for static C/C++ code analysis
|
|
||||||
* Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam,
|
|
||||||
* Leandro Penz, Kimmo Varis
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/
|
|
||||||
*/
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY MACHINE, SEE ../tools/errmsg.cpp !
|
|
||||||
|
|
||||||
#ifndef errormessageH
|
|
||||||
#define errormessageH
|
|
||||||
#include <list>
|
|
||||||
#include <string>
|
|
||||||
#include "settings.h"
|
|
||||||
class ErrorLogger;
|
|
||||||
class Token;
|
|
||||||
class Tokenizer;
|
|
||||||
class ErrorMessage
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
ErrorMessage() { }
|
|
||||||
static void _writemsg(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *tok, const char severity[], const std::string msg, const std::string &id);
|
|
||||||
static void _writemsg(ErrorLogger *logger, const Tokenizer *tokenizer, const std::list<const Token *> &callstack, const char severity[], const std::string msg, const std::string &id);
|
|
||||||
static void _writemsg(ErrorLogger *logger, const std::string msg, const std::string &id);
|
|
||||||
public:
|
|
||||||
static void arrayIndexOutOfBounds(ErrorLogger *logger, const Tokenizer *tokenizer, const std::list<const Token *> &Location)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "all", "Array index out of bounds", "arrayIndexOutOfBounds");
|
|
||||||
}
|
|
||||||
static bool arrayIndexOutOfBounds(const Settings &s)
|
|
||||||
{
|
|
||||||
return s._showAll;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void bufferOverrun(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "all", "Buffer overrun", "bufferOverrun");
|
|
||||||
}
|
|
||||||
static bool bufferOverrun(const Settings &s)
|
|
||||||
{
|
|
||||||
return s._showAll;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void outOfBounds(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &what)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "error", "" + what + " is out of bounds", "outOfBounds");
|
|
||||||
}
|
|
||||||
static bool outOfBounds()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void noConstructor(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &classname)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "style", "The class '" + classname + "' has no constructor", "noConstructor");
|
|
||||||
}
|
|
||||||
static bool noConstructor(const Settings &s)
|
|
||||||
{
|
|
||||||
return s._checkCodingStyle;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void uninitVar(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &classname, const std::string &varname)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "error", "Uninitialized member variable '" + classname + "::" + varname + "'", "uninitVar");
|
|
||||||
}
|
|
||||||
static bool uninitVar()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void unusedPrivateFunction(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &classname, const std::string &funcname)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "style", "Unused private function '" + classname + "::" + funcname + "'", "unusedPrivateFunction");
|
|
||||||
}
|
|
||||||
static bool unusedPrivateFunction(const Settings &s)
|
|
||||||
{
|
|
||||||
return s._checkCodingStyle;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void memsetClass(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &memfunc)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "error", "Using '" + memfunc + "' on class", "memsetClass");
|
|
||||||
}
|
|
||||||
static bool memsetClass()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void memsetStruct(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &memfunc, const std::string &classname)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "error", "Using '" + memfunc + "' on struct that contains a 'std::" + classname + "'", "memsetStruct");
|
|
||||||
}
|
|
||||||
static bool memsetStruct()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void operatorEq(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "style", "'operator=' should return something", "operatorEq");
|
|
||||||
}
|
|
||||||
static bool operatorEq(const Settings &s)
|
|
||||||
{
|
|
||||||
return s._checkCodingStyle;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void virtualDestructor(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &Base, const std::string &Derived)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "error", "Class " + Base + " which is inherited by class " + Derived + " does not have a virtual destructor", "virtualDestructor");
|
|
||||||
}
|
|
||||||
static bool virtualDestructor()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void unusedFunction(ErrorLogger *logger, const std::string &filename, const std::string &funcname)
|
|
||||||
{
|
|
||||||
_writemsg(logger, "[" + filename + "]: The function '" + funcname + "' is never used", "unusedFunction");
|
|
||||||
}
|
|
||||||
static bool unusedFunction(const Settings &s)
|
|
||||||
{
|
|
||||||
return s._checkCodingStyle || s._showAll;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mismatchAllocDealloc(ErrorLogger *logger, const Tokenizer *tokenizer, const std::list<const Token *> &Location, const std::string &varname)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "error", "Mismatching allocation and deallocation: " + varname + "", "mismatchAllocDealloc");
|
|
||||||
}
|
|
||||||
static bool mismatchAllocDealloc()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void memleak(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "error", "Memory leak: " + varname + "", "memleak");
|
|
||||||
}
|
|
||||||
static bool memleak()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void memleakall(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "all", "Memory leak: " + varname + "", "memleakall");
|
|
||||||
}
|
|
||||||
static bool memleakall(const Settings &s)
|
|
||||||
{
|
|
||||||
return s._showAll;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void resourceLeak(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "error", "Resource leak: " + varname + "", "resourceLeak");
|
|
||||||
}
|
|
||||||
static bool resourceLeak()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void deallocDealloc(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "error", "Deallocating a deallocated pointer: " + varname + "", "deallocDealloc");
|
|
||||||
}
|
|
||||||
static bool deallocDealloc()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void deallocuse(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "error", "Using '" + varname + "' after it is deallocated / released", "deallocuse");
|
|
||||||
}
|
|
||||||
static bool deallocuse()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mismatchSize(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &sz)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "error", "The given size " + sz + " is mismatching", "mismatchSize");
|
|
||||||
}
|
|
||||||
static bool mismatchSize()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void cstyleCast(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "style", "C-style pointer casting", "cstyleCast");
|
|
||||||
}
|
|
||||||
static bool cstyleCast(const Settings &s)
|
|
||||||
{
|
|
||||||
return s._checkCodingStyle;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void redundantIfDelete0(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "style", "Redundant condition. It is safe to deallocate a NULL pointer", "redundantIfDelete0");
|
|
||||||
}
|
|
||||||
static bool redundantIfDelete0(const Settings &s)
|
|
||||||
{
|
|
||||||
return s._checkCodingStyle;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void redundantIfRemove(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "style", "Redundant condition. The remove function in the STL will not do anything if element doesn't exist", "redundantIfRemove");
|
|
||||||
}
|
|
||||||
static bool redundantIfRemove(const Settings &s)
|
|
||||||
{
|
|
||||||
return s._checkCodingStyle;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dangerousUsageStrtol(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "error", "Invalid radix in call to strtol or strtoul. Must be 0 or 2-36", "dangerousUsageStrtol");
|
|
||||||
}
|
|
||||||
static bool dangerousUsageStrtol()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ifNoAction(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "style", "Found redundant if condition - 'if (condition);'", "ifNoAction");
|
|
||||||
}
|
|
||||||
static bool ifNoAction(const Settings &s)
|
|
||||||
{
|
|
||||||
return s._checkCodingStyle;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void sprintfOverlappingData(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "error", "Overlapping data buffer " + varname + "", "sprintfOverlappingData");
|
|
||||||
}
|
|
||||||
static bool sprintfOverlappingData()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void udivError(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "error", "Unsigned division. The result will be wrong.", "udivError");
|
|
||||||
}
|
|
||||||
static bool udivError()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void udivWarning(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "all style", "Warning: Division with signed and unsigned operators", "udivWarning");
|
|
||||||
}
|
|
||||||
static bool udivWarning(const Settings &s)
|
|
||||||
{
|
|
||||||
return s._checkCodingStyle || s._showAll;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void unusedStructMember(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &structname, const std::string &varname)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "style", "struct or union member '" + structname + "::" + varname + "' is never used", "unusedStructMember");
|
|
||||||
}
|
|
||||||
static bool unusedStructMember(const Settings &s)
|
|
||||||
{
|
|
||||||
return s._checkCodingStyle;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void passedByValue(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &parname)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "style", "Function parameter '" + parname + "' is passed by value. It could be passed by reference instead.", "passedByValue");
|
|
||||||
}
|
|
||||||
static bool passedByValue(const Settings &s)
|
|
||||||
{
|
|
||||||
return s._checkCodingStyle;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void constStatement(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &type)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "style", "Redundant code: Found a statement that begins with " + type + " constant", "constStatement");
|
|
||||||
}
|
|
||||||
static bool constStatement(const Settings &s)
|
|
||||||
{
|
|
||||||
return s._checkCodingStyle;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void charArrayIndex(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "style", "Warning - using char variable as array index", "charArrayIndex");
|
|
||||||
}
|
|
||||||
static bool charArrayIndex(const Settings &s)
|
|
||||||
{
|
|
||||||
return s._checkCodingStyle;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void charBitOp(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "style", "Warning - using char variable in bit operation", "charBitOp");
|
|
||||||
}
|
|
||||||
static bool charBitOp(const Settings &s)
|
|
||||||
{
|
|
||||||
return s._checkCodingStyle;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void variableScope(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "never", "The scope of the variable " + varname + " can be limited", "variableScope");
|
|
||||||
}
|
|
||||||
static bool variableScope()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void conditionAlwaysTrueFalse(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &truefalse)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "style", "Condition is always " + truefalse + "", "conditionAlwaysTrueFalse");
|
|
||||||
}
|
|
||||||
static bool conditionAlwaysTrueFalse(const Settings &s)
|
|
||||||
{
|
|
||||||
return s._checkCodingStyle;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void strPlusChar(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "error", "Unusual pointer arithmetic", "strPlusChar");
|
|
||||||
}
|
|
||||||
static bool strPlusChar()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void returnLocalVariable(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location)
|
|
||||||
{
|
|
||||||
_writemsg(logger, tokenizer, Location, "error", "Returning pointer to local array variable", "returnLocalVariable");
|
|
||||||
}
|
|
||||||
static bool returnLocalVariable()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
#endif
|
|
|
@ -138,9 +138,9 @@ int main()
|
||||||
fout << "\n\tg++ $(CXXFLAGS) -c -o " << objfile(testfiles[i]) << " " << testfiles[i] << "\n\n";
|
fout << "\n\tg++ $(CXXFLAGS) -c -o " << objfile(testfiles[i]) << " " << testfiles[i] << "\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
fout << "src/errormessage.h:\ttools/errmsg\n";
|
fout << "src/errorlogger.h:\ttools/errmsg\n";
|
||||||
fout << "\ttools/errmsg\n";
|
fout << "\ttools/errmsg\n";
|
||||||
fout << "\tmv errormessage.h src/\n\n";
|
fout << "\tmv errorlogger.h src/\n\n";
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ int main()
|
||||||
|
|
||||||
// Generate code..
|
// Generate code..
|
||||||
std::cout << "Generate code.." << std::endl;
|
std::cout << "Generate code.." << std::endl;
|
||||||
std::ofstream fout("errormessage.h");
|
std::ofstream fout("errorlogger.h");
|
||||||
|
|
||||||
fout << "/*\n";
|
fout << "/*\n";
|
||||||
fout << " * Cppcheck - A tool for static C/C++ code analysis\n";
|
fout << " * Cppcheck - A tool for static C/C++ code analysis\n";
|
||||||
|
@ -128,24 +128,61 @@ int main()
|
||||||
fout << " * along with this program. If not, see <http://www.gnu.org/licenses/\n";
|
fout << " * along with this program. If not, see <http://www.gnu.org/licenses/\n";
|
||||||
fout << " */\n\n";
|
fout << " */\n\n";
|
||||||
fout << "// THIS FILE IS GENERATED BY MACHINE, SEE ../tools/errmsg.cpp !\n\n";
|
fout << "// THIS FILE IS GENERATED BY MACHINE, SEE ../tools/errmsg.cpp !\n\n";
|
||||||
fout << "#ifndef errormessageH\n";
|
fout << "#ifndef errorloggerH\n";
|
||||||
fout << "#define errormessageH\n";
|
fout << "#define errorloggerH\n";
|
||||||
fout << "#include <list>\n";
|
fout << "#include <list>\n";
|
||||||
fout << "#include <string>\n";
|
fout << "#include <string>\n";
|
||||||
fout << "#include \"settings.h\"\n";
|
fout << "#include \"settings.h\"\n";
|
||||||
fout << "class ErrorLogger;\n";
|
|
||||||
fout << "class Token;\n";
|
fout << "class Token;\n";
|
||||||
fout << "class Tokenizer;\n";
|
fout << "class Tokenizer;\n";
|
||||||
fout << "class ErrorMessage\n";
|
fout << "\n";
|
||||||
|
fout << "/**\n";
|
||||||
|
fout << " * This is an interface, which the class responsible of error logging\n";
|
||||||
|
fout << " * should implement.\n";
|
||||||
|
fout << " */\n";
|
||||||
|
fout << "class ErrorLogger\n";
|
||||||
fout << "{\n";
|
fout << "{\n";
|
||||||
fout << "private:\n";
|
|
||||||
fout << " ErrorMessage() { }\n";
|
|
||||||
fout << " static void _writemsg(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *tok, const char severity[], const std::string msg, const std::string &id);\n";
|
|
||||||
fout << " static void _writemsg(ErrorLogger *logger, const Tokenizer *tokenizer, const std::list<const Token *> &callstack, const char severity[], const std::string msg, const std::string &id);\n";
|
|
||||||
fout << " static void _writemsg(ErrorLogger *logger, const std::string msg, const std::string &id);\n";
|
|
||||||
fout << "public:\n";
|
fout << "public:\n";
|
||||||
|
fout << "\n";
|
||||||
|
fout << " ErrorLogger() { }\n";
|
||||||
|
fout << " virtual ~ErrorLogger() { }\n";
|
||||||
|
fout << "\n";
|
||||||
|
fout << " /**\n";
|
||||||
|
fout << " * Errors and warnings are directed here.\n";
|
||||||
|
fout << " *\n";
|
||||||
|
fout << " * @param errmsg Errors messages are normally in format\n";
|
||||||
|
fout << " * \"[filepath:line number] Message\", e.g.\n";
|
||||||
|
fout << " * \"[main.cpp:4] Uninitialized member variable\"\n";
|
||||||
|
fout << " */\n";
|
||||||
|
fout << " virtual void reportErr(const std::string &errmsg) = 0;\n";
|
||||||
|
fout << "\n";
|
||||||
|
fout << " /**\n";
|
||||||
|
fout << " * Information about progress is directed here.\n";
|
||||||
|
fout << " *\n";
|
||||||
|
fout << " * @param outmsg, E.g. \"Checking main.cpp...\"\n";
|
||||||
|
fout << " */\n";
|
||||||
|
fout << " virtual void reportOut(const std::string &outmsg) = 0;\n";
|
||||||
|
fout << "\n";
|
||||||
|
fout << " /**\n";
|
||||||
|
fout << " * XML output of error / warning\n";
|
||||||
|
fout << " * Todo: callstack handling\n";
|
||||||
|
fout << " *\n";
|
||||||
|
fout << " * @param file filepath (can be \"\")\n";
|
||||||
|
fout << " * @param line line (can be \"\")\n";
|
||||||
|
fout << " * @param id error id (function name)\n";
|
||||||
|
fout << " * @param severity severity of error (always, all, style, all+style, never)\n";
|
||||||
|
fout << " * @param msg error message in plain text\n";
|
||||||
|
fout << " */\n";
|
||||||
|
fout << " virtual void reportXml(const std::string &file, const std::string &line, const std::string &id, const std::string &severity, const std::string &msg) = 0;\n";
|
||||||
|
fout << "\n";
|
||||||
|
|
||||||
for (std::list<Message>::const_iterator it = err.begin(); it != err.end(); ++it)
|
for (std::list<Message>::const_iterator it = err.begin(); it != err.end(); ++it)
|
||||||
it->generateCode(fout);
|
it->generateCode(fout);
|
||||||
|
fout << "\n";
|
||||||
|
fout << "private:\n";
|
||||||
|
fout << " void _writemsg(const Tokenizer *tokenizer, const Token *tok, const char severity[], const std::string msg, const std::string &id);\n";
|
||||||
|
fout << " void _writemsg(const Tokenizer *tokenizer, const std::list<const Token *> &callstack, const char severity[], const std::string msg, const std::string &id);\n";
|
||||||
|
fout << " void _writemsg(const std::string msg, const std::string &id);\n";
|
||||||
fout << "};\n";
|
fout << "};\n";
|
||||||
fout << "#endif\n";
|
fout << "#endif\n";
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
@ -224,7 +261,7 @@ void Message::generateCode(std::ostream &ostr) const
|
||||||
bool loc = bool(_msg.substr(0, 4) != "[%1]");
|
bool loc = bool(_msg.substr(0, 4) != "[%1]");
|
||||||
|
|
||||||
// Error message..
|
// Error message..
|
||||||
ostr << " static void " << _funcname << "(ErrorLogger *logger, ";
|
ostr << " void " << _funcname << "(";
|
||||||
if (loc)
|
if (loc)
|
||||||
{
|
{
|
||||||
ostr << "const Tokenizer *tokenizer, ";
|
ostr << "const Tokenizer *tokenizer, ";
|
||||||
|
@ -245,7 +282,7 @@ void Message::generateCode(std::ostream &ostr) const
|
||||||
ostr << ", const std::string &" << _par2;
|
ostr << ", const std::string &" << _par2;
|
||||||
ostr << ")\n";
|
ostr << ")\n";
|
||||||
ostr << " {\n";
|
ostr << " {\n";
|
||||||
ostr << " _writemsg(logger, ";
|
ostr << " _writemsg(";
|
||||||
if (loc)
|
if (loc)
|
||||||
ostr << "tokenizer, Location, \"" << stringifySettings(true) << "\", ";
|
ostr << "tokenizer, Location, \"" << stringifySettings(true) << "\", ";
|
||||||
ostr << msg(true) << ", \"" << _funcname << "\");\n";
|
ostr << msg(true) << ", \"" << _funcname << "\");\n";
|
||||||
|
|
Loading…
Reference in New Issue