diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index b64229edf..39c6eb916 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -648,7 +648,7 @@ void CmdLineParser::PrintHelp() " -i [dir] Give path to ignore. Give several -i parameters to ignore\n" " several paths. Give directory name or filename with path\n" " as parameter. Directory name is matched to all parts of the\n" - " path." + " path.\n" " --inline-suppr Enable inline suppressions. Use them by placing one or\n" " more comments, like: // cppcheck-suppress warningId\n" " on the lines before the warning to suppress.\n" diff --git a/gui/cppcheck_se.ts b/gui/cppcheck_se.ts index 0fec2db9a..624f1abc6 100644 --- a/gui/cppcheck_se.ts +++ b/gui/cppcheck_se.ts @@ -22,7 +22,7 @@ Copyright © 2007-2010 Daniel Marjamäki and cppcheck team. Copyright (C) 2007-2010 Daniel Marjamäki and cppcheck team. - Copyright (C) 2007-2010 Daniel Marjamäki and cppcheck team. + Copyright (C) 2007-2010 Daniel Marjamäki and cppcheck team. @@ -83,12 +83,12 @@ kate -l(line) (file) Application's name: - + Programmets namn: Command to execute: - + Kommando @@ -142,37 +142,37 @@ kate -l(line) (file) Cppcheck Help - + Cppcheck Hjälp Go back - + Gå tillbaka Back - + Bakåt Go forward - + Gå framåt Forward - + Fram Start - + Start Home - + Hem @@ -180,42 +180,42 @@ kate -l(line) (file) Checking Log - + Analys logg &Save - + &Spara Clear - + Töm Close - + Stäng Save Log - + Spara logg Text files (*.txt *.log);;All files (*.*) - + Text filer (*.txt *.log);;Alla filer (*.*) Cppcheck - Cppcheck + Cppcheck Could not open file for writing: "%1" - + Kunde ej öppna fil för skrivning: "%1" @@ -285,7 +285,7 @@ kate -l(line) (file) Check files - + Analysera filer @@ -301,7 +301,7 @@ kate -l(line) (file) Check directory - + Analysera mapp @@ -327,7 +327,7 @@ kate -l(line) (file) Stop checking - + Stoppa analys @@ -362,60 +362,60 @@ kate -l(line) (file) Errors - + Fel Show errors - + Visa fel Warnings - + Varningar Show warnings - + Visa varningar Performance warnings - + Prestanda varningar Show performance warnings - + Visa prestanda varningar Show &hidden - + Visa dolda Information - + Information Show information messages - + Visa informations meddelanden Portability - + Portabilitet Show portability warnings - + Visa portabilitets varningar @@ -466,42 +466,42 @@ kate -l(line) (file) &Open XML... - + &Öppna XML... Open P&roject File... - + Öppna Projektfil... &New Project File... - + Ny projektfil... &Log View - + Log View - + Logg vy C&lose Project File - + Stäng projektfil &Edit Project File... - + Redigera projektfil... &Statistics - + Statistik @@ -516,13 +516,13 @@ kate -l(line) (file) Style warnings - + Stil varningar Show style warnings - + Visa stil varningar @@ -583,26 +583,28 @@ kate -l(line) (file) You must close the project file before selecting new files or directories! - + Du måste stänga projektfilen innan nya filer eller sökvägar kan väljas! Project: - + Projekt. Open the report file - + Öppna rapportfilen Checking is running. Do you want to stop the checking and exit Cppcheck?. - + Cppcheck kör. + +Vill du stoppa analysen och avsluta Cppcheck? @@ -639,38 +641,38 @@ Do you want to stop the checking and exit Cppcheck?. Cppcheck Help - + Cppcheck Hjälp Failed to load help file (not found) - + Misslyckades att öppna hjälpfilen (hittades ej) Failed to load help file - + Misslykades att öppna hjälpfilen Project files (*.cppcheck);;All files(*.*) - + Projektfiler (*.cppcheck);;Alla filer(*.*) Select Project File - + Välj projektfil Select Project Filename - + Välj Projektfil No project file loaded - + Inget projekt laddat @@ -711,12 +713,12 @@ Do you want to stop the checking and exit Cppcheck?. Japanese Japanease - + Japanska Serbian - + Serbiska @@ -725,17 +727,17 @@ Do you want to stop the checking and exit Cppcheck?. Cppcheck - Cppcheck + Cppcheck Could not read the project file. - + Kunde ej läsa projektfilen. Could not write the project file. - + Kunde ej skriva projektfilen @@ -743,33 +745,33 @@ Do you want to stop the checking and exit Cppcheck?. Project File - + Projektfil Project: - + Projekt: Paths: - + Sökvägar: Browse... - + Bläddra... Include paths: - + Include sökvägar: Defines: - + Defines: @@ -777,17 +779,17 @@ Do you want to stop the checking and exit Cppcheck?. Project file: %1 - + Projektfil: %1 Select include directory - + Välj include sökväg Select directory to check - Välj katalog som skall kontrolleras + Välj katalog som skall kontrolleras @@ -834,7 +836,7 @@ Do you want to stop the checking and exit Cppcheck?. Summary - + Sammanfattning @@ -859,7 +861,7 @@ Do you want to stop the checking and exit Cppcheck?. Hide - + Dölj @@ -875,7 +877,7 @@ Do you want to stop the checking and exit Cppcheck?. Could not find the file! - + Kunde inte hitta filen! @@ -891,12 +893,14 @@ Kontrollera att sökvägen och parametrarna är korrekta. Could not find file: %1 Please select the directory where file is located. - + Kunde inte hitta filen: +%1 +Välj mappen där filen finns. Select Directory - + Välj mapp @@ -911,22 +915,22 @@ Please select the directory where file is located. warning - + varning performance - + prestanda portability - + portabilitet information - + information @@ -953,17 +957,17 @@ För att ställa in vilka fel som skall visas använd visa menyn. Failed to read the report. - + Misslyckades att läsa rapporten. Summary - + Sammanfattning Message - + Meddelande @@ -997,12 +1001,12 @@ För att ställa in vilka fel som skall visas använd visa menyn. Include paths: - + Include sökvägar: Add... - + Lägg till... @@ -1012,18 +1016,18 @@ För att ställa in vilka fel som skall visas använd visa menyn. Ideal count: - + Optimalt värde: TextLabel - + TextLabel Force checking all #ifdef configurations Check all #ifdef configurations - Kontrollera alla #ifdef konfigurationer + Kontrollera alla #ifdef konfigurationer @@ -1038,12 +1042,12 @@ För att ställa in vilka fel som skall visas använd visa menyn. Show internal warnings in log - + Visa interna fel i loggen Enable inline suppressions - + Använd inline suppressions @@ -1088,7 +1092,7 @@ För att ställa in vilka fel som skall visas använd visa menyn. Language - + Språk @@ -1096,7 +1100,7 @@ För att ställa in vilka fel som skall visas använd visa menyn. N/A - + Ej tillgängligt @@ -1111,7 +1115,7 @@ För att ställa in vilka fel som skall visas använd visa menyn. Select include directory - + Välj include mapp @@ -1120,143 +1124,143 @@ För att ställa in vilka fel som skall visas använd visa menyn. Statistics - + Statistik Project - + Projekt Project: - + Projekt: Paths: - + Sökvägar: Include paths: - + Include sökvägar: Defines: - + Defines: Previous Scan - + Föregående analys Path Selected: - + Vald sökväg: Number of Files Scanned: - + Antal analyserade filer: Scan Duration: - + Analys tid: Errors: - + Fel: Warnings: - + Varningar: Stylistic warnings: - + Stil varningar: Portability warnings: - + Portabilitets varningar: TextLabel - + TextLabel Performance issues: - + Prestanda varningar: Information messages: - + Informations meddelanden: Copy to Clipboard - + Kopiera 1 day - + 1 dag %1 days - + %1 dagar 1 hour - + 1 timme %1 hours - + %1 timmar 1 minute - + 1 minut %1 minutes - + %1 minuter 1 second - + 1 sekund %1 seconds - + %1 sekunder 0.%1 seconds - + 0.%1 sekunder and - + och @@ -1277,7 +1281,22 @@ Statistics Performance warnings: %12 Information messages: %13 - + Projectinställningar + Projekt: %1 + Sökvägar: %2 + Include sökvägar: %3 + Defines: %4 +Föregående analys + Sökväg: %5 + Antal analyserade filer: %6 + Tid: %7 +Statistik + Fel: %8 + Varningar: %9 + Stil varningar: %10 + Portability warnings: %11 + Prestanda varningar: %12 + Information meddelanden: %13 diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 97a8ea249..409381a25 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -2708,7 +2708,7 @@ void CheckMemoryLeakInClass::check() const Scope *scope = *i; // only check classes and structures - if (scope->type == Scope::eClass) + if (scope->isClassOrStruct()) { std::list::const_iterator var; for (var = scope->varlist.begin(); var != scope->varlist.end(); ++var) @@ -2999,7 +2999,7 @@ void CheckMemoryLeakStructMember::check() break; // Struct member is allocated => check if it is also properly deallocated.. - else if (Token::Match(tok2, "%varid% . %var% = malloc|strdup|kmalloc (", vartok->varId())) + else if (Token::Match(tok2->previous(), "[;{}] %varid% . %var% = malloc|strdup|kmalloc (", vartok->varId())) { const unsigned int structid(vartok->varId()); const unsigned int structmemberid(tok2->tokAt(2)->varId()); diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 4e5ff04cd..dff996088 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -289,7 +289,8 @@ void CheckOther::checkSelfAssignment() const Token *tok = Token::findmatch(_tokenizer->tokens(), selfAssignmentPattern); while (tok) { - if (tok->varId() && tok->varId() == tok->tokAt(2)->varId()) + if (Token::Match(tok->previous(), "[;{}]") && + tok->varId() && tok->varId() == tok->tokAt(2)->varId()) { selfAssignmentError(tok, tok->str()); } @@ -2731,9 +2732,9 @@ void CheckOther::sprintfOverlappingDataError(const Token *tok, const std::string { reportError(tok, Severity::error, "sprintfOverlappingData", "Undefined behavior: variable is used as parameter and destination in s[n]printf().\n" - "The variable '" + varname + "' is used both as parameter and destination in " - "and destination buffer overlap. Quote from glibc (C-library) documentation " - "(http://www.gnu.org/software/libc/manual/html_mono/libc.html#Formatted-Output-Functions): " + "The variable '" + varname + "' is used both as a parameter and as a destination in " + "s[n]printf(). The origin and destination buffers overlap. Quote from glibc (C-library) " + "documentation (http://www.gnu.org/software/libc/manual/html_mono/libc.html#Formatted-Output-Functions): " "'If copying takes place between objects that overlap as a result of a call " "to sprintf() or snprintf(), the results are undefined.'"); } @@ -2846,8 +2847,9 @@ void CheckOther::sizeofsizeofError(const Token *tok) { reportError(tok, Severity::warning, "sizeofsizeof", "Calling sizeof for 'sizeof'.\n" - "This is suspicious code and most likely there should be just" - "one 'sizeof'. The current code is equivalent to 'sizeof(size_t)'"); + "Calling sizeof for 'sizeof looks like a suspicious code and " + "most likely there should be just one 'sizeof'. The current " + "code is equivalent to 'sizeof(size_t)'"); } void CheckOther::sizeofCalculation() @@ -2901,6 +2903,7 @@ void CheckOther::assignmentInAssertError(const Token *tok, const std::string &va { reportError(tok, Severity::warning, "assignmentInAssert", "Assert statement modifies '" + varname + "'.\n" + "Variable '" + varname + "' is modified insert assert statement. " "Assert statements are removed from release builds so the code inside " "assert statement is not run. If the code is needed also in release " "builds this is a bug."); diff --git a/lib/checkother.h b/lib/checkother.h index bc5b1db35..0ca251491 100644 --- a/lib/checkother.h +++ b/lib/checkother.h @@ -63,6 +63,7 @@ public: checkOther.checkRedundantAssignmentInSwitch(); checkOther.checkAssignmentInAssert(); checkOther.checkSizeofForArrayParameter(); + checkOther.checkSelfAssignment(); } /** @brief Run checks against the simplified token list */ @@ -82,7 +83,6 @@ public: checkOther.checkFflushOnInputStream(); checkOther.invalidScanf(); - checkOther.checkSelfAssignment(); checkOther.checkIncorrectLogicOperator(); checkOther.checkMisusedScopedObject(); checkOther.checkCatchExceptionByValue(); diff --git a/lib/checkpostfixoperator.cpp b/lib/checkpostfixoperator.cpp index 2861926c2..5c0578c40 100644 --- a/lib/checkpostfixoperator.cpp +++ b/lib/checkpostfixoperator.cpp @@ -101,6 +101,7 @@ void CheckPostfixOperator::postfixOperatorError(const Token *tok) { reportError(tok, Severity::performance, "postfixOperator", "Prefer prefix ++/-- operators for non-primitive types.\n" + "Prefix ++/-- operators should be preferred for non-primitive types. " "Pre-increment/decrement can be more efficient than " "post-increment/decrement. Post-increment/decrement usually " "involves keeping a copy of the previous value around and " diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index a2c871db3..e52a4b79f 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -724,6 +724,7 @@ void CheckStl::stlBoundriesError(const Token *tok, const std::string &container_ { reportError(tok, Severity::error, "stlBoundries", "Dangerous container iterator compare using < operator for " + container_name + "\n" + "Container '" + container_name + "' iterator compared with < operator. " "Using < operator with container type iterators is dangerous since the order of " "the items is not guaranteed. One should use != operator instead when comparing " "iterators in the container."); @@ -782,6 +783,7 @@ void CheckStl::if_findError(const Token *tok, bool str) if (str) reportError(tok, Severity::warning, "stlIfStrFind", "Suspicious checking of string::find() return value.\n" + "Checking of string::find() return value looks Suspicious. " "string::find will return 0 if the string is found at position 0. " "If that is wanted to check then string::compare is a faster alternative " "because it doesn't scan through the string."); @@ -870,6 +872,7 @@ void CheckStl::sizeError(const Token *tok) const std::string varname(tok ? tok->str().c_str() : "list"); reportError(tok, Severity::performance, "stlSize", "Possible inefficient checking for '" + varname + "' emptiness.\n" + "Checking for '" + varname + "' emptiness might be inefficient. " "Using " + varname + ".empty() instead of " + varname + ".size() can be faster. " + varname + ".size() can take linear time but " + varname + ".empty() is " "guaranteed to take constant time."); @@ -907,7 +910,9 @@ void CheckStl::redundantCondition() void CheckStl::redundantIfRemoveError(const Token *tok) { - reportError(tok, Severity::style, "redundantIfRemove", "Redundant checking of STL container element.\n" + reportError(tok, Severity::style, "redundantIfRemove", + "Redundant checking of STL container element.\n" + "Redundant checking of STL container element existence before removing it. " "The remove method in the STL will not do anything if element doesn't exist"); } diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index 0bb9cbc98..387603d8f 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -150,7 +150,7 @@ std::string ErrorLogger::ErrorMessage::getXMLHeader(int xml_version) // standard xml header std::ostringstream ostr; - ostr << "\n"; + ostr << "\n"; // version 1 header if (xml_version <= 1) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index a9634b2d1..af0dd6818 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -581,7 +581,9 @@ bool SymbolDatabase::isFunction(const Token *tok, const Token **funcStart, const } // regular function? - else if (Token::Match(tok, "%var% (") && Token::Match(tok->next()->link(), ") const| ;|{|=|:")) + else if (Token::Match(tok, "%var% (") && + (Token::Match(tok->next()->link(), ") const| ;|{|=") || + Token::Match(tok->next()->link(), ") : %var% ("))) { *funcStart = tok; *argStart = tok->next(); diff --git a/man/cppcheck.1.xml b/man/cppcheck.1.xml index 4b3a5dde7..7c86354cd 100644 --- a/man/cppcheck.1.xml +++ b/man/cppcheck.1.xml @@ -106,21 +106,24 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ - + + + - + + @@ -158,34 +161,40 @@ Example: -DDEBUG=1 -D__cplusplus - Enable specific checks. The available ids are: + Enable additional checks. The available ids are: all - Enable all checks. + Enable all checks style - Check coding style. + Check coding style + + + + information + + Enable information messages unusedFunction - Check for unused functions. + Check for unused functions missingInclude - check for missing includes + Check for missing includes - Several ids can be given if you separate them with commas, e.g. --enable=style,unusedFunction. + By default none of the additional checks are enabled. Several ids can be given if you separate them with commas, e.g. --enable=style,unusedFunction. @@ -199,7 +208,13 @@ Example: -DDEBUG=1 -D__cplusplus - + + + Print a list of all possible error messages in XML format. + + + + Used when certain messages should be displayed but should not cause a non-zero exitcode. @@ -232,6 +247,15 @@ default. files, this is not needed. + + + + + Give path to ignore. Give several -i parameters to ignore several paths. Give directory name or filename with path as parameter. +Directory name is matched to all parts of the path. + + + @@ -266,7 +290,7 @@ files, this is not needed. - + Suppress warnings listed in the file. Filename and line are optional. The format of the single line in file is: [error id]:[filename]:[line]. You can use --template or --xml to see the error id. @@ -297,11 +321,17 @@ files, this is not needed. Write results in XML to error stream + + + + Select the XML file version. Currently versions 1 and 2 are available. The default version is 1. + + AUTHOR - The program was written by Bill Egert, Daniel Marjamäki, Gianluca Scacco, Hoang Tuan Su, Kimmo Varis, Leandro Penz, Martin Ettl, Nguyen Duong Tuan, Nicolas Le Cam, Reijo Tomperi, Robert Reif, Slava Semushin, Vesa Pikki and Zachary Blair + The program was written by Daniel Marjamäki and Cppcheck team. See AUTHORS file for list of team members. SEE ALSO diff --git a/test/testclass.cpp b/test/testclass.cpp index ffeac3df6..0fd7f6fcd 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -189,6 +189,7 @@ private: TEST_CASE(symboldatabase8); // ticket #2252 TEST_CASE(symboldatabase9); // ticket #2525 TEST_CASE(symboldatabase10); // ticket #2537 + TEST_CASE(symboldatabase11); // ticket #2539 } // Check the operator Equal @@ -5505,6 +5506,17 @@ private: ASSERT_EQUALS("", errout.str()); } + void symboldatabase11() + { + // ticket #2539 - segmentation fault + checkConst("int g ();\n" + "struct S {\n" + " int i : (false ? g () : 1);\n" + "};\n"); + + ASSERT_EQUALS("", errout.str()); + } + }; REGISTER_TEST(TestClass) diff --git a/test/testerrorlogger.cpp b/test/testerrorlogger.cpp index e716602a5..9e4962e1d 100644 --- a/test/testerrorlogger.cpp +++ b/test/testerrorlogger.cpp @@ -125,7 +125,7 @@ private: std::list locs; locs.push_back(loc); ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId"); - ASSERT_EQUALS("\n", ErrorLogger::ErrorMessage::getXMLHeader(1)); + ASSERT_EQUALS("\n", ErrorLogger::ErrorMessage::getXMLHeader(1)); ASSERT_EQUALS("", ErrorLogger::ErrorMessage::getXMLFooter(1)); ASSERT_EQUALS("", msg.toXML(false,1)); } @@ -138,7 +138,7 @@ private: std::list locs; locs.push_back(loc); ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId"); - ASSERT_EQUALS("\n", ErrorLogger::ErrorMessage::getXMLHeader(1)); + ASSERT_EQUALS("\n", ErrorLogger::ErrorMessage::getXMLHeader(1)); ASSERT_EQUALS("", ErrorLogger::ErrorMessage::getXMLFooter(1)); ASSERT_EQUALS("", msg.toXML(true,1)); } @@ -151,7 +151,7 @@ private: std::list locs; locs.push_back(loc); ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId"); - std::string header("\n\n"); + std::string header("\n\n"); header += " \n "; diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 6699e56ac..713179a00 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -4253,7 +4253,8 @@ private: TEST_CASE(ret2); // assignments - TEST_CASE(assign); + TEST_CASE(assign1); + TEST_CASE(assign2); // Failed allocation TEST_CASE(failedAllocation); @@ -4356,7 +4357,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void assign() + void assign1() { check("static void foo()\n" "{\n" @@ -4385,6 +4386,15 @@ private: } + void assign2() + { + check("static void foo() {\n" + " struct ABC *abc = malloc(123);\n" + " abc->a = abc->b = malloc(10)\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void failedAllocation() { check("static struct ABC * foo()\n" diff --git a/test/testother.cpp b/test/testother.cpp index dced35a69..864cf25a1 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1160,7 +1160,7 @@ private: " std::string var = var = \"test\";\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant assignment of \"var\" to itself\n", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant assignment of \"var\" to itself\n", "", errout.str()); check("void foo()\n" "{\n" @@ -1169,6 +1169,13 @@ private: " return 0;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("void foo()\n" + "{\n" + " int *x = getx();\n" + " *x = x;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void testScanf1()