From b944168bdc3e413b0482a5444b8bd645e4dad012 Mon Sep 17 00:00:00 2001 From: Raphael Geissert Date: Sun, 30 Jan 2011 12:47:17 -0600 Subject: [PATCH 01/14] Check for cpp conditionals where a define is already guaranteed --- lib/preprocessor.cpp | 15 ++++++ test/testpreprocessor.cpp | 109 +++++++++++++++++++++++++++++++++++++- 2 files changed, 122 insertions(+), 2 deletions(-) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index ddf0b6128..6a29c9e13 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -888,6 +888,21 @@ std::list Preprocessor::getcfgs(const std::string &filedata, const def += ";"; def += *it; } + else + { + std::ostringstream lineStream; + lineStream << __LINE__; + + ErrorLogger::ErrorMessage errmsg; + ErrorLogger::ErrorMessage::FileLocation loc; + loc.setfile(filename); + loc.line = linenr; + errmsg._callStack.push_back(loc); + errmsg._severity = Severity::fromString("error"); + errmsg.setmsg(*it+" is already guaranteed to be defined"); + errmsg._id = "preprocessor" + lineStream.str(); + _errorLogger->reportErr(errmsg); + } } if (from_negation) { diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 0cd5fb4ab..76823ad26 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -429,13 +429,118 @@ private: preprocessor.preprocess(istr, actual, "file.c"); // Make sure an error message is written.. - TODO_ASSERT_EQUALS("[test.cpp:3]: this preprocessor condition is always true", - "", errout.str()); + ASSERT_EQUALS("[file.c:3]: (error) ABC is already guaranteed to be defined\n", + errout.str()); // Compare results.. ASSERT_EQUALS("\n\n\n\n\n\n", actual[""]); ASSERT_EQUALS("\nA\n\nB\n\n\n", actual["ABC"]); ASSERT_EQUALS(2, static_cast(actual.size())); + + test7a(); + test7b(); + test7c(); + test7d(); + } + + void test7a() + { + const char filedata[] = "#ifndef ABC\n" + "A\n" + "#ifndef ABC\n" + "B\n" + "#endif\n" + "#endif\n"; + + // Preprocess => actual result.. + std::istringstream istr(filedata); + std::map actual; + Settings settings; + Preprocessor preprocessor(&settings, this); + errout.str(""); + preprocessor.preprocess(istr, actual, "file.c"); + + // Make sure an error message is written.. + TODO_ASSERT_EQUALS("[file.c:3]: (error) ABC is already guaranteed NOT to be defined\n", + "", errout.str()); + + // Compare results.. + ASSERT_EQUALS(2, static_cast(actual.size())); + } + + void test7b() + { + const char filedata[] = "#ifndef ABC\n" + "A\n" + "#ifdef ABC\n" + "B\n" + "#endif\n" + "#endif\n"; + + // Preprocess => actual result.. + std::istringstream istr(filedata); + std::map actual; + Settings settings; + Preprocessor preprocessor(&settings, this); + errout.str(""); + preprocessor.preprocess(istr, actual, "file.c"); + + // Make sure an error message is written.. + TODO_ASSERT_EQUALS("[file.c:3]: (error) ABC is already guaranteed NOT to be defined\n", + "", errout.str()); + + // Compare results.. + ASSERT_EQUALS(2, static_cast(actual.size())); + } + + void test7c() + { + const char filedata[] = "#ifdef ABC\n" + "A\n" + "#ifndef ABC\n" + "B\n" + "#endif\n" + "#endif\n"; + + // Preprocess => actual result.. + std::istringstream istr(filedata); + std::map actual; + Settings settings; + Preprocessor preprocessor(&settings, this); + errout.str(""); + preprocessor.preprocess(istr, actual, "file.c"); + + // Make sure an error message is written.. + ASSERT_EQUALS("[file.c:3]: (error) ABC is already guaranteed to be defined\n", + errout.str()); + + // Compare results.. + ASSERT_EQUALS(2, static_cast(actual.size())); + } + + void test7d() + { + const char filedata[] = "#if defined(ABC)\n" + "A\n" + "#if defined(ABC)\n" + "B\n" + "#endif\n" + "#endif\n"; + + // Preprocess => actual result.. + std::istringstream istr(filedata); + std::map actual; + Settings settings; + Preprocessor preprocessor(&settings, this); + errout.str(""); + preprocessor.preprocess(istr, actual, "file.c"); + + // Make sure an error message is written.. + ASSERT_EQUALS("[file.c:3]: (error) ABC is already guaranteed to be defined\n", + errout.str()); + + // Compare results.. + ASSERT_EQUALS(2, static_cast(actual.size())); } From 66253af1e5ffe8e2d1613eea30623896364c8568 Mon Sep 17 00:00:00 2001 From: Raphael Geissert Date: Sun, 30 Jan 2011 17:33:44 -0600 Subject: [PATCH 02/14] Handle "#endif !defined" conditionals --- lib/preprocessor.cpp | 32 ++++++++++++++++++++++++++++++-- test/testpreprocessor.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 6a29c9e13..3e5ca8726 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -714,13 +714,14 @@ void Preprocessor::preprocess(std::istream &srcCodeStream, std::string &processe std::string Preprocessor::getdef(std::string line, bool def) { // If def is true, the line must start with "#ifdef" - if (def && line.find("#ifdef ") != 0 && line.find("#if ") != 0 && line.find("#elif ") != 0 && line.find("#if defined ") != 0) + if (def && line.find("#ifdef ") != 0 && line.find("#if ") != 0 + && (line.find("#elif ") != 0 || line.find("#elif !") == 0)) { return ""; } // If def is false, the line must start with "#ifndef" - if (!def && line.find("#ifndef ") != 0) + if (!def && line.find("#ifndef ") != 0 && line.find("#elif !") != 0) { return ""; } @@ -728,6 +729,17 @@ std::string Preprocessor::getdef(std::string line, bool def) // Remove the "#ifdef" or "#ifndef" if (line.find("#if defined ") == 0) line.erase(0, 11); + else if (line.find("#elif !defined(") == 0) + { + std::string::size_type pos = 0; + + line.erase(0, 15); + pos = line.find(")"); + // if pos == ::npos then another part of the code will complain + // about the mismatch + if (pos != std::string::npos) + line.erase(pos, 1); + } else line.erase(0, line.find(" ")); @@ -1360,6 +1372,22 @@ std::string Preprocessor::getcode(const std::string &filedata, std::string cfg, } } + else if (line.find("#elif !") == 0) + { + if (matched_ifdef.back()) + { + matching_ifdef.back() = false; + } + else + { + if (!match_cfg_def(cfgmap, ndef)) + { + matching_ifdef.back() = true; + matched_ifdef.back() = true; + } + } + } + else if (line.find("#elif ") == 0) { if (matched_ifdef.back()) diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 76823ad26..80d32aacc 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -911,6 +911,7 @@ private: if_cond2b(); if_cond2c(); if_cond2d(); + if_cond2e(); } void if_cond2b() @@ -998,6 +999,31 @@ private: ASSERT_EQUALS("\n!a\n\nb\n\n\n\n\n\n\n\n\n\n\n\n", actual["B"]); } + void if_cond2e() + { + const char filedata[] = "#if !defined(A)\n" + "!a\n" + "#elif !defined(B)\n" + "!b\n" + "#endif\n"; + + // Preprocess => actual result.. + errout.str(""); + std::istringstream istr(filedata); + std::map actual; + Settings settings; + settings.debug = settings.debugwarnings = true; + Preprocessor preprocessor(&settings, this); + preprocessor.preprocess(istr, actual, "file.c"); + + // Compare results.. + ASSERT_EQUALS(3, static_cast(actual.size())); + ASSERT_EQUALS("\n!a\n\n\n\n", actual[""]); + ASSERT_EQUALS("\n\n\n!b\n\n", actual["A"]); + TODO_ASSERT_EQUALS("\n\n\n\n\n", "", actual["A;B"]); + ASSERT_EQUALS("", errout.str()); + } + void if_cond3() { const char filedata[] = "#ifdef A\n" From b4a249f26ee39afcc70c6555b599b0561898f56d Mon Sep 17 00:00:00 2001 From: Raphael Geissert Date: Sun, 30 Jan 2011 18:40:59 -0600 Subject: [PATCH 03/14] Reduce std::string::find() abuse --- lib/preprocessor.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 3e5ca8726..dcb292d9f 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -714,22 +714,22 @@ void Preprocessor::preprocess(std::istream &srcCodeStream, std::string &processe std::string Preprocessor::getdef(std::string line, bool def) { // If def is true, the line must start with "#ifdef" - if (def && line.find("#ifdef ") != 0 && line.find("#if ") != 0 - && (line.find("#elif ") != 0 || line.find("#elif !") == 0)) + if (def && line.compare(0, 7, "#ifdef ") != 0 && line.compare(0, 4, "#if ") != 0 + && (line.compare(0, 6, "#elif ") != 0 || line.compare(0, 7, "#elif !") == 0)) { return ""; } // If def is false, the line must start with "#ifndef" - if (!def && line.find("#ifndef ") != 0 && line.find("#elif !") != 0) + if (!def && line.compare(0, 8, "#ifndef ") != 0 && line.compare(0, 7, "#elif !") != 0) { return ""; } // Remove the "#ifdef" or "#ifndef" - if (line.find("#if defined ") == 0) + if (line.compare(0, 12, "#if defined ") == 0) line.erase(0, 11); - else if (line.find("#elif !defined(") == 0) + else if (line.compare(0, 15, "#elif !defined(") == 0) { std::string::size_type pos = 0; @@ -880,7 +880,7 @@ std::list Preprocessor::getcfgs(const std::string &filedata, const simplifyCondition(varmap, def, false); } - if (! deflist.empty() && line.find("#elif ") == 0) + if (! deflist.empty() && line.compare(0, 6, "#elif ") == 0) deflist.pop_back(); deflist.push_back(def); def = ""; @@ -930,7 +930,7 @@ std::list Preprocessor::getcfgs(const std::string &filedata, const } } - else if (line.find("#else") == 0 && ! deflist.empty()) + else if (line.compare(0, 5, "#else") == 0 && ! deflist.empty()) { if (deflist.back() == "!") { @@ -946,7 +946,7 @@ std::list Preprocessor::getcfgs(const std::string &filedata, const } } - else if (line.find("#endif") == 0 && ! deflist.empty()) + else if (line.compare(0, 6, "#endif") == 0 && ! deflist.empty()) { if (deflist.back() == "!") ndeflist.pop_back(); @@ -1372,7 +1372,7 @@ std::string Preprocessor::getcode(const std::string &filedata, std::string cfg, } } - else if (line.find("#elif !") == 0) + else if (line.compare(0, 7, "#elif !") == 0) { if (matched_ifdef.back()) { @@ -1388,7 +1388,7 @@ std::string Preprocessor::getcode(const std::string &filedata, std::string cfg, } } - else if (line.find("#elif ") == 0) + else if (line.compare(0, 6, "#elif ") == 0) { if (matched_ifdef.back()) { From 29ca5fbe1e74c58eea345a74dee2018ef23c5631 Mon Sep 17 00:00:00 2001 From: Raphael Geissert Date: Sun, 30 Jan 2011 18:47:49 -0600 Subject: [PATCH 04/14] Minor optimisations to the preprocessor --- lib/preprocessor.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index dcb292d9f..e76c2b43c 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -713,6 +713,9 @@ void Preprocessor::preprocess(std::istream &srcCodeStream, std::string &processe // Get the DEF in this line: "#ifdef DEF" std::string Preprocessor::getdef(std::string line, bool def) { + if (line.empty() || line[0] != '#') + return ""; + // If def is true, the line must start with "#ifdef" if (def && line.compare(0, 7, "#ifdef ") != 0 && line.compare(0, 4, "#if ") != 0 && (line.compare(0, 6, "#elif ") != 0 || line.compare(0, 7, "#elif !") == 0)) @@ -787,6 +790,8 @@ std::list Preprocessor::getcfgs(const std::string &filedata, const if (_errorLogger) _errorLogger->reportProgress(filename, "Preprocessing (get configurations 1)", 0); + if (line.empty()) + continue; if (line.compare(0, 6, "#file ") == 0) { @@ -818,6 +823,9 @@ std::list Preprocessor::getcfgs(const std::string &filedata, const if (!line.empty() && line.compare(0, 3, "#if") != 0) includeguard = false; + if (line[0] != '#') + continue; + if (includeguard) continue; From 386de53ff730bc6d688955bf1eff9436aa33ba10 Mon Sep 17 00:00:00 2001 From: Raphael Geissert Date: Sun, 30 Jan 2011 20:37:37 -0600 Subject: [PATCH 05/14] Formatting, sorry --- lib/preprocessor.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index e76c2b43c..4cdd5f729 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -714,7 +714,7 @@ void Preprocessor::preprocess(std::istream &srcCodeStream, std::string &processe std::string Preprocessor::getdef(std::string line, bool def) { if (line.empty() || line[0] != '#') - return ""; + return ""; // If def is true, the line must start with "#ifdef" if (def && line.compare(0, 7, "#ifdef ") != 0 && line.compare(0, 4, "#if ") != 0 @@ -791,7 +791,7 @@ std::list Preprocessor::getcfgs(const std::string &filedata, const _errorLogger->reportProgress(filename, "Preprocessing (get configurations 1)", 0); if (line.empty()) - continue; + continue; if (line.compare(0, 6, "#file ") == 0) { @@ -823,8 +823,8 @@ std::list Preprocessor::getcfgs(const std::string &filedata, const if (!line.empty() && line.compare(0, 3, "#if") != 0) includeguard = false; - if (line[0] != '#') - continue; + if (line[0] != '#') + continue; if (includeguard) continue; From 800d8d1e056ddba9318fc2a8be85572587d2928c Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Mon, 31 Jan 2011 09:18:35 +0200 Subject: [PATCH 06/14] Cleanup makefile a bit. Align object file lists first line. Remove excessive use of tabs. --- Makefile | 16 ++++++++-------- tools/dmake.cpp | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index de50b8d09..09aadde1c 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ MAN_SOURCE=man/cppcheck.1.xml ###### Object Files -LIBOBJ = lib/checkautovariables.o \ +LIBOBJ = lib/checkautovariables.o \ lib/checkbufferoverrun.o \ lib/checkclass.o \ lib/checkexceptionsafety.o \ @@ -46,7 +46,7 @@ LIBOBJ = lib/checkautovariables.o \ lib/token.o \ lib/tokenize.o -CLIOBJ = cli/cmdlineparser.o \ +CLIOBJ = cli/cmdlineparser.o \ cli/cppcheckexecutor.o \ cli/filelister.o \ cli/filelister_unix.o \ @@ -90,7 +90,7 @@ TESTOBJ = test/options.o \ test/testunusedprivfunc.o \ test/testunusedvar.o -EXTOBJ = externals/tinyxml/tinystr.o \ +EXTOBJ = externals/tinyxml/tinystr.o \ externals/tinyxml/tinyxml.o \ externals/tinyxml/tinyxmlerror.o \ externals/tinyxml/tinyxmlparser.o @@ -98,13 +98,13 @@ EXTOBJ = externals/tinyxml/tinystr.o \ ###### Targets -cppcheck: $(LIBOBJ) $(CLIOBJ) $(EXTOBJ) +cppcheck: $(LIBOBJ) $(CLIOBJ) $(EXTOBJ) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o cppcheck $(CLIOBJ) $(LIBOBJ) $(EXTOBJ) -lpcre $(LDFLAGS) -all: cppcheck testrunner +all: cppcheck testrunner -testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/filelister.o cli/filelister_unix.o - $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o testrunner $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) -lpcre cli/threadexecutor.o cli/cmdlineparser.o cli/filelister.o cli/filelister_unix.o $(LDFLAGS) +testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/filelister.o cli/filelister_unix.o + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o testrunner $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) -lpcre cli/threadexecutor.o cli/cmdlineparser.o cli/filelister.o cli/filelister_unix.o $(LDFLAGS) test: all ./testrunner @@ -127,7 +127,7 @@ man/cppcheck.1: $(MAN_SOURCE) tags: ctags -R --exclude=doxyoutput . -install: cppcheck +install: cppcheck install -d ${BIN} install cppcheck ${BIN} diff --git a/tools/dmake.cpp b/tools/dmake.cpp index 0ff33c099..434a4128c 100644 --- a/tools/dmake.cpp +++ b/tools/dmake.cpp @@ -208,11 +208,11 @@ int main(int argc, char **argv) fout << "MAN_SOURCE=man/cppcheck.1.xml\n\n"; fout << "\n###### Object Files\n\n"; - fout << "LIBOBJ = " << objfile(libfiles[0]); + fout << "LIBOBJ = " << objfile(libfiles[0]); for (unsigned int i = 1; i < libfiles.size(); ++i) fout << " \\" << std::endl << std::string(14, ' ') << objfile(libfiles[i]); fout << "\n\n"; - fout << "CLIOBJ = " << objfile(clifiles[0]); + fout << "CLIOBJ = " << objfile(clifiles[0]); for (unsigned int i = 1; i < clifiles.size(); ++i) fout << " \\" << std::endl << std::string(14, ' ') << objfile(clifiles[i]); fout << "\n\n"; @@ -220,18 +220,18 @@ int main(int argc, char **argv) for (unsigned int i = 1; i < testfiles.size(); ++i) fout << " \\" << std::endl << std::string(14, ' ') << objfile(testfiles[i]); fout << "\n\n"; - fout << "EXTOBJ = " << objfile(externalfiles[0]); + fout << "EXTOBJ = " << objfile(externalfiles[0]); for (unsigned int i = 1; i < externalfiles.size(); ++i) fout << " \\" << std::endl << std::string(14, ' ') << objfile(externalfiles[i]); fout << "\n\n"; fout << "\n###### Targets\n\n"; - fout << "cppcheck:\t$(LIBOBJ)\t$(CLIOBJ)\t$(EXTOBJ)\n"; + fout << "cppcheck: $(LIBOBJ) $(CLIOBJ) $(EXTOBJ)\n"; fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o cppcheck $(CLIOBJ) $(LIBOBJ) $(EXTOBJ) -lpcre $(LDFLAGS)\n\n"; - fout << "all:\tcppcheck\ttestrunner\n\n"; - fout << "testrunner:\t$(TESTOBJ)\t$(LIBOBJ)\t$(EXTOBJ)\tcli/threadexecutor.o\tcli/cmdlineparser.o\tcli/cppcheckexecutor.o\tcli/filelister.o\tcli/filelister_unix.o\n"; - fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o testrunner $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) -lpcre cli/threadexecutor.o cli/cmdlineparser.o\tcli/filelister.o\tcli/filelister_unix.o $(LDFLAGS)\n\n"; + fout << "all:\tcppcheck testrunner\n\n"; + fout << "testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/filelister.o cli/filelister_unix.o\n"; + fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o testrunner $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) -lpcre cli/threadexecutor.o cli/cmdlineparser.o cli/filelister.o cli/filelister_unix.o $(LDFLAGS)\n\n"; fout << "test:\tall\n"; fout << "\t./testrunner\n\n"; fout << "check:\tall\n"; @@ -248,7 +248,7 @@ int main(int argc, char **argv) fout << "\t$(XP) $(DB2MAN) $(MAN_SOURCE)\n\n"; fout << "tags:\n"; fout << "\tctags -R --exclude=doxyoutput .\n\n"; - fout << "install:\tcppcheck\n"; + fout << "install: cppcheck\n"; fout << "\tinstall -d ${BIN}\n"; fout << "\tinstall cppcheck ${BIN}\n\n"; #endif From 43b0e2a74c12df59afa23758154ce416957bbb31 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Mon, 31 Jan 2011 10:25:14 +0200 Subject: [PATCH 07/14] GUI: Fill summary data when reading XML file. When reading XML file there is no summary data stored so we must dublicate the message data to summary. Since message can be long try to find full stop from the message and cut summary to it. Ticket: #2402 ([GUI] Summary is not shown for loaded .xml file) --- gui/xmlreport.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gui/xmlreport.cpp b/gui/xmlreport.cpp index c82478055..f481f3615 100644 --- a/gui/xmlreport.cpp +++ b/gui/xmlreport.cpp @@ -159,6 +159,16 @@ ErrorLine XmlReport::ReadError(QXmlStreamReader *reader) line.line = attribs.value("", LineAttribute).toString().toUInt(); line.id = attribs.value("", IdAttribute).toString(); line.severity = attribs.value("", SeverityAttribute).toString(); + + // NOTE: This dublicates the message to Summary-field. But since + // old XML format doesn't have separate summary and verbose messages + // we must add same message to both data so it shows up in GUI. + // Check if there is full stop and cut the summary to it. + QString summary = attribs.value("", MsgAttribute).toString(); + const int ind = summary.indexOf('.'); + if (ind != -1) + summary = summary.left(ind + 1); + line.summary = summary; line.message = attribs.value("", MsgAttribute).toString(); } return line; From b7cb684b1b842862da65ffb9e9ca1839c3532a3c Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Mon, 31 Jan 2011 10:32:23 +0200 Subject: [PATCH 08/14] GUI: Write error summary to CSV and TXT reports. It makes more sense to write the one-line summary to TXT and especially to CSV reports. Long multi-line verbose messages ruin the layout these files. --- gui/csvreport.cpp | 2 +- gui/txtreport.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gui/csvreport.cpp b/gui/csvreport.cpp index a9016e42e..0080f1434 100644 --- a/gui/csvreport.cpp +++ b/gui/csvreport.cpp @@ -65,7 +65,7 @@ void CsvReport::WriteError(const ErrorItem &error) QString line; const QString file = QDir::toNativeSeparators(error.files[error.files.size() - 1]); line += QString("%1,%2,").arg(file).arg(error.lines[error.lines.size() - 1]); - line += QString("%1,%2").arg(error.severity).arg(error.message); + line += QString("%1,%2").arg(error.severity).arg(error.summary); mTxtWriter << line << endl; } diff --git a/gui/txtreport.cpp b/gui/txtreport.cpp index a6f8dbe4b..20c34d7b7 100644 --- a/gui/txtreport.cpp +++ b/gui/txtreport.cpp @@ -76,7 +76,7 @@ void TxtReport::WriteError(const ErrorItem &error) } } - line += QString("(%1) %2").arg(error.severity).arg(error.message); + line += QString("(%1) %2").arg(error.severity).arg(error.summary); mTxtWriter << line << endl; } From f70aaac5cde249e5ebdf657c2fd0976e995339f6 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Mon, 31 Jan 2011 11:16:32 +0200 Subject: [PATCH 09/14] GUI: Reword the option for checking all #ifdefs. The current wording was confusing (espcially related to CLI) since it said the option will make Cppcheck to check all #ifdef configs. But this really is case only when there is excessive amount of those configs and without the option some would be ignored. So format the option text in line of CLI switch and say it is forcing not enabling checking of all configurations. --- gui/settings.ui | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gui/settings.ui b/gui/settings.ui index ac5f19f33..8d6fc2e3d 100644 --- a/gui/settings.ui +++ b/gui/settings.ui @@ -7,7 +7,7 @@ 0 0 589 - 281 + 313 @@ -135,7 +135,7 @@ - Check all #ifdef configurations + Force checking all #ifdef configurations From 0112cd505d089695dc3adb485536cea12042747f Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Mon, 31 Jan 2011 11:20:03 +0200 Subject: [PATCH 10/14] GUI: Update translation files. --- gui/cppcheck_de.ts | 59 +++++++++++++++++++++++----------------------- gui/cppcheck_en.ts | 59 +++++++++++++++++++++++----------------------- gui/cppcheck_fi.ts | 59 +++++++++++++++++++++++----------------------- gui/cppcheck_ja.ts | 59 +++++++++++++++++++++++----------------------- gui/cppcheck_nl.ts | 59 +++++++++++++++++++++++----------------------- gui/cppcheck_pl.ts | 57 ++++++++++++++++++++++---------------------- gui/cppcheck_ru.ts | 59 +++++++++++++++++++++++----------------------- gui/cppcheck_se.ts | 59 +++++++++++++++++++++++----------------------- gui/cppcheck_sr.ts | 59 +++++++++++++++++++++++----------------------- 9 files changed, 269 insertions(+), 260 deletions(-) diff --git a/gui/cppcheck_de.ts b/gui/cppcheck_de.ts index 9b3ff31ea..3c7b047a7 100644 --- a/gui/cppcheck_de.ts +++ b/gui/cppcheck_de.ts @@ -222,10 +222,10 @@ kate -l(line) (file) - - - - + + + + Cppcheck Cppcheck @@ -552,28 +552,28 @@ kate -l(line) (file) Kein passenden Dateien zum Überprüfen gefunden! - + License Lizenz - + Authors Autoren - + XML files (*.xml);;Text files (*.txt);;CSV files (*.csv) XML-Dateien (*.xml);;Textdateien (*.txt);;CSV-Dateien (*.csv) - + Save the report file Speichert die Berichtdatei - - + + XML files (*.xml) XML-Dateien (*.xml) @@ -584,40 +584,40 @@ kate -l(line) (file) - - + + Project: - + Open the report file - + Checking is running. Do you want to stop the checking and exit Cppcheck?. - + Text files (*.txt) Textdateien (*.txt) - + CSV files (*.csv) CSV-Dateien (*.csv) - + Cppcheck - %1 Cppcheck - %1 - + Failed to change the language: %1 @@ -633,39 +633,39 @@ Do you want to stop the checking and exit Cppcheck?. - - + + Cppcheck Help - + Failed to load help file (not found) - + Failed to load help file - - + + Project files (*.cppcheck);;All files(*.*) - + Select Project File - + Select Project Filename - + No project file loaded @@ -1018,8 +1018,9 @@ Legen Sie unter dem Menü Ansicht fest, welche Art von Fehlern angezeigt werden - Check all #ifdef configurations - Alle #ifdef-Konfigurationen überprüfen + Force checking all #ifdef configurations + Check all #ifdef configurations + Alle #ifdef-Konfigurationen überprüfen diff --git a/gui/cppcheck_en.ts b/gui/cppcheck_en.ts index 3a96b3c94..9ee278852 100644 --- a/gui/cppcheck_en.ts +++ b/gui/cppcheck_en.ts @@ -224,10 +224,10 @@ kate -l(line) (file) - - - - + + + + Cppcheck Cppcheck @@ -554,28 +554,28 @@ kate -l(line) (file) No suitable files found to check! - + License License - + Authors Authors - + XML files (*.xml);;Text files (*.txt);;CSV files (*.csv) XML files (*.xml);;Text files (*.txt);;CSV files (*.csv) - + Save the report file Save the report file - - + + XML files (*.xml) XML files (*.xml) @@ -586,40 +586,40 @@ kate -l(line) (file) - - + + Project: - + Open the report file - + Checking is running. Do you want to stop the checking and exit Cppcheck?. - + Text files (*.txt) Text files (*.txt) - + CSV files (*.csv) - + Cppcheck - %1 Cppcheck - %1 - + Failed to change the language: %1 @@ -633,39 +633,39 @@ Do you want to stop the checking and exit Cppcheck?. %1 - - + + Cppcheck Help - + Failed to load help file (not found) - + Failed to load help file - - + + Project files (*.cppcheck);;All files(*.*) - + Select Project File - + Select Project Filename - + No project file loaded @@ -1018,8 +1018,9 @@ To toggle what kind of errors are shown, open view menu. - Check all #ifdef configurations - Check all #ifdef configurations + Force checking all #ifdef configurations + Check all #ifdef configurations + Check all #ifdef configurations diff --git a/gui/cppcheck_fi.ts b/gui/cppcheck_fi.ts index 57924099c..303d349e6 100644 --- a/gui/cppcheck_fi.ts +++ b/gui/cppcheck_fi.ts @@ -226,10 +226,10 @@ kate -l(line) (file) - - - - + + + + Cppcheck Cppcheck @@ -556,28 +556,28 @@ kate -l(line) (file) Tarkistettavaksi sopivia tiedostoja ei löytynyt! - + License Lisenssi - + Authors Tekijät - + XML files (*.xml);;Text files (*.txt);;CSV files (*.csv) XML-tiedostot (*.xml);;Tekstitiedostot (*.txt);;CSV-tiedostot (*.csv) - + Save the report file Tallenna raportti - - + + XML files (*.xml) XML-tiedostot (*xml) @@ -588,40 +588,40 @@ kate -l(line) (file) - - + + Project: - + Open the report file - + Checking is running. Do you want to stop the checking and exit Cppcheck?. - + Text files (*.txt) Tekstitiedostot (*.txt) - + CSV files (*.csv) - + Cppcheck - %1 Cppcheck - %1 - + Failed to change the language: %1 @@ -637,39 +637,39 @@ Do you want to stop the checking and exit Cppcheck?. - - + + Cppcheck Help - + Failed to load help file (not found) - + Failed to load help file - - + + Project files (*.cppcheck);;All files(*.*) - + Select Project File - + Select Project Filename - + No project file loaded @@ -1022,8 +1022,9 @@ Määrittääksesi minkä tyyppisiä virheitä näytetään, avaa näkymä valik - Check all #ifdef configurations - Tarkista kaikki #ifdef kombinaatiot + Force checking all #ifdef configurations + Check all #ifdef configurations + Tarkista kaikki #ifdef kombinaatiot diff --git a/gui/cppcheck_ja.ts b/gui/cppcheck_ja.ts index 911b32756..222900f08 100644 --- a/gui/cppcheck_ja.ts +++ b/gui/cppcheck_ja.ts @@ -210,10 +210,10 @@ kate -l(line) (file) - - - - + + + + Cppcheck Cppcheck @@ -546,24 +546,24 @@ kate -l(line) (file) - - + + Project: プロジェクト: - - + + XML files (*.xml) XML ファイル (*.xml) - + Open the report file レポートを開く - + Checking is running. Do you want to stop the checking and exit Cppcheck?. @@ -572,42 +572,42 @@ Do you want to stop the checking and exit Cppcheck?. 解析を停止してCppcheckを終了しますか?. - + License ライセンス - + Authors 作者 - + XML files (*.xml);;Text files (*.txt);;CSV files (*.csv) XML ファイル (*.xml);;テキストファイル (*.txt);;CSV形式ファイル (*.csv) - + Save the report file レポートを保存 - + Text files (*.txt) テキストファイル (*.txt) - + CSV files (*.csv) CSV形式ファイル (*.csv) - + Cppcheck - %1 Cppcheck - %1 - + Failed to change the language: %1 @@ -620,39 +620,39 @@ Do you want to stop the checking and exit Cppcheck?. - - + + Cppcheck Help Cppcheck ヘルプ - + Failed to load help file (not found) ヘルプファイルが見つかりませんでした - + Failed to load help file ヘルプファイルの読み込みに失敗しました - - + + Project files (*.cppcheck);;All files(*.*) プロジェクトファイル (*.cppcheck);;All files(*.*) - + Select Project File プロジェクトファイルを選択 - + Select Project Filename プロジェクトファイル名を選択 - + No project file loaded プロジェクトファイルが読み込まれていません @@ -1003,8 +1003,9 @@ To toggle what kind of errors are shown, open view menu. - Check all #ifdef configurations - すべての #ifdef をチェックする + Force checking all #ifdef configurations + Check all #ifdef configurations + すべての #ifdef をチェックする diff --git a/gui/cppcheck_nl.ts b/gui/cppcheck_nl.ts index c5e5e6747..a5ac7b33f 100644 --- a/gui/cppcheck_nl.ts +++ b/gui/cppcheck_nl.ts @@ -224,10 +224,10 @@ kate -l(line) (file) - - - - + + + + Cppcheck Cppcheck @@ -554,28 +554,28 @@ kate -l(line) (file) Geen geschikte bestanden gevonden om te controleren! - + License Licentie - + Authors Auteurs - + XML files (*.xml);;Text files (*.txt);;CSV files (*.csv) XML bestanden (*.xml);;Tekst bestanden (*.txt);;CSV bestanden (*.csv) - + Save the report file Rapport opslaan - - + + XML files (*.xml) XML bestanden (*.xml) @@ -586,40 +586,40 @@ kate -l(line) (file) - - + + Project: - + Open the report file - + Checking is running. Do you want to stop the checking and exit Cppcheck?. - + Text files (*.txt) Tekst bestanden (*.txt) - + CSV files (*.csv) - + Cppcheck - %1 Cppcheck - %1 - + Failed to change the language: %1 @@ -633,39 +633,39 @@ Do you want to stop the checking and exit Cppcheck?. %1 - - + + Cppcheck Help - + Failed to load help file (not found) - + Failed to load help file - - + + Project files (*.cppcheck);;All files(*.*) - + Select Project File - + Select Project Filename - + No project file loaded @@ -1018,8 +1018,9 @@ Gebruik het uitzicht menu om te selecteren welke fouten getoond worden. - Check all #ifdef configurations - Controleer alle #ifdef combinaties + Force checking all #ifdef configurations + Check all #ifdef configurations + Controleer alle #ifdef combinaties diff --git a/gui/cppcheck_pl.ts b/gui/cppcheck_pl.ts index c35ddefb1..79013cad9 100644 --- a/gui/cppcheck_pl.ts +++ b/gui/cppcheck_pl.ts @@ -211,10 +211,10 @@ kate -l(line) (file) - - - - + + + + Cppcheck @@ -547,92 +547,92 @@ kate -l(line) (file) - - + + Project: - + Open the report file - + License - + Authors - + XML files (*.xml);;Text files (*.txt);;CSV files (*.csv) - + Save the report file - - + + Cppcheck Help - + Failed to load help file (not found) - + Failed to load help file - + Select Project Filename - + No project file loaded - - + + XML files (*.xml) - + Checking is running. Do you want to stop the checking and exit Cppcheck?. - + Text files (*.txt) - + CSV files (*.csv) - + Cppcheck - %1 - + Failed to change the language: %1 @@ -641,13 +641,13 @@ Do you want to stop the checking and exit Cppcheck?. - - + + Project files (*.cppcheck);;All files(*.*) - + Select Project File @@ -994,7 +994,8 @@ To toggle what kind of errors are shown, open view menu. - Check all #ifdef configurations + Force checking all #ifdef configurations + Check all #ifdef configurations diff --git a/gui/cppcheck_ru.ts b/gui/cppcheck_ru.ts index 6c3d6d407..56e10c928 100644 --- a/gui/cppcheck_ru.ts +++ b/gui/cppcheck_ru.ts @@ -214,10 +214,10 @@ kate -l(line) (file) - - - - + + + + Cppcheck Cppcheck @@ -544,28 +544,28 @@ kate -l(line) (file) - + License Лицензия - + Authors Авторы - + XML files (*.xml);;Text files (*.txt);;CSV files (*.csv) - + Save the report file - - + + XML files (*.xml) @@ -576,40 +576,40 @@ kate -l(line) (file) - - + + Project: - + Open the report file - + Checking is running. Do you want to stop the checking and exit Cppcheck?. - + Text files (*.txt) Текстовые файлы (*.txt) - + CSV files (*.csv) - + Cppcheck - %1 Cppcheck - %1 - + Failed to change the language: %1 @@ -625,39 +625,39 @@ Do you want to stop the checking and exit Cppcheck?. - - + + Cppcheck Help - + Failed to load help file (not found) - + Failed to load help file - - + + Project files (*.cppcheck);;All files(*.*) - + Select Project File - + Select Project Filename - + No project file loaded @@ -1007,8 +1007,9 @@ To toggle what kind of errors are shown, open view menu. - Check all #ifdef configurations - Проверять все варианты #ifdef конфигураций + Force checking all #ifdef configurations + Check all #ifdef configurations + Проверять все варианты #ifdef конфигураций diff --git a/gui/cppcheck_se.ts b/gui/cppcheck_se.ts index 278a2de3f..0fec2db9a 100644 --- a/gui/cppcheck_se.ts +++ b/gui/cppcheck_se.ts @@ -224,10 +224,10 @@ kate -l(line) (file) - - - - + + + + Cppcheck Cppcheck @@ -555,28 +555,28 @@ kate -l(line) (file) Inga lämpliga filer hittades! - + License Licens - + Authors Utvecklare - + XML files (*.xml);;Text files (*.txt);;CSV files (*.csv) XML filer (*.xml);;Text filer (*.txt);;CSV filer (*.csv) - + Save the report file Spara rapport - - + + XML files (*.xml) XML filer (*.xml) @@ -587,40 +587,40 @@ kate -l(line) (file) - - + + Project: - + Open the report file - + Checking is running. Do you want to stop the checking and exit Cppcheck?. - + Text files (*.txt) Text filer (*.txt) - + CSV files (*.csv) CSV filer (*.csv) - + Cppcheck - %1 Cppcheck - %1 - + Failed to change the language: %1 @@ -636,39 +636,39 @@ Do you want to stop the checking and exit Cppcheck?. - - + + Cppcheck Help - + Failed to load help file (not found) - + Failed to load help file - - + + Project files (*.cppcheck);;All files(*.*) - + Select Project File - + Select Project Filename - + No project file loaded @@ -1021,8 +1021,9 @@ För att ställa in vilka fel som skall visas använd visa menyn. - Check all #ifdef configurations - Kontrollera alla #ifdef konfigurationer + Force checking all #ifdef configurations + Check all #ifdef configurations + Kontrollera alla #ifdef konfigurationer diff --git a/gui/cppcheck_sr.ts b/gui/cppcheck_sr.ts index 4beb61085..8710dd855 100644 --- a/gui/cppcheck_sr.ts +++ b/gui/cppcheck_sr.ts @@ -224,10 +224,10 @@ kate -l(line) (file) - - - - + + + + Cppcheck Cppcheck @@ -554,28 +554,28 @@ kate -l(line) (file) No suitable files found to check! - + License License - + Authors Authors - + XML files (*.xml);;Text files (*.txt);;CSV files (*.csv) XML files (*.xml);;Text files (*.txt);;CSV files (*.csv) - + Save the report file Save the report file - - + + XML files (*.xml) XML files (*.xml) @@ -586,40 +586,40 @@ kate -l(line) (file) - - + + Project: - + Open the report file - + Checking is running. Do you want to stop the checking and exit Cppcheck?. - + Text files (*.txt) Text files (*.txt) - + CSV files (*.csv) - + Cppcheck - %1 Cppcheck - %1 - + Failed to change the language: %1 @@ -633,39 +633,39 @@ Do you want to stop the checking and exit Cppcheck?. %1 - - + + Cppcheck Help - + Failed to load help file (not found) - + Failed to load help file - - + + Project files (*.cppcheck);;All files(*.*) - + Select Project File - + Select Project Filename - + No project file loaded @@ -1018,8 +1018,9 @@ To toggle what kind of errors are shown, open view menu. - Check all #ifdef configurations - Check all #ifdef configurations + Force checking all #ifdef configurations + Check all #ifdef configurations + Check all #ifdef configurations From f3111b541ee117c09bafd62f8333718e5ddf5bd8 Mon Sep 17 00:00:00 2001 From: Ettl Martin Date: Mon, 31 Jan 2011 13:46:51 +0100 Subject: [PATCH 11/14] #2528 added todo-testcase --- test/testbufferoverrun.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index c63094fde..7b1f4d905 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -106,6 +106,7 @@ private: TEST_CASE(array_index_29); // ticket #1734 TEST_CASE(array_index_30); // ticket #2086 - out of bounds when type is unknown TEST_CASE(array_index_31); // ticket #2120 - out of bounds in subfunction when type is unknown + TEST_CASE(array_index_32); TEST_CASE(array_index_multidim); TEST_CASE(array_index_switch_in_for); TEST_CASE(array_index_calculation); @@ -1067,6 +1068,21 @@ private: ASSERT_EQUALS("", errout.str()); } + void array_index_32() + { + check("class X\n" + "{\n" + " public:\n" + " X()\n" + " {\n" + " m_x[0] = 0;\n" + " m_x[1] = 0;\n" + " }\n" + " int m_x[1];\n" + "};\n"); + TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Array 'm_x[1]' index 1 out of bounds\n","", errout.str()); + } + void array_index_multidim() { check("void f()\n" From 757c840633ce8dcafbdf6cfa8c1dd8730fdbf08b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 31 Jan 2011 17:26:07 +0100 Subject: [PATCH 12/14] astyle formatting --- cli/filelister_win32.cpp | 2 +- test/testbufferoverrun.cpp | 2 +- test/testpreprocessor.cpp | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cli/filelister_win32.cpp b/cli/filelister_win32.cpp index 776e0245a..041613331 100644 --- a/cli/filelister_win32.cpp +++ b/cli/filelister_win32.cpp @@ -88,7 +88,7 @@ static BOOL MyIsDirectory(std::string path) return (GetFileAttributes(path.c_str()) & FILE_ATTRIBUTE_DIRECTORY); #else // See http://msdn.microsoft.com/en-us/library/bb773621(VS.85).aspx - return PathIsDirectory(path.c_str()); +return PathIsDirectory(path.c_str()); #endif } diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 7b1f4d905..4966231ba 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -1073,7 +1073,7 @@ private: check("class X\n" "{\n" " public:\n" - " X()\n" + " X()\n" " {\n" " m_x[0] = 0;\n" " m_x[1] = 0;\n" diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 80d32aacc..2d9486d49 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -430,7 +430,7 @@ private: // Make sure an error message is written.. ASSERT_EQUALS("[file.c:3]: (error) ABC is already guaranteed to be defined\n", - errout.str()); + errout.str()); // Compare results.. ASSERT_EQUALS("\n\n\n\n\n\n", actual[""]); @@ -512,7 +512,7 @@ private: // Make sure an error message is written.. ASSERT_EQUALS("[file.c:3]: (error) ABC is already guaranteed to be defined\n", - errout.str()); + errout.str()); // Compare results.. ASSERT_EQUALS(2, static_cast(actual.size())); @@ -537,7 +537,7 @@ private: // Make sure an error message is written.. ASSERT_EQUALS("[file.c:3]: (error) ABC is already guaranteed to be defined\n", - errout.str()); + errout.str()); // Compare results.. ASSERT_EQUALS(2, static_cast(actual.size())); From 202c8eb4a0463139ad47f5bff3a0445590889526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 31 Jan 2011 17:30:27 +0100 Subject: [PATCH 13/14] Fixed #2525 (False positive 'Possible null pointer dereference') --- lib/checknullpointer.cpp | 6 ++++++ test/testnullpointer.cpp | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index e9b1467bd..bd36a4e37 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -485,6 +485,12 @@ void CheckNullPointer::nullPointerByDeRefAndChec() break; } + if (tok1->str() == ")" && Token::simpleMatch(tok1->link()->previous(), "sizeof (")) + { + tok1 = tok1->link()->previous(); + continue; + } + if (tok1->str() == "break") break; diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 53198703c..0c9e09a1f 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -437,6 +437,15 @@ private: " }\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // #2525 - sizeof + check("void f() {\n" + " int *test = NULL;\n" + " int c = sizeof(test[0]);\n" + " if (!test)\n" + " ;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void nullpointer5() From 52fea0f24521c58ddbb639e2c2642ba459bf488a Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Mon, 31 Jan 2011 22:18:16 +0200 Subject: [PATCH 14/14] Ticket #2522 (update project files to fix missing include messages) --- cppcheck.cppcheck | 4 ++++ gui/gui.cppcheck | 13 +++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/cppcheck.cppcheck b/cppcheck.cppcheck index a76e7db2a..188043b4f 100644 --- a/cppcheck.cppcheck +++ b/cppcheck.cppcheck @@ -3,10 +3,14 @@ + + + + diff --git a/gui/gui.cppcheck b/gui/gui.cppcheck index 632b61115..7c87003bd 100644 --- a/gui/gui.cppcheck +++ b/gui/gui.cppcheck @@ -1,6 +1,7 @@ - - - - - - + + + + + + +