From eba1b0881dfc220162365a5d64e519c40bad58cd Mon Sep 17 00:00:00 2001 From: amai2012 Date: Sat, 7 May 2016 16:30:54 +0200 Subject: [PATCH] Minor refactoring: use nullptr (instead of 0/NULL), change signature of Tokenizer::createTokens --- lib/check64bit.h | 10 ++-- lib/checkassert.h | 6 +-- lib/checkautovariables.h | 20 ++++---- lib/checkbool.h | 20 ++++---- lib/checkbufferoverrun.h | 30 ++++++------ lib/checkclass.h | 56 +++++++++++----------- lib/checkcondition.h | 26 +++++----- lib/checkexceptionsafety.h | 19 ++++---- lib/checkfunctions.h | 14 +++--- lib/checkinternal.h | 18 +++---- lib/checkio.h | 46 +++++++++--------- lib/checkleakautovar.h | 8 ++-- lib/checkmemoryleak.h | 28 +++++------ lib/checknullpointer.h | 8 ++-- lib/checkother.h | 98 +++++++++++++++++++------------------- lib/checkpostfixoperator.h | 4 +- lib/checksizeof.h | 24 +++++----- lib/checkstl.h | 56 +++++++++++----------- lib/checkstring.h | 20 ++++---- lib/checktype.h | 12 ++--- lib/checkuninitvar.h | 12 ++--- lib/checkunusedfunctions.h | 2 +- lib/checkunusedvar.h | 12 ++--- lib/checkvaarg.h | 12 ++--- lib/errorlogger.h | 2 +- lib/token.h | 6 +-- lib/tokenize.cpp | 5 +- lib/tokenize.h | 2 +- 28 files changed, 287 insertions(+), 289 deletions(-) diff --git a/lib/check64bit.h b/lib/check64bit.h index 1e825508f..1f6378224 100644 --- a/lib/check64bit.h +++ b/lib/check64bit.h @@ -68,11 +68,11 @@ private: void returnPointerError(const Token *tok); void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { - Check64BitPortability c(0, settings, errorLogger); - c.assignmentAddressToIntegerError(0); - c.assignmentIntegerToAddressError(0); - c.returnIntegerError(0); - c.returnPointerError(0); + Check64BitPortability c(nullptr, settings, errorLogger); + c.assignmentAddressToIntegerError(nullptr); + c.assignmentIntegerToAddressError(nullptr); + c.returnIntegerError(nullptr); + c.returnPointerError(nullptr); } static std::string myName() { diff --git a/lib/checkassert.h b/lib/checkassert.h index 8280a9d2f..fb2c30227 100644 --- a/lib/checkassert.h +++ b/lib/checkassert.h @@ -57,9 +57,9 @@ private: void assignmentInAssertError(const Token *tok, const std::string &varname); void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { - CheckAssert c(0, settings, errorLogger); - c.sideEffectInAssertError(0, "function"); - c.assignmentInAssertError(0, "var"); + CheckAssert c(nullptr, settings, errorLogger); + c.sideEffectInAssertError(nullptr, "function"); + c.assignmentInAssertError(nullptr, "var"); } static std::string myName() { diff --git a/lib/checkautovariables.h b/lib/checkautovariables.h index 7c003f2d6..98b74fa0f 100644 --- a/lib/checkautovariables.h +++ b/lib/checkautovariables.h @@ -92,16 +92,16 @@ private: void errorUselessAssignmentPtrArg(const Token *tok); void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { - CheckAutoVariables c(0,settings,errorLogger); - c.errorAutoVariableAssignment(0, false); - c.errorReturnAddressToAutoVariable(0); - c.errorReturnPointerToLocalArray(0); - c.errorReturnReference(0); - c.errorReturnTempReference(0); - c.errorInvalidDeallocation(0); - c.errorReturnAddressOfFunctionParameter(0, "parameter"); - c.errorUselessAssignmentArg(0); - c.errorUselessAssignmentPtrArg(0); + CheckAutoVariables c(nullptr,settings,errorLogger); + c.errorAutoVariableAssignment(nullptr, false); + c.errorReturnAddressToAutoVariable(nullptr); + c.errorReturnPointerToLocalArray(nullptr); + c.errorReturnReference(nullptr); + c.errorReturnTempReference(nullptr); + c.errorInvalidDeallocation(nullptr); + c.errorReturnAddressOfFunctionParameter(nullptr, "parameter"); + c.errorUselessAssignmentArg(nullptr); + c.errorUselessAssignmentPtrArg(nullptr); } static std::string myName() { diff --git a/lib/checkbool.h b/lib/checkbool.h index 9f90a929c..5ab03df5f 100644 --- a/lib/checkbool.h +++ b/lib/checkbool.h @@ -110,17 +110,17 @@ private: void pointerArithBoolError(const Token *tok); void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { - CheckBool c(0, settings, errorLogger); + CheckBool c(nullptr, settings, errorLogger); - c.assignBoolToPointerError(0); - c.assignBoolToFloatError(0); - c.comparisonOfFuncReturningBoolError(0, "func_name"); - c.comparisonOfTwoFuncsReturningBoolError(0, "func_name1", "func_name2"); - c.comparisonOfBoolWithBoolError(0, "var_name"); - c.incrementBooleanError(0); - c.bitwiseOnBooleanError(0, "varname", "&&"); - c.comparisonOfBoolExpressionWithIntError(0, true); - c.pointerArithBoolError(0); + c.assignBoolToPointerError(nullptr); + c.assignBoolToFloatError(nullptr); + c.comparisonOfFuncReturningBoolError(nullptr, "func_name"); + c.comparisonOfTwoFuncsReturningBoolError(nullptr, "func_name1", "func_name2"); + c.comparisonOfBoolWithBoolError(nullptr, "var_name"); + c.incrementBooleanError(nullptr); + c.bitwiseOnBooleanError(nullptr, "varname", "&&"); + c.comparisonOfBoolExpressionWithIntError(nullptr, true); + c.pointerArithBoolError(nullptr); } static std::string myName() { diff --git a/lib/checkbufferoverrun.h b/lib/checkbufferoverrun.h index 3029c2662..c0262d3b2 100644 --- a/lib/checkbufferoverrun.h +++ b/lib/checkbufferoverrun.h @@ -243,23 +243,23 @@ private: public: void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { - CheckBufferOverrun c(0, settings, errorLogger); + CheckBufferOverrun c(nullptr, settings, errorLogger); const std::vector indexes(2, 1); - c.arrayIndexOutOfBoundsError(0, ArrayInfo(0, "array", 1, 2), indexes); - c.bufferOverrunError(0, std::string("buffer")); - c.strncatUsageError(0); - c.outOfBoundsError(0, "index", true, 2, 1); - c.sizeArgumentAsCharError(0); - c.terminateStrncpyError(0, "buffer"); - c.bufferNotZeroTerminatedError(0, "buffer", "strncpy"); - c.negativeIndexError(0, -1); - c.cmdLineArgsError(0); + c.arrayIndexOutOfBoundsError(nullptr, ArrayInfo(0, "array", 1, 2), indexes); + c.bufferOverrunError(nullptr, std::string("buffer")); + c.strncatUsageError(nullptr); + c.outOfBoundsError(nullptr, "index", true, 2, 1); + c.sizeArgumentAsCharError(nullptr); + c.terminateStrncpyError(nullptr, "buffer"); + c.bufferNotZeroTerminatedError(nullptr, "buffer", "strncpy"); + c.negativeIndexError(nullptr, -1); + c.cmdLineArgsError(nullptr); c.pointerOutOfBoundsError(nullptr, nullptr, 0); - c.arrayIndexThenCheckError(0, "index"); - c.possibleBufferOverrunError(0, "source", "destination", false); - c.argumentSizeError(0, "function", "array"); - c.negativeMemoryAllocationSizeError(0); - c.negativeArraySizeError(0); + c.arrayIndexThenCheckError(nullptr, "index"); + c.possibleBufferOverrunError(nullptr, "source", "destination", false); + c.argumentSizeError(nullptr, "function", "array"); + c.negativeMemoryAllocationSizeError(nullptr); + c.negativeArraySizeError(nullptr); c.reportError(nullptr, Severity::warning, "arrayIndexOutOfBoundsCond", "Array 'x[10]' accessed at index 20, which is out of bounds. Otherwise condition 'y==20' is redundant.", CWE119, false); } private: diff --git a/lib/checkclass.h b/lib/checkclass.h index dff80bee3..5fe5742fe 100644 --- a/lib/checkclass.h +++ b/lib/checkclass.h @@ -35,7 +35,7 @@ class Function; class CPPCHECKLIB CheckClass : public Check { public: /** @brief This constructor is used when registering the CheckClass */ - CheckClass() : Check(myName()), symbolDatabase(NULL) { + CheckClass() : Check(myName()), symbolDatabase(nullptr) { } /** @brief This constructor is used when running checks. */ @@ -169,33 +169,33 @@ private: void duplInheritedMembersError(const Token* tok1, const Token* tok2, const std::string &derivedname, const std::string &basename, const std::string &variablename, bool derivedIsStruct, bool baseIsStruct); void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { - CheckClass c(0, settings, errorLogger); - c.noConstructorError(0, "classname", false); - c.noExplicitConstructorError(0, "classname", false); - //c.copyConstructorMallocError(0, 0, "var"); - c.copyConstructorShallowCopyError(0, "var"); - c.noCopyConstructorError(0, "class", false); - c.uninitVarError(0, "classname", "varname", false); - c.operatorEqVarError(0, "classname", "", false); - c.unusedPrivateFunctionError(0, "classname", "funcname"); - c.memsetError(0, "memfunc", "classname", "class"); - c.memsetErrorReference(0, "memfunc", "class"); - c.memsetErrorFloat(0, "class"); - c.mallocOnClassWarning(0, "malloc", 0); - c.mallocOnClassError(0, "malloc", 0, "std::string"); - c.operatorEqReturnError(0, "class"); - c.virtualDestructorError(0, "Base", "Derived", false); - c.thisSubtractionError(0); - c.operatorEqRetRefThisError(0); - c.operatorEqMissingReturnStatementError(0, true); - c.operatorEqShouldBeLeftUnimplementedError(0); - c.operatorEqToSelfError(0); - c.checkConstError(0, "class", "function", false); - c.checkConstError(0, "class", "function", true); - c.initializerListError(0, 0, "class", "variable"); - c.suggestInitializationList(0, "variable"); - c.selfInitializationError(0, "var"); - c.duplInheritedMembersError(0, 0, "class", "class", "variable", false, false); + CheckClass c(nullptr, settings, errorLogger); + c.noConstructorError(nullptr, "classname", false); + c.noExplicitConstructorError(nullptr, "classname", false); + //c.copyConstructorMallocError(nullptr, 0, "var"); + c.copyConstructorShallowCopyError(nullptr, "var"); + c.noCopyConstructorError(nullptr, "class", false); + c.uninitVarError(nullptr, "classname", "varname", false); + c.operatorEqVarError(nullptr, "classname", "", false); + c.unusedPrivateFunctionError(nullptr, "classname", "funcname"); + c.memsetError(nullptr, "memfunc", "classname", "class"); + c.memsetErrorReference(nullptr, "memfunc", "class"); + c.memsetErrorFloat(nullptr, "class"); + c.mallocOnClassWarning(nullptr, "malloc", 0); + c.mallocOnClassError(nullptr, "malloc", 0, "std::string"); + c.operatorEqReturnError(nullptr, "class"); + c.virtualDestructorError(nullptr, "Base", "Derived", false); + c.thisSubtractionError(nullptr); + c.operatorEqRetRefThisError(nullptr); + c.operatorEqMissingReturnStatementError(nullptr, true); + c.operatorEqShouldBeLeftUnimplementedError(nullptr); + c.operatorEqToSelfError(nullptr); + c.checkConstError(nullptr, "class", "function", false); + c.checkConstError(nullptr, "class", "function", true); + c.initializerListError(nullptr, 0, "class", "variable"); + c.suggestInitializationList(nullptr, "variable"); + c.selfInitializationError(nullptr, "var"); + c.duplInheritedMembersError(nullptr, 0, "class", "class", "variable", false, false); } static std::string myName() { diff --git a/lib/checkcondition.h b/lib/checkcondition.h index 6d86b2fce..75519ceea 100644 --- a/lib/checkcondition.h +++ b/lib/checkcondition.h @@ -129,20 +129,20 @@ private: void invalidTestForOverflow(const Token* tok, bool result); void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { - CheckCondition c(0, settings, errorLogger); + CheckCondition c(nullptr, settings, errorLogger); - c.assignIfError(0, 0, "", false); - c.badBitmaskCheckError(0); - c.comparisonError(0, "&", 6, "==", 1, false); - c.multiConditionError(0,1); - c.mismatchingBitAndError(0, 0xf0, 0, 1); - c.oppositeInnerConditionError(0, 0); - c.incorrectLogicOperatorError(0, "foo > 3 && foo < 4", true); - c.redundantConditionError(0, "If x > 11 the condition x > 10 is always true."); - c.moduloAlwaysTrueFalseError(0, "1"); - c.clarifyConditionError(0, true, false); - c.alwaysTrueFalseError(0, true); - c.invalidTestForOverflow(0, false); + c.assignIfError(nullptr, 0, "", false); + c.badBitmaskCheckError(nullptr); + c.comparisonError(nullptr, "&", 6, "==", 1, false); + c.multiConditionError(nullptr,1); + c.mismatchingBitAndError(nullptr, 0xf0, 0, 1); + c.oppositeInnerConditionError(nullptr, 0); + c.incorrectLogicOperatorError(nullptr, "foo > 3 && foo < 4", true); + c.redundantConditionError(nullptr, "If x > 11 the condition x > 10 is always true."); + c.moduloAlwaysTrueFalseError(nullptr, "1"); + c.clarifyConditionError(nullptr, true, false); + c.alwaysTrueFalseError(nullptr, true); + c.invalidTestForOverflow(nullptr, false); } static std::string myName() { diff --git a/lib/checkexceptionsafety.h b/lib/checkexceptionsafety.h index fba0d9e70..cda9e2ac9 100644 --- a/lib/checkexceptionsafety.h +++ b/lib/checkexceptionsafety.h @@ -23,6 +23,7 @@ #include "config.h" #include "check.h" +#include "utils.h" // CWE ID used: static const struct CWE CWE398(398U); // Indicator of Poor Code Quality @@ -119,9 +120,7 @@ private: /** Missing exception specification */ void unhandledExceptionSpecificationError(const Token * const tok1, const Token * const tok2, const std::string & funcname) { std::string str1(tok1 ? tok1->str() : "foo"); - std::list locationList; - locationList.push_back(tok1); - locationList.push_back(tok2); + const std::list locationList = make_container< std::list > () << tok1 << tok2; reportError(locationList, Severity::style, "unhandledExceptionSpecification", "Unhandled exception specification when calling function " + str1 + "().\n" "Unhandled exception specification when calling function " + str1 + "(). " @@ -130,13 +129,13 @@ private: /** Generate all possible errors (for --errorlist) */ void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { - CheckExceptionSafety c(0, settings, errorLogger); - c.destructorsError(0, "Class"); - c.deallocThrowError(0, "p"); - c.rethrowCopyError(0, "varname"); - c.catchExceptionByValueError(0); - c.noexceptThrowError(0); - c.unhandledExceptionSpecificationError(0, 0, "funcname"); + CheckExceptionSafety c(nullptr, settings, errorLogger); + c.destructorsError(nullptr, "Class"); + c.deallocThrowError(nullptr, "p"); + c.rethrowCopyError(nullptr, "varname"); + c.catchExceptionByValueError(nullptr); + c.noexceptThrowError(nullptr); + c.unhandledExceptionSpecificationError(nullptr, 0, "funcname"); } /** Short description of class (for --doc) */ diff --git a/lib/checkfunctions.h b/lib/checkfunctions.h index b99ed0e93..088d8f257 100644 --- a/lib/checkfunctions.h +++ b/lib/checkfunctions.h @@ -95,17 +95,17 @@ private: void mathfunctionCallWarning(const Token *tok, const std::string& oldexp, const std::string& newexp); void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { - CheckFunctions c(0, settings, errorLogger); + CheckFunctions c(nullptr, settings, errorLogger); for (std::map::const_iterator i = settings->library.functionwarn.cbegin(); i != settings->library.functionwarn.cend(); ++i) { - c.reportError(0, Severity::style, i->first+"Called", i->second.message); + c.reportError(nullptr, Severity::style, i->first+"Called", i->second.message); } - c.invalidFunctionArgError(0, "func_name", 1, "1-4"); - c.invalidFunctionArgBoolError(0, "func_name", 1); - c.ignoredReturnValueError(0, "malloc"); - c.mathfunctionCallWarning(0); - c.mathfunctionCallWarning(0, "1 - erf(x)", "erfc(x)"); + c.invalidFunctionArgError(nullptr, "func_name", 1, "1-4"); + c.invalidFunctionArgBoolError(nullptr, "func_name", 1); + c.ignoredReturnValueError(nullptr, "malloc"); + c.mathfunctionCallWarning(nullptr); + c.mathfunctionCallWarning(nullptr, "1 - erf(x)", "erfc(x)"); } static std::string myName() { diff --git a/lib/checkinternal.h b/lib/checkinternal.h index 792a04084..9aea830b7 100644 --- a/lib/checkinternal.h +++ b/lib/checkinternal.h @@ -85,15 +85,15 @@ private: void extraWhitespaceError(const Token *tok, const std::string &pattern, const std::string &funcname); void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { - CheckInternal c(0, settings, errorLogger); - c.multiComparePatternError(0, ";|%type%", "Match"); - c.simplePatternError(0, "class {", "Match"); - c.complexPatternError(0, "%type% ( )", "Match"); - c.missingPercentCharacterError(0, "%num", "Match"); - c.unknownPatternError(0, "%typ"); - c.redundantNextPreviousError(0, "previous", "next"); - c.orInComplexPattern(0, "||", "Match"); - c.extraWhitespaceError(0, "%str% ", "Match"); + CheckInternal c(nullptr, settings, errorLogger); + c.multiComparePatternError(nullptr, ";|%type%", "Match"); + c.simplePatternError(nullptr, "class {", "Match"); + c.complexPatternError(nullptr, "%type% ( )", "Match"); + c.missingPercentCharacterError(nullptr, "%num", "Match"); + c.unknownPatternError(nullptr, "%typ"); + c.redundantNextPreviousError(nullptr, "previous", "next"); + c.orInComplexPattern(nullptr, "||", "Match"); + c.extraWhitespaceError(nullptr, "%str% ", "Match"); } static std::string myName() { diff --git a/lib/checkio.h b/lib/checkio.h index 82ce274e5..77e794f34 100644 --- a/lib/checkio.h +++ b/lib/checkio.h @@ -130,30 +130,30 @@ private: static void argumentType(std::ostream & s, const ArgumentInfo * argInfo); void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { - CheckIO c(0, settings, errorLogger); + CheckIO c(nullptr, settings, errorLogger); - c.coutCerrMisusageError(0, "cout"); - c.fflushOnInputStreamError(0, "stdin"); - c.ioWithoutPositioningError(0); - c.readWriteOnlyFileError(0); - c.writeReadOnlyFileError(0); - c.useClosedFileError(0); - c.seekOnAppendedFileError(0); - c.invalidScanfError(0); - c.wrongPrintfScanfArgumentsError(0,"printf",3,2); - c.invalidScanfArgTypeError_s(0, 1, "s", NULL); - c.invalidScanfArgTypeError_int(0, 1, "d", NULL, false); - c.invalidScanfArgTypeError_float(0, 1, "f", NULL); - c.invalidPrintfArgTypeError_s(0, 1, NULL); - c.invalidPrintfArgTypeError_n(0, 1, NULL); - c.invalidPrintfArgTypeError_p(0, 1, NULL); - c.invalidPrintfArgTypeError_int(0, 1, "X", NULL); - c.invalidPrintfArgTypeError_uint(0, 1, "u", NULL); - c.invalidPrintfArgTypeError_sint(0, 1, "i", NULL); - c.invalidPrintfArgTypeError_float(0, 1, "f", NULL); - c.invalidLengthModifierError(0, 1, "I"); - c.invalidScanfFormatWidthError(0, 10, 5, NULL); - c.wrongPrintfScanfPosixParameterPositionError(0, "printf", 2, 1); + c.coutCerrMisusageError(nullptr, "cout"); + c.fflushOnInputStreamError(nullptr, "stdin"); + c.ioWithoutPositioningError(nullptr); + c.readWriteOnlyFileError(nullptr); + c.writeReadOnlyFileError(nullptr); + c.useClosedFileError(nullptr); + c.seekOnAppendedFileError(nullptr); + c.invalidScanfError(nullptr); + c.wrongPrintfScanfArgumentsError(nullptr, "printf",3,2); + c.invalidScanfArgTypeError_s(nullptr, 1, "s", nullptr); + c.invalidScanfArgTypeError_int(nullptr, 1, "d", nullptr, false); + c.invalidScanfArgTypeError_float(nullptr, 1, "f", nullptr); + c.invalidPrintfArgTypeError_s(nullptr, 1, nullptr); + c.invalidPrintfArgTypeError_n(nullptr, 1, nullptr); + c.invalidPrintfArgTypeError_p(nullptr, 1, nullptr); + c.invalidPrintfArgTypeError_int(nullptr, 1, "X", nullptr); + c.invalidPrintfArgTypeError_uint(nullptr, 1, "u", nullptr); + c.invalidPrintfArgTypeError_sint(nullptr, 1, "i", nullptr); + c.invalidPrintfArgTypeError_float(nullptr, 1, "f", nullptr); + c.invalidLengthModifierError(nullptr, 1, "I"); + c.invalidScanfFormatWidthError(nullptr, 10, 5, nullptr); + c.wrongPrintfScanfPosixParameterPositionError(nullptr, "printf", 2, 1); } static std::string myName() { diff --git a/lib/checkleakautovar.h b/lib/checkleakautovar.h index f925b6271..99779ef05 100644 --- a/lib/checkleakautovar.h +++ b/lib/checkleakautovar.h @@ -126,10 +126,10 @@ private: void configurationInfo(const Token* tok, const std::string &functionName); void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { - CheckLeakAutoVar c(0, settings, errorLogger); - c.deallocReturnError(0, "p"); - c.configurationInfo(0, "f"); // user configuration is needed to complete analysis - c.doubleFreeError(0, "varname", 0); + CheckLeakAutoVar c(nullptr, settings, errorLogger); + c.deallocReturnError(nullptr, "p"); + c.configurationInfo(nullptr, "f"); // user configuration is needed to complete analysis + c.doubleFreeError(nullptr, "varname", 0); } static std::string myName() { diff --git a/lib/checkmemoryleak.h b/lib/checkmemoryleak.h index 73504062c..9f32b83d0 100644 --- a/lib/checkmemoryleak.h +++ b/lib/checkmemoryleak.h @@ -108,7 +108,7 @@ public: /** * @brief Get type of allocation at given position */ - AllocType getAllocationType(const Token *tok2, unsigned int varid, std::list *callstack = NULL) const; + AllocType getAllocationType(const Token *tok2, unsigned int varid, std::list *callstack = nullptr) const; /** * @brief Get type of reallocation at given position @@ -149,7 +149,7 @@ public: void memleakUponReallocFailureError(const Token *tok, const std::string &varname) const; /** What type of allocated memory does the given function return? */ - AllocType functionReturnType(const Function* func, std::list *callstack = NULL) const; + AllocType functionReturnType(const Function* func, std::list *callstack = nullptr) const; /** Function allocates pointed-to argument (a la asprintf)? */ const char *functionArgAlloc(const Function *func, unsigned int targetpar, AllocType &allocType) const; @@ -176,7 +176,7 @@ public: class CPPCHECKLIB CheckMemoryLeakInFunction : private Check, public CheckMemoryLeak { public: /** @brief This constructor is used when registering this class */ - CheckMemoryLeakInFunction() : Check(myName()), CheckMemoryLeak(0, 0, 0), symbolDatabase(NULL) { + CheckMemoryLeakInFunction() : Check(myName()), CheckMemoryLeak(0, 0, 0), symbolDatabase(nullptr) { } /** @brief This constructor is used when running checks */ @@ -284,17 +284,17 @@ public: private: /** Report all possible errors (for the --errorlist) */ void getErrorMessages(ErrorLogger *e, const Settings *settings) const { - CheckMemoryLeakInFunction c(0, settings, e); + CheckMemoryLeakInFunction c(nullptr, settings, e); - c.memleakError(0, "varname"); - c.resourceLeakError(0, "varname"); + c.memleakError(nullptr, "varname"); + c.resourceLeakError(nullptr, "varname"); - c.deallocDeallocError(0, "varname"); - c.deallocuseError(0, "varname"); - c.mismatchSizeError(0, "sz"); + c.deallocDeallocError(nullptr, "varname"); + c.deallocuseError(nullptr, "varname"); + c.mismatchSizeError(nullptr, "sz"); std::list callstack; c.mismatchAllocDealloc(callstack, "varname"); - c.memleakUponReallocFailureError(0, "varname"); + c.memleakUponReallocFailureError(nullptr, "varname"); } /** @@ -442,11 +442,11 @@ private: void unsafeArgAllocError(const Token *tok, const std::string &funcName, const std::string &ptrType, const std::string &objType); void getErrorMessages(ErrorLogger *e, const Settings *settings) const { - CheckMemoryLeakNoVar c(0, settings, e); + CheckMemoryLeakNoVar c(nullptr, settings, e); - c.functionCallLeak(0, "funcName", "funcName"); - c.returnValueNotUsedError(0, "funcName"); - c.unsafeArgAllocError(0, "funcName", "shared_ptr", "int"); + c.functionCallLeak(nullptr, "funcName", "funcName"); + c.returnValueNotUsedError(nullptr, "funcName"); + c.unsafeArgAllocError(nullptr, "funcName", "shared_ptr", "int"); } static std::string myName() { diff --git a/lib/checknullpointer.h b/lib/checknullpointer.h index 7d545429f..d8c92c9bc 100644 --- a/lib/checknullpointer.h +++ b/lib/checknullpointer.h @@ -92,10 +92,10 @@ private: /** Get error messages. Used by --errorlist */ void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { - CheckNullPointer c(0, settings, errorLogger); - c.nullPointerError(0); - c.nullPointerError(0, "pointer", false, true, true); - c.nullPointerError(0, "pointer", nullptr, false); + CheckNullPointer c(nullptr, settings, errorLogger); + c.nullPointerError(nullptr); + c.nullPointerError(nullptr, "pointer", false, true, true); + c.nullPointerError(nullptr, "pointer", nullptr, false); } /** Name of check */ diff --git a/lib/checkother.h b/lib/checkother.h index 40e6cac51..ff6cac786 100644 --- a/lib/checkother.h +++ b/lib/checkother.h @@ -259,61 +259,61 @@ private: void unknownEvaluationOrder(const Token* tok); void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { - CheckOther c(0, settings, errorLogger); + CheckOther c(nullptr, settings, errorLogger); // error - c.zerodivError(0, false); - c.zerodivcondError(0,0,false); - c.misusedScopeObjectError(NULL, "varname"); - c.invalidPointerCastError(0, "float", "double", false); - c.negativeBitwiseShiftError(0,1); - c.checkPipeParameterSizeError(0, "varname", "dimension"); - c.raceAfterInterlockedDecrementError(0); + c.zerodivError(nullptr, false); + c.zerodivcondError(nullptr, 0,false); + c.misusedScopeObjectError(nullptr, "varname"); + c.invalidPointerCastError(nullptr, "float", "double", false); + c.negativeBitwiseShiftError(nullptr, 1); + c.checkPipeParameterSizeError(nullptr, "varname", "dimension"); + c.raceAfterInterlockedDecrementError(nullptr); //performance - c.redundantCopyError(0, "varname"); - c.redundantCopyError(0, 0, "var"); - c.redundantAssignmentError(0, 0, "var", false); + c.redundantCopyError(nullptr, "varname"); + c.redundantCopyError(nullptr, 0, "var"); + c.redundantAssignmentError(nullptr, 0, "var", false); // style/warning - c.checkComparisonFunctionIsAlwaysTrueOrFalseError(0,"isless","varName",false); - c.checkCastIntToCharAndBackError(0,"func_name"); - c.cstyleCastError(0); - c.passedByValueError(0, "parametername"); - c.constStatementError(0, "type"); - c.signedCharArrayIndexError(0); - c.unknownSignCharArrayIndexError(0); - c.charBitOpError(0); - c.variableScopeError(0, "varname"); - c.redundantAssignmentInSwitchError(0, 0, "var"); - c.redundantCopyInSwitchError(0, 0, "var"); - c.switchCaseFallThrough(0); - c.suspiciousCaseInSwitchError(0, "||"); - c.suspiciousEqualityComparisonError(0); - c.selfAssignmentError(0, "varname"); - c.memsetZeroBytesError(0); - c.memsetFloatError(0, "varname"); - c.memsetValueOutOfRangeError(0, "varname"); - c.clarifyCalculationError(0, "+"); - c.clarifyStatementError(0); - c.duplicateBranchError(0, 0); - c.duplicateExpressionError(0, 0, "&&"); - c.duplicateExpressionTernaryError(0); - c.duplicateBreakError(0, false); - c.unreachableCodeError(0, false); - c.unsignedLessThanZeroError(0, "varname", false); - c.unsignedPositiveError(0, "varname", false); - c.pointerLessThanZeroError(0, false); - c.pointerPositiveError(0, false); - c.SuspiciousSemicolonError(0); - c.incompleteArrayFillError(0, "buffer", "memset", false); - c.varFuncNullUBError(0); - c.nanInArithmeticExpressionError(0); - c.commaSeparatedReturnError(0); - c.redundantPointerOpError(0, "varname", false); - c.unusedLabelError(0, true); - c.unusedLabelError(0, false); - c.unknownEvaluationOrder(0); + c.checkComparisonFunctionIsAlwaysTrueOrFalseError(nullptr, "isless","varName",false); + c.checkCastIntToCharAndBackError(nullptr, "func_name"); + c.cstyleCastError(nullptr); + c.passedByValueError(nullptr, "parametername"); + c.constStatementError(nullptr, "type"); + c.signedCharArrayIndexError(nullptr); + c.unknownSignCharArrayIndexError(nullptr); + c.charBitOpError(nullptr); + c.variableScopeError(nullptr, "varname"); + c.redundantAssignmentInSwitchError(nullptr, 0, "var"); + c.redundantCopyInSwitchError(nullptr, 0, "var"); + c.switchCaseFallThrough(nullptr); + c.suspiciousCaseInSwitchError(nullptr, "||"); + c.suspiciousEqualityComparisonError(nullptr); + c.selfAssignmentError(nullptr, "varname"); + c.memsetZeroBytesError(nullptr); + c.memsetFloatError(nullptr, "varname"); + c.memsetValueOutOfRangeError(nullptr, "varname"); + c.clarifyCalculationError(nullptr, "+"); + c.clarifyStatementError(nullptr); + c.duplicateBranchError(nullptr, 0); + c.duplicateExpressionError(nullptr, 0, "&&"); + c.duplicateExpressionTernaryError(nullptr); + c.duplicateBreakError(nullptr, false); + c.unreachableCodeError(nullptr, false); + c.unsignedLessThanZeroError(nullptr, "varname", false); + c.unsignedPositiveError(nullptr, "varname", false); + c.pointerLessThanZeroError(nullptr, false); + c.pointerPositiveError(nullptr, false); + c.SuspiciousSemicolonError(nullptr); + c.incompleteArrayFillError(nullptr, "buffer", "memset", false); + c.varFuncNullUBError(nullptr); + c.nanInArithmeticExpressionError(nullptr); + c.commaSeparatedReturnError(nullptr); + c.redundantPointerOpError(nullptr, "varname", false); + c.unusedLabelError(nullptr, true); + c.unusedLabelError(nullptr, false); + c.unknownEvaluationOrder(nullptr); } static std::string myName() { diff --git a/lib/checkpostfixoperator.h b/lib/checkpostfixoperator.h index 16d6dd49d..c722e35c9 100644 --- a/lib/checkpostfixoperator.h +++ b/lib/checkpostfixoperator.h @@ -59,8 +59,8 @@ private: void postfixOperatorError(const Token *tok); void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { - CheckPostfixOperator c(0, settings, errorLogger); - c.postfixOperatorError(0); + CheckPostfixOperator c(nullptr, settings, errorLogger); + c.postfixOperatorError(nullptr); } static std::string myName() { diff --git a/lib/checksizeof.h b/lib/checksizeof.h index 803697c80..4ed06a382 100644 --- a/lib/checksizeof.h +++ b/lib/checksizeof.h @@ -99,19 +99,19 @@ private: void arithOperationsOnVoidPointerError(const Token* tok, const std::string &varname, const std::string &vartype); void getErrorMessages(ErrorLogger* errorLogger, const Settings* settings) const { - CheckSizeof c(0, settings, errorLogger); + CheckSizeof c(nullptr, settings, errorLogger); - c.sizeofForArrayParameterError(0); - c.sizeofForPointerError(0, "varname"); - c.divideBySizeofError(0, "memset"); - c.sizeofForNumericParameterError(0); - c.sizeofsizeofError(0); - c.sizeofCalculationError(0, false); - c.multiplySizeofError(0); - c.divideSizeofError(0); - c.sizeofVoidError(0); - c.sizeofDereferencedVoidPointerError(0, "varname"); - c.arithOperationsOnVoidPointerError(0, "varname", "vartype"); + c.sizeofForArrayParameterError(nullptr); + c.sizeofForPointerError(nullptr, "varname"); + c.divideBySizeofError(nullptr, "memset"); + c.sizeofForNumericParameterError(nullptr); + c.sizeofsizeofError(nullptr); + c.sizeofCalculationError(nullptr, false); + c.multiplySizeofError(nullptr); + c.divideSizeofError(nullptr); + c.sizeofVoidError(nullptr); + c.sizeofDereferencedVoidPointerError(nullptr, "varname"); + c.arithOperationsOnVoidPointerError(nullptr, "varname", "vartype"); } static std::string myName() { diff --git a/lib/checkstl.h b/lib/checkstl.h index 739f5f497..9d35a305f 100644 --- a/lib/checkstl.h +++ b/lib/checkstl.h @@ -186,34 +186,34 @@ private: void readingEmptyStlContainerError(const Token *tok); void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { - CheckStl c(0, settings, errorLogger); - c.invalidIteratorError(0, "iterator"); - c.iteratorsError(0, "container1", "container2"); - c.mismatchingContainersError(0); - c.dereferenceErasedError(0, 0, "iter"); - c.stlOutOfBoundsError(0, "i", "foo", false); - c.invalidIteratorError(0, "push_back|push_front|insert", "iterator"); - c.invalidPointerError(0, "push_back", "pointer"); - c.stlBoundariesError(0); - c.if_findError(0, false); - c.if_findError(0, true); - c.string_c_strError(0); - c.string_c_strReturn(0); - c.string_c_strParam(0, 0); - c.sizeError(0); - c.missingComparisonError(0, 0); - c.redundantIfRemoveError(0); - c.autoPointerError(0); - c.autoPointerContainerError(0); - c.autoPointerArrayError(0); - c.autoPointerMallocError(0, "malloc"); - c.uselessCallsReturnValueError(0, "str", "find"); - c.uselessCallsSwapError(0, "str"); - c.uselessCallsSubstrError(0, false); - c.uselessCallsEmptyError(0); - c.uselessCallsRemoveError(0, "remove"); - c.dereferenceInvalidIteratorError(0, "i"); - c.readingEmptyStlContainerError(0); + CheckStl c(nullptr, settings, errorLogger); + c.invalidIteratorError(nullptr, "iterator"); + c.iteratorsError(nullptr, "container1", "container2"); + c.mismatchingContainersError(nullptr); + c.dereferenceErasedError(nullptr, nullptr, "iter"); + c.stlOutOfBoundsError(nullptr, "i", "foo", false); + c.invalidIteratorError(nullptr, "push_back|push_front|insert", "iterator"); + c.invalidPointerError(nullptr, "push_back", "pointer"); + c.stlBoundariesError(nullptr); + c.if_findError(nullptr, false); + c.if_findError(nullptr, true); + c.string_c_strError(nullptr); + c.string_c_strReturn(nullptr); + c.string_c_strParam(nullptr, 0); + c.sizeError(nullptr); + c.missingComparisonError(nullptr, 0); + c.redundantIfRemoveError(nullptr); + c.autoPointerError(nullptr); + c.autoPointerContainerError(nullptr); + c.autoPointerArrayError(nullptr); + c.autoPointerMallocError(nullptr, "malloc"); + c.uselessCallsReturnValueError(nullptr, "str", "find"); + c.uselessCallsSwapError(nullptr, "str"); + c.uselessCallsSubstrError(nullptr, false); + c.uselessCallsEmptyError(nullptr); + c.uselessCallsRemoveError(nullptr, "remove"); + c.dereferenceInvalidIteratorError(nullptr, "i"); + c.readingEmptyStlContainerError(nullptr); } static std::string myName() { diff --git a/lib/checkstring.h b/lib/checkstring.h index c85345398..e82cab275 100644 --- a/lib/checkstring.h +++ b/lib/checkstring.h @@ -92,17 +92,17 @@ private: void suspiciousStringCompareError_char(const Token* tok, const std::string& var); void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { - CheckString c(0, settings, errorLogger); + CheckString c(nullptr, settings, errorLogger); - c.stringLiteralWriteError(0,0); - c.sprintfOverlappingDataError(0, "varname"); - c.strPlusCharError(0); - c.incorrectStringCompareError(0, "substr", "\"Hello World\""); - c.suspiciousStringCompareError(0, "foo"); - c.suspiciousStringCompareError_char(0, "foo"); - c.incorrectStringBooleanError(0, "\"Hello World\""); - c.alwaysTrueFalseStringCompareError(0, "str1", "str2"); - c.alwaysTrueStringVariableCompareError(0, "varname1", "varname2"); + c.stringLiteralWriteError(nullptr,0); + c.sprintfOverlappingDataError(nullptr, "varname"); + c.strPlusCharError(nullptr); + c.incorrectStringCompareError(nullptr, "substr", "\"Hello World\""); + c.suspiciousStringCompareError(nullptr, "foo"); + c.suspiciousStringCompareError_char(nullptr, "foo"); + c.incorrectStringBooleanError(nullptr, "\"Hello World\""); + c.alwaysTrueFalseStringCompareError(nullptr, "str1", "str2"); + c.alwaysTrueStringVariableCompareError(nullptr, "varname1", "varname2"); } static std::string myName() { diff --git a/lib/checktype.h b/lib/checktype.h index a682926f9..fa5c0b629 100644 --- a/lib/checktype.h +++ b/lib/checktype.h @@ -80,12 +80,12 @@ private: void longCastReturnError(const Token *tok); void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { - CheckType c(0, settings, errorLogger); - c.tooBigBitwiseShiftError(0, 32, ValueFlow::Value(64)); - c.integerOverflowError(0, ValueFlow::Value(1LL<<32)); - c.signConversionError(0, false); - c.longCastAssignError(0); - c.longCastReturnError(0); + CheckType c(nullptr, settings, errorLogger); + c.tooBigBitwiseShiftError(nullptr, 32, ValueFlow::Value(64)); + c.integerOverflowError(nullptr, ValueFlow::Value(1LL<<32)); + c.signConversionError(nullptr, false); + c.longCastAssignError(nullptr); + c.longCastReturnError(nullptr); } static std::string myName() { diff --git a/lib/checkuninitvar.h b/lib/checkuninitvar.h index 26ad90fd8..64064b1d9 100644 --- a/lib/checkuninitvar.h +++ b/lib/checkuninitvar.h @@ -93,14 +93,14 @@ public: private: void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { - CheckUninitVar c(0, settings, errorLogger); + CheckUninitVar c(nullptr, settings, errorLogger); // error - c.uninitstringError(0, "varname", true); - c.uninitdataError(0, "varname"); - c.uninitvarError(0, "varname"); - c.uninitStructMemberError(0, "a.b"); - c.deadPointerError(0,0); + c.uninitstringError(nullptr, "varname", true); + c.uninitdataError(nullptr, "varname"); + c.uninitvarError(nullptr, "varname"); + c.uninitStructMemberError(nullptr, "a.b"); + c.deadPointerError(nullptr, nullptr); } static std::string myName() { diff --git a/lib/checkunusedfunctions.h b/lib/checkunusedfunctions.h index 1b6804c4a..982511547 100644 --- a/lib/checkunusedfunctions.h +++ b/lib/checkunusedfunctions.h @@ -58,7 +58,7 @@ public: private: void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { - CheckUnusedFunctions c(0, settings, errorLogger); + CheckUnusedFunctions c(nullptr, settings, errorLogger); c.unusedFunctionError(errorLogger, "", 0, "funcName"); } diff --git a/lib/checkunusedvar.h b/lib/checkunusedvar.h index 38f6143b7..dd59aa159 100644 --- a/lib/checkunusedvar.h +++ b/lib/checkunusedvar.h @@ -82,14 +82,14 @@ private: void unassignedVariableError(const Token *tok, const std::string &varname); void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { - CheckUnusedVar c(0, settings, errorLogger); + CheckUnusedVar c(nullptr, settings, errorLogger); // style/warning - c.unusedVariableError(0, "varname"); - c.allocatedButUnusedVariableError(0, "varname"); - c.unreadVariableError(0, "varname"); - c.unassignedVariableError(0, "varname"); - c.unusedStructMemberError(0, "structname", "variable"); + c.unusedVariableError(nullptr, "varname"); + c.allocatedButUnusedVariableError(nullptr, "varname"); + c.unreadVariableError(nullptr, "varname"); + c.unassignedVariableError(nullptr, "varname"); + c.unusedStructMemberError(nullptr, "structname", "variable"); } static std::string myName() { diff --git a/lib/checkvaarg.h b/lib/checkvaarg.h index 5cccdf5c2..6827e9521 100644 --- a/lib/checkvaarg.h +++ b/lib/checkvaarg.h @@ -58,12 +58,12 @@ private: void va_start_subsequentCallsError(const Token *tok, const std::string& varname); void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { - CheckVaarg c(0, settings, errorLogger); - c.wrongParameterTo_va_start_error(0, "arg1", "arg2"); - c.referenceAs_va_start_error(0, "arg1"); - c.va_end_missingError(0, "vl"); - c.va_list_usedBeforeStartedError(0, "vl"); - c.va_start_subsequentCallsError(0, "vl"); + CheckVaarg c(nullptr, settings, errorLogger); + c.wrongParameterTo_va_start_error(nullptr, "arg1", "arg2"); + c.referenceAs_va_start_error(nullptr, "arg1"); + c.va_end_missingError(nullptr, "vl"); + c.va_list_usedBeforeStartedError(nullptr, "vl"); + c.va_start_subsequentCallsError(nullptr, "vl"); } static std::string myName() { diff --git a/lib/errorlogger.h b/lib/errorlogger.h index 29aa61253..fdeb0de3c 100644 --- a/lib/errorlogger.h +++ b/lib/errorlogger.h @@ -130,7 +130,7 @@ public: case debug: return "debug"; }; - throw InternalError(NULL, "Unknown severity"); + throw InternalError(nullptr, "Unknown severity"); } static SeverityType fromString(const std::string &severity) { if (severity.empty()) diff --git a/lib/token.h b/lib/token.h index 176e22c7a..0707ec9d0 100644 --- a/lib/token.h +++ b/lib/token.h @@ -748,7 +748,7 @@ public: if (it->intvalue == val && !it->tokvalue) return &(*it); } - return NULL; + return nullptr; } const ValueFlow::Value * getMaxValue(bool condition) const { @@ -758,7 +758,7 @@ public: if (it->tokvalue) continue; if ((!ret || it->intvalue > ret->intvalue) && - ((it->condition != NULL) == condition)) + ((it->condition != nullptr) == condition)) ret = &(*it); } return ret; @@ -911,7 +911,7 @@ public: bool isCalculation() const; void clearAst() { - _astOperand1 = _astOperand2 = _astParent = NULL; + _astOperand1 = _astOperand2 = _astParent = nullptr; } std::string astString(const char *sep = "") const { diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index e3007ac93..c10b1da29 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1433,8 +1433,7 @@ void Tokenizer::simplifyTypedef() // This is the case of casting operator. // Name is not available, and () should not be // inserted - bool castOperator = inOperator && Token::Match(tok2, "%type% ("); - + const bool castOperator = inOperator && Token::Match(tok2, "%type% ("); Token *tok3; if (!castOperator) { @@ -1679,7 +1678,7 @@ void Tokenizer::simplifyMulAndParens() } bool Tokenizer::createTokens(std::istream &code, - const char FileName[]) + const std::string& FileName) { // make sure settings specified assert(_settings); diff --git a/lib/tokenize.h b/lib/tokenize.h index 8ba36ad34..2f47f3b77 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -72,7 +72,7 @@ public: bool IsScopeNoReturn(const Token *endScopeToken, bool *unknown = nullptr) const; bool createTokens(std::istream &code, - const char FileName[]); + const std::string& FileName); bool simplifyTokens1(const std::string &configuration, bool noSymbolDB_AST = false);