added a classInfo function for each check class

This commit is contained in:
Daniel Marjamäki 2009-06-12 12:19:37 +02:00
parent 092bd79ec4
commit 0c01132698
9 changed files with 77 additions and 1 deletions

View File

@ -63,6 +63,9 @@ public:
/** get error messages */ /** get error messages */
virtual void getErrorMessages() = 0; virtual void getErrorMessages() = 0;
/** get information about this class */
virtual std::string classInfo() const = 0;
protected: protected:
const Tokenizer * const _tokenizer; const Tokenizer * const _tokenizer;
const Settings * const _settings; const Settings * const _settings;

View File

@ -70,6 +70,16 @@ private:
reportError(0, "error", "autoVariables", "Wrong assignement of an auto-variable to an effective parameter of a function"); reportError(0, "error", "autoVariables", "Wrong assignement of an auto-variable to an effective parameter of a function");
errorReturnPointerToLocalArray(0); errorReturnPointerToLocalArray(0);
} }
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"
"Check:\n"
" * returning a pointer to auto variable\n"
" * assignement of an auto-variable to an effective parameter of a function\n";
}
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -82,6 +82,11 @@ private:
outOfBounds(0, "index"); outOfBounds(0, "index");
sizeArgumentAsChar(0); sizeArgumentAsChar(0);
} }
std::string classInfo() const
{
return "out of bounds checking";
}
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -120,6 +120,17 @@ private:
virtualDestructorError(0, "Base", "Derived"); virtualDestructorError(0, "Base", "Derived");
} }
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"
" * 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";
}
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#endif #endif

View File

@ -62,7 +62,13 @@ private:
dangerousFunctionscanf(0); dangerousFunctionscanf(0);
} }
std::string classInfo() const
{
return "Warn if any of these deprecated functions are used:\n"
" * mktemp\n"
" * gets\n"
" * scanf\n";
}
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -152,6 +152,11 @@ private:
void getErrorMessages() void getErrorMessages()
{ } { }
std::string classInfo() const
{
return "Memory leaks (function variables)[BR]\n"
"Is there any allocated memory when a function goes out of scope";
}
}; };
@ -199,6 +204,11 @@ private:
void getErrorMessages() void getErrorMessages()
{ } { }
std::string classInfo() const
{
return "Memory leaks (class variables)[BR]\n"
"If the constructor allocate memory then the destructor must deallocate it.";
}
}; };

View File

@ -163,6 +163,23 @@ private:
zerodivError(0); zerodivError(0);
} }
std::string classInfo() const
{
return "Other checks\n"
" * C-style pointer cast in cpp file\n"
" * redundant if\n"
" * bad usage of the function 'strtol'\n"
" * bad usage of the function 'sprintf' (overlapping data)\n"
" * division with zero\n"
" * unsigned division\n"
" * unused struct member\n"
" * passing parameter by value\n"
" * char array-index\n"
" * char operand in a bit operation\n"
" * condition that is always true/false\n"
" * unusal pointer arithmetic. For example: \"abc\" + 'd'\n"
" * dereferencing a null pointer\n";
}
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -57,6 +57,11 @@ private:
std::cout << "===security===" << "\n"; std::cout << "===security===" << "\n";
unvalidatedInput(0); unvalidatedInput(0);
} }
std::string classInfo() const
{
return "This is an unfinnished check that will detect unvalidated input.\n";
}
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -107,6 +107,15 @@ private:
invalidPointerError(0, "pointer"); invalidPointerError(0, "pointer");
stlBoundriesError(0); stlBoundriesError(0);
} }
std::string classInfo() const
{
return "STL usage:\n"
" * out of bounds errors\n"
" * misuse of iterators when iterating through a container\n"
" * dereferencing an erased iterator\n"
" * for vectors: using iterator/pointer after push_back has been used\n";
}
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------