From 9b2b14a608dcf33d974f3246804378167a81afa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 12 Jun 2009 15:20:08 +0200 Subject: [PATCH] doc: generating wiki documentation --- src/check.h | 13 +++++++++++++ src/checkautovariables.h | 10 +++++++--- src/checkbufferoverrun.h | 5 +++++ src/checkclass.h | 6 +++++- src/checkdangerousfunctions.h | 5 +++++ src/checkheaders.h | 5 +++++ src/checkmemoryleak.h | 16 ++++++++++++---- src/checkother.h | 13 +++++++++---- src/checksecurity.h | 5 +++++ src/checkstl.h | 7 ++++++- src/cppcheck.cpp | 22 ++++++++++++++++++++++ 11 files changed, 94 insertions(+), 13 deletions(-) diff --git a/src/check.h b/src/check.h index dc27e7fe1..4ee2f1b0b 100644 --- a/src/check.h +++ b/src/check.h @@ -34,6 +34,7 @@ public: : _tokenizer(0), _settings(0), _errorLogger(0) { instances().push_back(this); + instances().sort(); } /** This constructor is used when running checks.. */ @@ -63,6 +64,9 @@ public: /** get error messages */ virtual void getErrorMessages() = 0; + /** class name */ + virtual std::string name() const = 0; + /** get information about this class */ virtual std::string classInfo() const = 0; @@ -101,7 +105,16 @@ protected: _errorLogger->reportErr(ErrorLogger::ErrorMessage(locationList, severity, msg, id)); } +private: + // compare the names of Check classes + bool operator<(const Check *other) + { + return (name() < other->name()); + } + }; + + #endif diff --git a/src/checkautovariables.h b/src/checkautovariables.h index b51017029..40c7e9c24 100644 --- a/src/checkautovariables.h +++ b/src/checkautovariables.h @@ -71,14 +71,18 @@ private: errorReturnPointerToLocalArray(0); } + std::string name() const + { + return "Auto Variables"; + } + std::string classInfo() const { return "Auto variables are deallocated when they go out of scope. " - "A pointer to an auto variable is therefore only valid as " - "long as the auto variable is in scope.[BR]\n" + "A pointer to an auto variable is therefore only valid as long as the auto variable is in scope.[BR]\n" "Check:\n" " * returning a pointer to auto variable\n" - " * assignement of an auto-variable to an effective parameter of a function\n"; + " * assignment of an auto-variable to an effective parameter of a function\n"; } }; diff --git a/src/checkbufferoverrun.h b/src/checkbufferoverrun.h index c3b9c1fe6..9d327ac64 100644 --- a/src/checkbufferoverrun.h +++ b/src/checkbufferoverrun.h @@ -83,6 +83,11 @@ private: sizeArgumentAsChar(0); } + std::string name() const + { + return "Bounds checking"; + } + std::string classInfo() const { return "out of bounds checking"; diff --git a/src/checkclass.h b/src/checkclass.h index 2d0081c40..c8a0d8842 100644 --- a/src/checkclass.h +++ b/src/checkclass.h @@ -120,13 +120,17 @@ private: virtualDestructorError(0, "Base", "Derived"); } + std::string name() const + { + return "Class"; + } std::string classInfo() const { return "Check the code for each class.\n" " * Missing constructors\n" " * Are all variables initialized by the constructors?\n" - " * Warn if memset, memcpy etc are used on a class.\n" + " * [[CheckMemset|Warn if memset, memcpy etc are used on a class]]\n" " * If it's a base class, check that the destructor is virtual\n" " * The operator= should return a constant reference to itself\n" " * Are there unused private functions\n"; diff --git a/src/checkdangerousfunctions.h b/src/checkdangerousfunctions.h index 921322ffa..9b71b64f9 100644 --- a/src/checkdangerousfunctions.h +++ b/src/checkdangerousfunctions.h @@ -62,6 +62,11 @@ private: dangerousFunctionscanf(0); } + std::string name() const + { + return "Deprecated functions"; + } + std::string classInfo() const { return "Warn if any of these deprecated functions are used:\n" diff --git a/src/checkheaders.h b/src/checkheaders.h index 9a41f1068..708d198d2 100644 --- a/src/checkheaders.h +++ b/src/checkheaders.h @@ -36,6 +36,11 @@ public: private: const Tokenizer *_tokenizer; ErrorLogger *_errorLogger; + + std::string name() const + { + return "Headers"; + } }; //--------------------------------------------------------------------------- diff --git a/src/checkmemoryleak.h b/src/checkmemoryleak.h index 18a395a35..4f8947922 100644 --- a/src/checkmemoryleak.h +++ b/src/checkmemoryleak.h @@ -152,10 +152,14 @@ private: void getErrorMessages() { } + std::string name() const + { + return "Memory leaks (function variables)"; + } + std::string classInfo() const { - return "Memory leaks (function variables)[BR]\n" - "Is there any allocated memory when a function goes out of scope"; + return "Is there any allocated memory when a function goes out of scope"; } }; @@ -204,10 +208,14 @@ private: void getErrorMessages() { } + std::string name() const + { + return "Memory leaks (class variables)"; + } + std::string classInfo() const { - return "Memory leaks (class variables)[BR]\n" - "If the constructor allocate memory then the destructor must deallocate it."; + return "If the constructor allocate memory then the destructor must deallocate it."; } }; diff --git a/src/checkother.h b/src/checkother.h index a6c218431..1761d48a8 100644 --- a/src/checkother.h +++ b/src/checkother.h @@ -163,6 +163,11 @@ private: zerodivError(0); } + std::string name() const + { + return "Other"; + } + std::string classInfo() const { return "Other checks\n" @@ -171,14 +176,14 @@ private: " * bad usage of the function 'strtol'\n" " * bad usage of the function 'sprintf' (overlapping data)\n" " * division with zero\n" - " * unsigned division\n" + " * [[CheckUnsignedDivision|unsigned division]]\n" " * unused struct member\n" " * passing parameter by value\n" - " * char array-index\n" - " * char operand in a bit operation\n" + " * [[charvar|check how signed char variables are used]]\n" " * condition that is always true/false\n" " * unusal pointer arithmetic. For example: \"abc\" + 'd'\n" - " * dereferencing a null pointer\n"; + " * dereferencing a null pointer\n" + " * [[IncompleteStatement|Incomplete statement]]\n"; } }; diff --git a/src/checksecurity.h b/src/checksecurity.h index eeb66f7ce..000c4b0be 100644 --- a/src/checksecurity.h +++ b/src/checksecurity.h @@ -58,6 +58,11 @@ private: unvalidatedInput(0); } + std::string name() const + { + return "Security"; + } + std::string classInfo() const { return "This is an unfinnished check that will detect unvalidated input.\n"; diff --git a/src/checkstl.h b/src/checkstl.h index 2b036cf4d..7cde0e086 100644 --- a/src/checkstl.h +++ b/src/checkstl.h @@ -108,9 +108,14 @@ private: stlBoundriesError(0); } + std::string name() const + { + return "STL usage"; + } + std::string classInfo() const { - return "STL usage:\n" + return "Check for invalid usage of STL:\n" " * out of bounds errors\n" " * misuse of iterators when iterating through a container\n" " * dereferencing an erased iterator\n" diff --git a/src/cppcheck.cpp b/src/cppcheck.cpp index b0d0ef811..d7e353b5f 100644 --- a/src/cppcheck.cpp +++ b/src/cppcheck.cpp @@ -66,6 +66,9 @@ void CppCheck::clearFiles() _fileContents.clear(); } + + + std::string CppCheck::parseFromArgs(int argc, const char* const argv[]) { std::vector pathnames; @@ -217,6 +220,25 @@ std::string CppCheck::parseFromArgs(int argc, const char* const argv[]) return ""; } + // documentation.. + else if (strcmp(argv[i], "--doc") == 0) + { + std::ostringstream doc; + // Get documentation.. + for (std::list::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) + { + doc << "===" << (*it)->name() << "===\n" + << (*it)->classInfo() << "\n\n"; + } + doc << "===" << "Unused functions" << "===\n" + << "Check for functions that are never called\n"; + std::string doc2(doc.str()); + while (doc2.find("\n\n\n") != std::string::npos) + doc2.erase(doc2.find("\n\n\n"), 1); + std::cout << doc2; + return ""; + } + else if (strncmp(argv[i], "-", 1) == 0 || strncmp(argv[i], "--", 2) == 0) { return "cppcheck: error: unrecognized command line option \"" + std::string(argv[i]) + "\"\n";