doc: generating wiki documentation
This commit is contained in:
parent
7bee0cd2df
commit
9b2b14a608
13
src/check.h
13
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
|
||||
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -83,6 +83,11 @@ private:
|
|||
sizeArgumentAsChar(0);
|
||||
}
|
||||
|
||||
std::string name() const
|
||||
{
|
||||
return "Bounds checking";
|
||||
}
|
||||
|
||||
std::string classInfo() const
|
||||
{
|
||||
return "out of bounds checking";
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -36,6 +36,11 @@ public:
|
|||
private:
|
||||
const Tokenizer *_tokenizer;
|
||||
ErrorLogger *_errorLogger;
|
||||
|
||||
std::string name() const
|
||||
{
|
||||
return "Headers";
|
||||
}
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -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.";
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -66,6 +66,9 @@ void CppCheck::clearFiles()
|
|||
_fileContents.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
std::string CppCheck::parseFromArgs(int argc, const char* const argv[])
|
||||
{
|
||||
std::vector<std::string> 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<Check *>::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";
|
||||
|
|
Loading…
Reference in New Issue