removed unused error messages (#4689)
This commit is contained in:
parent
a338be4682
commit
a09667a6d9
File diff suppressed because it is too large
Load Diff
|
@ -330,21 +330,6 @@ bool CheckAutoVariables::checkAutoVariableAssignment(const Token *expr, bool inc
|
|||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void CheckAutoVariables::errorReturnAddressToAutoVariable(const Token *tok)
|
||||
{
|
||||
reportError(tok, Severity::error, "returnAddressOfAutoVariable", "Address of an auto-variable returned.", CWE562, Certainty::normal);
|
||||
}
|
||||
|
||||
void CheckAutoVariables::errorReturnAddressToAutoVariable(const Token *tok, const ValueFlow::Value *value)
|
||||
{
|
||||
reportError(tok, Severity::error, "returnAddressOfAutoVariable", "Address of auto-variable '" + value->tokvalue->astOperand1()->expressionString() + "' returned", CWE562, Certainty::normal);
|
||||
}
|
||||
|
||||
void CheckAutoVariables::errorReturnPointerToLocalArray(const Token *tok)
|
||||
{
|
||||
reportError(tok, Severity::error, "returnLocalVariable", "Pointer to local array variable returned.", CWE562, Certainty::normal);
|
||||
}
|
||||
|
||||
void CheckAutoVariables::errorAutoVariableAssignment(const Token *tok, bool inconclusive)
|
||||
{
|
||||
if (!inconclusive) {
|
||||
|
@ -366,16 +351,6 @@ void CheckAutoVariables::errorAutoVariableAssignment(const Token *tok, bool inco
|
|||
}
|
||||
}
|
||||
|
||||
void CheckAutoVariables::errorReturnAddressOfFunctionParameter(const Token *tok, const std::string &varname)
|
||||
{
|
||||
reportError(tok, Severity::error, "returnAddressOfFunctionParameter",
|
||||
"$symbol:" + varname + "\n"
|
||||
"Address of function parameter '$symbol' returned.\n"
|
||||
"Address of the function parameter '$symbol' becomes invalid after the function exits because "
|
||||
"function parameters are stored on the stack which is freed when the function exits. Thus the returned "
|
||||
"value is invalid.", CWE562, Certainty::normal);
|
||||
}
|
||||
|
||||
void CheckAutoVariables::errorUselessAssignmentArg(const Token *tok)
|
||||
{
|
||||
reportError(tok,
|
||||
|
|
|
@ -77,9 +77,6 @@ public:
|
|||
void checkVarLifetimeScope(const Token * start, const Token * end);
|
||||
|
||||
private:
|
||||
void errorReturnAddressToAutoVariable(const Token *tok);
|
||||
void errorReturnAddressToAutoVariable(const Token *tok, const ValueFlow::Value *value);
|
||||
void errorReturnPointerToLocalArray(const Token *tok);
|
||||
void errorAutoVariableAssignment(const Token *tok, bool inconclusive);
|
||||
void errorReturnDanglingLifetime(const Token *tok, const ValueFlow::Value* val);
|
||||
void errorInvalidLifetime(const Token *tok, const ValueFlow::Value* val);
|
||||
|
@ -90,7 +87,6 @@ private:
|
|||
void errorDanglingTempReference(const Token* tok, ErrorPath errorPath, bool inconclusive);
|
||||
void errorReturnTempReference(const Token* tok, ErrorPath errorPath, bool inconclusive);
|
||||
void errorInvalidDeallocation(const Token *tok, const ValueFlow::Value *val);
|
||||
void errorReturnAddressOfFunctionParameter(const Token *tok, const std::string &varname);
|
||||
void errorUselessAssignmentArg(const Token *tok);
|
||||
void errorUselessAssignmentPtrArg(const Token *tok);
|
||||
|
||||
|
@ -98,14 +94,11 @@ private:
|
|||
ErrorPath errorPath;
|
||||
CheckAutoVariables c(nullptr,settings,errorLogger);
|
||||
c.errorAutoVariableAssignment(nullptr, false);
|
||||
c.errorReturnAddressToAutoVariable(nullptr);
|
||||
c.errorReturnPointerToLocalArray(nullptr);
|
||||
c.errorReturnReference(nullptr, errorPath, false);
|
||||
c.errorDanglingReference(nullptr, nullptr, errorPath);
|
||||
c.errorReturnTempReference(nullptr, errorPath, false);
|
||||
c.errorDanglingTempReference(nullptr, errorPath, false);
|
||||
c.errorInvalidDeallocation(nullptr, nullptr);
|
||||
c.errorReturnAddressOfFunctionParameter(nullptr, "parameter");
|
||||
c.errorUselessAssignmentArg(nullptr);
|
||||
c.errorUselessAssignmentPtrArg(nullptr);
|
||||
c.errorReturnDanglingLifetime(nullptr, nullptr);
|
||||
|
|
|
@ -111,7 +111,6 @@ private:
|
|||
|
||||
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
|
||||
CheckBool c(nullptr, settings, errorLogger);
|
||||
|
||||
c.assignBoolToPointerError(nullptr);
|
||||
c.assignBoolToFloatError(nullptr);
|
||||
c.comparisonOfFuncReturningBoolError(nullptr, "func_name");
|
||||
|
|
|
@ -56,7 +56,6 @@ static const CWE CWE131(131U); // Incorrect Calculation of Buffer Size
|
|||
static const CWE CWE170(170U); // Improper Null Termination
|
||||
static const CWE CWE_ARGUMENT_SIZE(398U); // Indicator of Poor Code Quality
|
||||
static const CWE CWE_ARRAY_INDEX_THEN_CHECK(398U); // Indicator of Poor Code Quality
|
||||
static const CWE CWE682(682U); // Incorrect Calculation
|
||||
static const CWE CWE758(758U); // Reliance on Undefined, Unspecified, or Implementation-Defined Behavior
|
||||
static const CWE CWE_POINTER_ARITHMETIC_OVERFLOW(758U); // Reliance on Undefined, Unspecified, or Implementation-Defined Behavior
|
||||
static const CWE CWE_BUFFER_UNDERRUN(786U); // Access of Memory Location Before Start of Buffer
|
||||
|
|
|
@ -134,7 +134,6 @@ private:
|
|||
|
||||
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
|
||||
CheckIO c(nullptr, settings, errorLogger);
|
||||
|
||||
c.coutCerrMisusageError(nullptr, "cout");
|
||||
c.fflushOnInputStreamError(nullptr, "stdin");
|
||||
c.ioWithoutPositioningError(nullptr);
|
||||
|
|
|
@ -338,21 +338,11 @@ void CheckMemoryLeak::resourceLeakError(const Token *tok, const std::string &var
|
|||
reportErr(tok, Severity::error, "resourceLeak", errmsg, CWE(775U));
|
||||
}
|
||||
|
||||
void CheckMemoryLeak::deallocDeallocError(const Token *tok, const std::string &varname) const
|
||||
{
|
||||
reportErr(tok, Severity::error, "deallocDealloc", "$symbol:" + varname + "\nDeallocating a deallocated pointer: $symbol", CWE(415U));
|
||||
}
|
||||
|
||||
void CheckMemoryLeak::deallocuseError(const Token *tok, const std::string &varname) const
|
||||
{
|
||||
reportErr(tok, Severity::error, "deallocuse", "$symbol:" + varname + "\nDereferencing '$symbol' after it is deallocated / released", CWE(416U));
|
||||
}
|
||||
|
||||
void CheckMemoryLeak::mismatchSizeError(const Token *tok, const std::string &sz) const
|
||||
{
|
||||
reportErr(tok, Severity::error, "mismatchSize", "The allocated size " + sz + " is not a multiple of the underlying type's size.", CWE(131U));
|
||||
}
|
||||
|
||||
void CheckMemoryLeak::mismatchAllocDealloc(const std::list<const Token *> &callstack, const std::string &varname) const
|
||||
{
|
||||
reportErr(callstack, Severity::error, "mismatchAllocDealloc", "$symbol:" + varname + "\nMismatching allocation and deallocation: $symbol", CWE(762U));
|
||||
|
|
|
@ -137,14 +137,7 @@ public:
|
|||
*/
|
||||
void resourceLeakError(const Token *tok, const std::string &varname) const;
|
||||
|
||||
/**
|
||||
* @brief Report error: deallocating a deallocated pointer
|
||||
* @param tok token where error occurs
|
||||
* @param varname name of variable
|
||||
*/
|
||||
void deallocDeallocError(const Token *tok, const std::string &varname) const;
|
||||
void deallocuseError(const Token *tok, const std::string &varname) const;
|
||||
void mismatchSizeError(const Token *tok, const std::string &sz) const;
|
||||
void mismatchAllocDealloc(const std::list<const Token *> &callstack, const std::string &varname) const;
|
||||
void memleakUponReallocFailureError(const Token *tok, const std::string &reallocfunction, const std::string &varname) const;
|
||||
|
||||
|
@ -196,13 +189,9 @@ private:
|
|||
/** Report all possible errors (for the --errorlist) */
|
||||
void getErrorMessages(ErrorLogger *e, const Settings *settings) const override {
|
||||
CheckMemoryLeakInFunction c(nullptr, settings, e);
|
||||
|
||||
c.memleakError(nullptr, "varname");
|
||||
c.resourceLeakError(nullptr, "varname");
|
||||
|
||||
c.deallocDeallocError(nullptr, "varname");
|
||||
c.deallocuseError(nullptr, "varname");
|
||||
c.mismatchSizeError(nullptr, "sz");
|
||||
const std::list<const Token *> callstack;
|
||||
c.mismatchAllocDealloc(callstack, "varname");
|
||||
c.memleakUponReallocFailureError(nullptr, "realloc", "varname");
|
||||
|
@ -352,7 +341,6 @@ private:
|
|||
|
||||
void getErrorMessages(ErrorLogger *e, const Settings *settings) const override {
|
||||
CheckMemoryLeakNoVar c(nullptr, settings, e);
|
||||
|
||||
c.functionCallLeak(nullptr, "funcName", "funcName");
|
||||
c.returnValueNotUsedError(nullptr, "funcName");
|
||||
c.unsafeArgAllocError(nullptr, "funcName", "shared_ptr", "int");
|
||||
|
|
|
@ -59,7 +59,6 @@ static const struct CWE CWE362(362U); // Concurrent Execution using Shared Res
|
|||
static const struct CWE CWE369(369U); // Divide By Zero
|
||||
static const struct CWE CWE398(398U); // Indicator of Poor Code Quality
|
||||
static const struct CWE CWE475(475U); // Undefined Behavior for Input to API
|
||||
static const struct CWE CWE482(482U); // Comparing instead of Assigning
|
||||
static const struct CWE CWE561(561U); // Dead Code
|
||||
static const struct CWE CWE563(563U); // Assignment to Variable without Use ('Unused Variable')
|
||||
static const struct CWE CWE570(570U); // Expression is Always False
|
||||
|
@ -511,14 +510,6 @@ void CheckOther::redundantCopyError(const Token *tok1, const Token* tok2, const
|
|||
"Buffer '$symbol' is being written before its old content has been used.", CWE563, Certainty::normal);
|
||||
}
|
||||
|
||||
void CheckOther::redundantCopyInSwitchError(const Token *tok1, const Token* tok2, const std::string &var)
|
||||
{
|
||||
const std::list<const Token *> callstack = { tok1, tok2 };
|
||||
reportError(callstack, Severity::style, "redundantCopyInSwitch",
|
||||
"$symbol:" + var + "\n"
|
||||
"Buffer '$symbol' is being written before its old content has been used. 'break;' missing?", CWE563, Certainty::normal);
|
||||
}
|
||||
|
||||
void CheckOther::redundantAssignmentError(const Token *tok1, const Token* tok2, const std::string& var, bool inconclusive)
|
||||
{
|
||||
const ErrorPath errorPath = { ErrorPathItem(tok1, var + " is assigned"), ErrorPathItem(tok2, var + " is overwritten") };
|
||||
|
|
|
@ -247,7 +247,6 @@ private:
|
|||
void redundantInitializationError(const Token *tok1, const Token* tok2, const std::string& var, bool inconclusive);
|
||||
void redundantAssignmentInSwitchError(const Token *tok1, const Token *tok2, const std::string &var);
|
||||
void redundantCopyError(const Token *tok1, const Token* tok2, const std::string& var);
|
||||
void redundantCopyInSwitchError(const Token *tok1, const Token* tok2, const std::string &var);
|
||||
void redundantBitwiseOperationInSwitchError(const Token *tok, const std::string &varname);
|
||||
void suspiciousCaseInSwitchError(const Token* tok, const std::string& operatorString);
|
||||
void selfAssignmentError(const Token *tok, const std::string &varname);
|
||||
|
@ -315,7 +314,6 @@ private:
|
|||
c.charBitOpError(nullptr);
|
||||
c.variableScopeError(nullptr, "varname");
|
||||
c.redundantAssignmentInSwitchError(nullptr, nullptr, "var");
|
||||
c.redundantCopyInSwitchError(nullptr, nullptr, "var");
|
||||
c.suspiciousCaseInSwitchError(nullptr, "||");
|
||||
c.selfAssignmentError(nullptr, "varname");
|
||||
c.clarifyCalculationError(nullptr, "+");
|
||||
|
|
|
@ -103,7 +103,6 @@ private:
|
|||
|
||||
void getErrorMessages(ErrorLogger* errorLogger, const Settings* settings) const override {
|
||||
CheckSizeof c(nullptr, settings, errorLogger);
|
||||
|
||||
c.sizeofForArrayParameterError(nullptr);
|
||||
c.sizeofForPointerError(nullptr, "varname");
|
||||
c.divideBySizeofError(nullptr, "memset");
|
||||
|
|
|
@ -2495,21 +2495,6 @@ void CheckStl::dereferenceInvalidIteratorError(const Token* deref, const std::st
|
|||
"Possible dereference of an invalid iterator: $symbol. Make sure to check that the iterator is valid before dereferencing it - not after.", CWE825, Certainty::normal);
|
||||
}
|
||||
|
||||
void CheckStl::readingEmptyStlContainerError(const Token *tok, const ValueFlow::Value *value)
|
||||
{
|
||||
const std::string varname = tok ? tok->str() : std::string("var");
|
||||
|
||||
std::string errmsg;
|
||||
if (value && value->condition)
|
||||
errmsg = "Reading from container '$symbol'. " + ValueFlow::eitherTheConditionIsRedundant(value->condition) + " or '$symbol' can be empty.";
|
||||
else
|
||||
errmsg = "Reading from empty STL container '$symbol'";
|
||||
|
||||
const ErrorPath errorPath = getErrorPath(tok, value, "Reading from empty container");
|
||||
|
||||
reportError(errorPath, value ? (value->errorSeverity() ? Severity::error : Severity::warning) : Severity::style, "reademptycontainer", "$symbol:" + varname +"\n" + errmsg, CWE398, !value ? Certainty::inconclusive : Certainty::normal);
|
||||
}
|
||||
|
||||
void CheckStl::useStlAlgorithmError(const Token *tok, const std::string &algoName)
|
||||
{
|
||||
reportError(tok, Severity::style, "useStlAlgorithm",
|
||||
|
|
|
@ -230,8 +230,6 @@ private:
|
|||
void dereferenceInvalidIteratorError(const Token* deref, const std::string& iterName);
|
||||
void dereferenceInvalidIteratorError(const Token* tok, const ValueFlow::Value *value, bool inconclusive);
|
||||
|
||||
void readingEmptyStlContainerError(const Token* tok, const ValueFlow::Value *value=nullptr);
|
||||
|
||||
void useStlAlgorithmError(const Token *tok, const std::string &algoName);
|
||||
|
||||
void knownEmptyContainerError(const Token *tok, const std::string& algo);
|
||||
|
@ -273,7 +271,6 @@ private:
|
|||
c.uselessCallsEmptyError(nullptr);
|
||||
c.uselessCallsRemoveError(nullptr, "remove");
|
||||
c.dereferenceInvalidIteratorError(nullptr, "i");
|
||||
c.readingEmptyStlContainerError(nullptr);
|
||||
c.useStlAlgorithmError(nullptr, emptyString);
|
||||
c.knownEmptyContainerError(nullptr, emptyString);
|
||||
c.globalLockGuardError(nullptr);
|
||||
|
|
|
@ -96,7 +96,6 @@ private:
|
|||
|
||||
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
|
||||
CheckString c(nullptr, settings, errorLogger);
|
||||
|
||||
c.stringLiteralWriteError(nullptr, nullptr);
|
||||
c.sprintfOverlappingDataError(nullptr, nullptr, "varname");
|
||||
c.strPlusCharError(nullptr);
|
||||
|
|
|
@ -51,7 +51,6 @@ namespace tinyxml2 {
|
|||
|
||||
// CWE ids used:
|
||||
static const struct CWE CWE_USE_OF_UNINITIALIZED_VARIABLE(457U);
|
||||
static const struct CWE CWE_USE_OF_POTENTIALLY_DANGEROUS_FUNCTION(676U);
|
||||
|
||||
// Register this check class (by creating a static instance of it)
|
||||
namespace {
|
||||
|
@ -1497,11 +1496,6 @@ bool CheckUninitVar::isMemberVariableUsage(const Token *tok, bool isPointer, All
|
|||
return false;
|
||||
}
|
||||
|
||||
void CheckUninitVar::uninitstringError(const Token *tok, const std::string &varname, bool strncpy_)
|
||||
{
|
||||
reportError(tok, Severity::error, "uninitstring", "$symbol:" + varname + "\nDangerous usage of '$symbol'" + (strncpy_ ? " (strncpy doesn't always null-terminate it)." : " (not null-terminated)."), CWE_USE_OF_POTENTIALLY_DANGEROUS_FUNCTION, Certainty::normal);
|
||||
}
|
||||
|
||||
void CheckUninitVar::uninitdataError(const Token *tok, const std::string &varname)
|
||||
{
|
||||
reportError(tok, Severity::error, "uninitdata", "$symbol:" + varname + "\nMemory is allocated but not initialized: $symbol", CWE_USE_OF_UNINITIALIZED_VARIABLE, Certainty::normal);
|
||||
|
|
|
@ -116,7 +116,6 @@ public:
|
|||
bool analyseWholeProgram(const CTU::FileInfo *ctu, const std::list<Check::FileInfo*> &fileInfo, const Settings& settings, ErrorLogger &errorLogger) override;
|
||||
|
||||
void uninitvarError(const Token* tok, const ValueFlow::Value& v);
|
||||
void uninitstringError(const Token *tok, const std::string &varname, bool strncpy_);
|
||||
void uninitdataError(const Token *tok, const std::string &varname);
|
||||
void uninitvarError(const Token *tok, const std::string &varname, ErrorPath errorPath);
|
||||
void uninitvarError(const Token *tok, const std::string &varname) {
|
||||
|
@ -142,9 +141,7 @@ private:
|
|||
|
||||
ValueFlow::Value v{};
|
||||
|
||||
// error
|
||||
c.uninitvarError(nullptr, v);
|
||||
c.uninitstringError(nullptr, "varname", true);
|
||||
c.uninitdataError(nullptr, "varname");
|
||||
c.uninitStructMemberError(nullptr, "a.b");
|
||||
}
|
||||
|
|
|
@ -85,8 +85,6 @@ private:
|
|||
|
||||
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
|
||||
CheckUnusedVar c(nullptr, settings, errorLogger);
|
||||
|
||||
// style/warning
|
||||
c.unusedVariableError(nullptr, "varname");
|
||||
c.allocatedButUnusedVariableError(nullptr, "varname");
|
||||
c.unreadVariableError(nullptr, "varname", false);
|
||||
|
|
Loading…
Reference in New Issue