Merge branch 'master' of github.com:danmar/cppcheck into wix
This commit is contained in:
commit
05bd91b9fc
2
Makefile
2
Makefile
|
@ -1,4 +1,4 @@
|
|||
CXXFLAGS=-Wall -Wextra -pedantic -g
|
||||
CXXFLAGS=-Wall -Wextra -pedantic -Wfloat-equal -Wcast-qual -Wlogical-op -g -D_GLIBCXX_DEBUG
|
||||
CXX=g++
|
||||
BIN=${DESTDIR}/usr/bin
|
||||
|
||||
|
|
|
@ -26,9 +26,8 @@ win32 {
|
|||
}
|
||||
|
||||
# Add more strict compiling flags for GCC
|
||||
# These flags are used in original (not generated by QMake) makefiles
|
||||
contains(QMAKE_CXX, g++) {
|
||||
QMAKE_CXXFLAGS_WARN_ON += -Wextra -pedantic
|
||||
QMAKE_CXXFLAGS_WARN_ON += -Wextra -pedantic -Wfloat-equal -Wcast-qual -Wlogical-op
|
||||
|
||||
CONFIG(debug, debug|release) {
|
||||
# checked STL
|
||||
|
|
|
@ -10,14 +10,29 @@
|
|||
# - win_installer/productInfo.wxs
|
||||
|
||||
# Tag to use
|
||||
tag=1.41
|
||||
tag=$1
|
||||
|
||||
# Name of release
|
||||
releasename=cppcheck-$tag
|
||||
|
||||
# wget http://josefsson.org/git2cl/git2cl
|
||||
echo Update Changelog..
|
||||
./git2cl > ChangeLog
|
||||
|
||||
echo Update Makefile..
|
||||
git tag -d $tag
|
||||
g++ -o dmake tools/dmake.cpp lib/filelister.cpp
|
||||
./dmake --release
|
||||
git commit -a -m "Makefile: Set release mode"
|
||||
git tag $tag
|
||||
|
||||
echo Create archives..
|
||||
git archive --format=tar --prefix=$releasename/ $tag | gzip > ~/$releasename.tar.gz
|
||||
git archive --format=tar --prefix=$releasename/ $tag | bzip2 > ~/$releasename.tar.bz2
|
||||
git archive --format=zip -9 --prefix=$releasename/ $tag > ~/$releasename.zip
|
||||
|
||||
echo Restoring repository..
|
||||
git tag -d $tag
|
||||
git reset --hard HEAD^1
|
||||
git pull
|
||||
|
||||
|
|
|
@ -118,6 +118,10 @@ protected:
|
|||
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
||||
for (std::list<const Token *>::const_iterator it = callstack.begin(); it != callstack.end(); ++it)
|
||||
{
|
||||
// --errorlist can provide null values here
|
||||
if (!(*it))
|
||||
continue;
|
||||
|
||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
||||
loc.line = (*it)->linenr();
|
||||
loc.file = _tokenizer->file(*it);
|
||||
|
|
|
@ -182,11 +182,8 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
|
|||
for (unsigned int i = 0; i < varname.size(); ++i)
|
||||
varnames += (i == 0 ? "" : " . ") + varname[i];
|
||||
|
||||
unsigned int varc = varname.size();
|
||||
if (varc == 0)
|
||||
varc = 1;
|
||||
const unsigned int varc(varname.empty() ? 0 : (varname.size() - 1) * 2);
|
||||
|
||||
varc = 2 * (varc - 1);
|
||||
if (Token::Match(tok, "return"))
|
||||
{
|
||||
tok = tok->next();
|
||||
|
@ -584,8 +581,8 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
|
|||
if ((varid > 0 && Token::Match(tok, "strcpy|strcat ( %varid% , %str% )", varid)) ||
|
||||
(varid == 0 && Token::Match(tok, ("strcpy|strcat ( " + varnames + " , %str% )").c_str())))
|
||||
{
|
||||
size_t len = Token::getStrLength(tok->tokAt(varc + 4));
|
||||
if (len >= static_cast<size_t>(total_size))
|
||||
long len = Token::getStrLength(tok->tokAt(varc + 4));
|
||||
if (len < 0 || len >= total_size)
|
||||
{
|
||||
bufferOverrun(tok, varid > 0 ? "" : varnames.c_str());
|
||||
continue;
|
||||
|
@ -597,8 +594,8 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
|
|||
Token::Match(tok, "read|write ( %any% , %varid% , %num% )", varid) &&
|
||||
MathLib::isInt(tok->strAt(6)))
|
||||
{
|
||||
size_t len = MathLib::toLongNumber(tok->strAt(6));
|
||||
if (len > static_cast<size_t>(total_size))
|
||||
long len = MathLib::toLongNumber(tok->strAt(6));
|
||||
if (len < 0 || len > total_size)
|
||||
{
|
||||
bufferOverrun(tok);
|
||||
continue;
|
||||
|
@ -610,8 +607,8 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
|
|||
Token::Match(tok, "fgets ( %varid% , %num% , %any% )", varid) &&
|
||||
MathLib::isInt(tok->strAt(4)))
|
||||
{
|
||||
size_t len = MathLib::toLongNumber(tok->strAt(4));
|
||||
if (len > static_cast<size_t>(total_size))
|
||||
long len = MathLib::toLongNumber(tok->strAt(4));
|
||||
if (len < 0 || len > total_size)
|
||||
{
|
||||
bufferOverrun(tok);
|
||||
continue;
|
||||
|
@ -622,7 +619,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
|
|||
if (varid > 0 && Token::Match(tok, "strncat ( %varid% , %any% , %num% )", varid))
|
||||
{
|
||||
int n = MathLib::toLongNumber(tok->strAt(6));
|
||||
if (n >= total_size)
|
||||
if (n < 0 || n >= total_size)
|
||||
strncatUsage(tok);
|
||||
}
|
||||
|
||||
|
|
|
@ -1593,7 +1593,7 @@ void CheckClass::checkConst()
|
|||
for (int k = nestInfo.size() - 2; k >= 0; k--)
|
||||
classname = std::string(nestInfo[k].className + "::" + classname);
|
||||
|
||||
checkConstError2(found, tok2, classname, functionName);
|
||||
checkConstError(found, classname, functionName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1785,14 +1785,6 @@ void CheckClass::checkConstError(const Token *tok, const std::string &classname,
|
|||
reportError(tok, Severity::style, "functionConst", "The function '" + classname + "::" + funcname + "' can be const");
|
||||
}
|
||||
|
||||
void CheckClass::checkConstError2(const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname)
|
||||
{
|
||||
std::list<const Token *> toks;
|
||||
toks.push_back(tok1);
|
||||
toks.push_back(tok2);
|
||||
reportError(toks, Severity::style, "functionConst", "The function '" + classname + "::" + funcname + "' can be const");
|
||||
}
|
||||
|
||||
void CheckClass::noConstructorError(const Token *tok, const std::string &classname, bool isStruct)
|
||||
{
|
||||
reportError(tok, Severity::style, "noConstructor", "The " + std::string(isStruct ? "struct" : "class") + " '" + classname + "' has no constructor. Member variables not initialized.");
|
||||
|
|
|
@ -169,7 +169,6 @@ private:
|
|||
void operatorEqToSelfError(const Token *tok);
|
||||
|
||||
void checkConstError(const Token *tok, const std::string &classname, const std::string &funcname);
|
||||
void checkConstError2(const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname);
|
||||
|
||||
void getErrorMessages()
|
||||
{
|
||||
|
@ -185,7 +184,6 @@ private:
|
|||
operatorEqRetRefThisError(0);
|
||||
operatorEqToSelfError(0);
|
||||
checkConstError(0, "class", "function");
|
||||
checkConstError2(0, 0, "class", "function");
|
||||
}
|
||||
|
||||
std::string name() const
|
||||
|
|
|
@ -1778,20 +1778,20 @@ private:
|
|||
" int getA();\n"
|
||||
"};\n"
|
||||
"int Fred::getA() { return a; }");
|
||||
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) The function 'Fred::getA' can be const\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:5]: (style) The function 'Fred::getA' can be const\n", errout.str());
|
||||
|
||||
checkConst("class Fred {\n"
|
||||
" const std::string foo();\n"
|
||||
"};\n"
|
||||
"const std::string Fred::foo() { return ""; }");
|
||||
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (style) The function 'Fred::foo' can be const\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'Fred::foo' can be const\n", errout.str());
|
||||
|
||||
checkConst("class Fred {\n"
|
||||
" std::string s;\n"
|
||||
" const std::string & foo();\n"
|
||||
"};\n"
|
||||
"const std::string & Fred::foo() { return ""; }");
|
||||
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) The function 'Fred::foo' can be const\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:5]: (style) The function 'Fred::foo' can be const\n", errout.str());
|
||||
|
||||
// constructors can't be const..
|
||||
checkConst("class Fred {\n"
|
||||
|
@ -1843,7 +1843,7 @@ private:
|
|||
" void foo(std::string & a);\n"
|
||||
"};\n"
|
||||
"void Fred::foo(std::string & a) { a = s; }");
|
||||
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) The function 'Fred::foo' can be const\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:5]: (style) The function 'Fred::foo' can be const\n", errout.str());
|
||||
|
||||
// assignment to variable can't be const
|
||||
checkConst("class Fred {\n"
|
||||
|
@ -1859,7 +1859,7 @@ private:
|
|||
" void foo(std::string & a, std::string & b);\n"
|
||||
"};\n"
|
||||
"void Fred::foo(std::string & a, std::string & b) { a = s; b = s; }");
|
||||
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) The function 'Fred::foo' can be const\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:5]: (style) The function 'Fred::foo' can be const\n", errout.str());
|
||||
|
||||
// assignment to variable, can't be const
|
||||
checkConst("class Fred {\n"
|
||||
|
@ -1891,7 +1891,7 @@ private:
|
|||
" void foo(int * a);\n"
|
||||
"};\n"
|
||||
"void Fred::foo(int * a) { *a = s; }");
|
||||
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) The function 'Fred::foo' can be const\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:5]: (style) The function 'Fred::foo' can be const\n", errout.str());
|
||||
|
||||
// assignment to variable, can't be const
|
||||
checkConst("class Fred {\n"
|
||||
|
@ -1907,7 +1907,7 @@ private:
|
|||
" void foo(std::string * a, std::string * b);\n"
|
||||
"};\n"
|
||||
"void Fred::foo(std::string * a, std::string * b) { *a = s; *b = s; }");
|
||||
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) The function 'Fred::foo' can be const\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:5]: (style) The function 'Fred::foo' can be const\n", errout.str());
|
||||
|
||||
// assignment to variable, can't be const
|
||||
checkConst("class Fred {\n"
|
||||
|
@ -1943,8 +1943,8 @@ private:
|
|||
"void Fred::foo() { }"
|
||||
"void Fred::foo(std::string & a) { a = s; }"
|
||||
"void Fred::foo(const std::string & a) { s = a; }");
|
||||
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:3]: (style) The function 'Fred::foo' can be const\n"
|
||||
"[test.cpp:7] -> [test.cpp:4]: (style) The function 'Fred::foo' can be const\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:7]: (style) The function 'Fred::foo' can be const\n"
|
||||
"[test.cpp:7]: (style) The function 'Fred::foo' can be const\n", errout.str());
|
||||
|
||||
// check functions with different or missing paramater names
|
||||
checkConst("class Fred {\n"
|
||||
|
@ -1960,11 +1960,11 @@ private:
|
|||
"void Fred::foo3(int a, int b) { }\n"
|
||||
"void Fred::foo4(int a, int b) { }\n"
|
||||
"void Fred::foo5(int, int) { }");
|
||||
ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:3]: (style) The function 'Fred::foo1' can be const\n"
|
||||
"[test.cpp:10] -> [test.cpp:4]: (style) The function 'Fred::foo2' can be const\n"
|
||||
"[test.cpp:11] -> [test.cpp:5]: (style) The function 'Fred::foo3' can be const\n"
|
||||
"[test.cpp:12] -> [test.cpp:6]: (style) The function 'Fred::foo4' can be const\n"
|
||||
"[test.cpp:13] -> [test.cpp:7]: (style) The function 'Fred::foo5' can be const\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:9]: (style) The function 'Fred::foo1' can be const\n"
|
||||
"[test.cpp:10]: (style) The function 'Fred::foo2' can be const\n"
|
||||
"[test.cpp:11]: (style) The function 'Fred::foo3' can be const\n"
|
||||
"[test.cpp:12]: (style) The function 'Fred::foo4' can be const\n"
|
||||
"[test.cpp:13]: (style) The function 'Fred::foo5' can be const\n", errout.str());
|
||||
|
||||
// check nested classes
|
||||
checkConst("class Fred {\n"
|
||||
|
@ -1982,7 +1982,7 @@ private:
|
|||
" };\n"
|
||||
" int A::getA() { return a; }\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:4]: (style) The function 'Fred::A::getA' can be const\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:6]: (style) The function 'Fred::A::getA' can be const\n", errout.str());
|
||||
|
||||
checkConst("class Fred {\n"
|
||||
" class A {\n"
|
||||
|
@ -1991,7 +1991,7 @@ private:
|
|||
" };\n"
|
||||
"};\n"
|
||||
"int Fred::A::getA() { return a; }");
|
||||
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:4]: (style) The function 'Fred::A::getA' can be const\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:7]: (style) The function 'Fred::A::getA' can be const\n", errout.str());
|
||||
|
||||
// check deeply nested classes
|
||||
checkConst("class Fred {\n"
|
||||
|
@ -2019,8 +2019,8 @@ private:
|
|||
" };\n"
|
||||
" int B::getB() { return b; }\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:4]: (style) The function 'Fred::B::getB' can be const\n"
|
||||
"[test.cpp:9] -> [test.cpp:7]: (style) The function 'Fred::B::A::getA' can be const\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:11]: (style) The function 'Fred::B::getB' can be const\n"
|
||||
"[test.cpp:9]: (style) The function 'Fred::B::A::getA' can be const\n", errout.str());
|
||||
|
||||
checkConst("class Fred {\n"
|
||||
" class B {\n"
|
||||
|
@ -2034,8 +2034,8 @@ private:
|
|||
"};\n"
|
||||
"int Fred::B::A::getA() { return a; }\n"
|
||||
"int Fred::B::getB() { return b; }\n");
|
||||
ASSERT_EQUALS("[test.cpp:12] -> [test.cpp:4]: (style) The function 'Fred::B::getB' can be const\n"
|
||||
"[test.cpp:11] -> [test.cpp:7]: (style) The function 'Fred::B::A::getA' can be const\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:12]: (style) The function 'Fred::B::getB' can be const\n"
|
||||
"[test.cpp:11]: (style) The function 'Fred::B::A::getA' can be const\n", errout.str());
|
||||
}
|
||||
|
||||
// operator< can often be const
|
||||
|
|
|
@ -94,8 +94,10 @@ static void getCppFiles(std::vector<std::string> &files, const std::string &path
|
|||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const bool release(argc >= 2 && std::string(argv[1]) == "--release");
|
||||
|
||||
// Get files..
|
||||
std::vector<std::string> libfiles;
|
||||
getCppFiles(libfiles, "lib/");
|
||||
|
@ -138,8 +140,10 @@ int main()
|
|||
|
||||
std::ofstream fout("Makefile");
|
||||
|
||||
// more warnings.. -Wfloat-equal -Wcast-qual -Wsign-conversion -Wlogical-op
|
||||
fout << "CXXFLAGS=-Wall -Wextra -pedantic -g\n";
|
||||
// Makefile settings..
|
||||
// TODO: add more compiler warnings. For example -Wsign-conversion
|
||||
fout << "CXXFLAGS=-Wall -Wextra -pedantic -Wfloat-equal -Wcast-qual -Wlogical-op ";
|
||||
fout << (release ? "-O2 -DNDEBUG" : "-g -D_GLIBCXX_DEBUG") << "\n";
|
||||
fout << "CXX=g++\n";
|
||||
fout << "BIN=${DESTDIR}/usr/bin\n\n";
|
||||
fout << "# For 'make man': sudo apt-get install xsltproc docbook-xsl docbook-xml\n";
|
||||
|
|
Loading…
Reference in New Issue