Skip to content

Commit 7d35447

Browse files
author
Daniel Marjamäki
committed
refactoring: renamed the severity "all" to "possible error"
1 parent 11bc519 commit 7d35447

15 files changed

Lines changed: 127 additions & 103 deletions

src/check.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,20 @@ class Check
8080
ErrorLogger * const _errorLogger;
8181

8282
/** report an error */
83-
void reportError(const Token *tok, const std::string &severity, const std::string &id, const std::string &msg)
83+
void reportError(const Token *tok, const Severity::e severity, const std::string &id, const std::string &msg)
8484
{
8585
std::list<const Token *> callstack;
8686
callstack.push_back(tok);
8787
reportError(callstack, severity, id, msg);
8888
}
8989

9090
/** report an error */
91-
void reportError(const std::list<const Token *> &callstack, const std::string &severity, const std::string &id, std::string msg)
91+
void reportError(const std::list<const Token *> &callstack, const Severity::e severity, const std::string &id, std::string msg)
9292
{
9393
// No errorLogger => just report the message to stdout
9494
if (_errorLogger == NULL)
9595
{
96-
std::cout << "(" << severity << ") " << msg << std::endl;
96+
std::cout << "(" << Severity::stringify(severity) << ") " << msg << std::endl;
9797
return;
9898
}
9999

@@ -114,7 +114,7 @@ class Check
114114
locationList.push_back(loc);
115115
}
116116

117-
_errorLogger->reportErr(ErrorLogger::ErrorMessage(locationList, severity, msg, id));
117+
_errorLogger->reportErr(ErrorLogger::ErrorMessage(locationList, Severity::stringify(severity), msg, id));
118118
}
119119

120120
private:

src/checkautovariables.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,23 +195,23 @@ void CheckAutoVariables::autoVariables()
195195
{
196196
if (errorAv(tok->tokAt(1), tok->tokAt(4)))
197197
reportError(tok,
198-
"error",
198+
Severity::error,
199199
"autoVariables",
200200
"Wrong assignement of an auto-variable to an effective parameter of a function");
201201
}
202202
else if (bindent > 0 && Token::Match(tok, "[;{}] %var% [ %any% ] = & %var%")) //Critical assignement
203203
{
204204
if (errorAv(tok->tokAt(1), tok->tokAt(7)))
205205
reportError(tok,
206-
"error",
206+
Severity::error,
207207
"autoVariables",
208208
"Wrong assignement of an auto-variable to an effective parameter of a function");
209209
}
210210
else if (bindent > 0 && Token::Match(tok, "return & %var% ;")) //Critical return
211211
{
212212
if (isAutoVar(tok->tokAt(2)))
213213
reportError(tok,
214-
"error",
214+
Severity::error,
215215
"autoVariables",
216216
"Return of the address of an auto-variable");
217217
}
@@ -285,7 +285,7 @@ void CheckAutoVariables::returnPointerToLocalArray()
285285

286286
void CheckAutoVariables::errorReturnPointerToLocalArray(const Token *tok)
287287
{
288-
reportError(tok, "error", "returnLocalVariable", "Returning pointer to local array variable");
288+
reportError(tok, Severity::error, "returnLocalVariable", "Returning pointer to local array variable");
289289
}
290290

291291

src/checkautovariables.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class CheckAutoVariables : public Check
6767
void getErrorMessages()
6868
{
6969
std::cout << "===auto variables===" << "\n";
70-
reportError(0, "error", "autoVariables", "Wrong assignement of an auto-variable to an effective parameter of a function");
70+
reportError(0, Severity::error, "autoVariables", "Wrong assignement of an auto-variable to an effective parameter of a function");
7171
errorReturnPointerToLocalArray(0);
7272
}
7373

src/checkbufferoverrun.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,27 @@ void CheckBufferOverrunClass::arrayIndexOutOfBounds(const Token *tok)
5252

5353
void CheckBufferOverrunClass::arrayIndexOutOfBounds()
5454
{
55-
reportError(_callStack, "all", "arrayIndexOutOfBounds", "Array index out of bounds");
55+
reportError(_callStack, Severity::possibleError, "arrayIndexOutOfBounds", "Array index out of bounds");
5656
}
5757

5858
void CheckBufferOverrunClass::bufferOverrun(const Token *tok)
5959
{
60-
reportError(tok, "all", "bufferOverrun", "Buffer overrun");
60+
reportError(tok, Severity::possibleError, "bufferOverrun", "Buffer overrun");
6161
}
6262

6363
void CheckBufferOverrunClass::strncatUsage(const Token *tok)
6464
{
65-
reportError(tok, "all", "strncatUsage", "Dangerous usage of strncat. Tip: the 3rd parameter means maximum number of characters to append");
65+
reportError(tok, Severity::possibleError, "strncatUsage", "Dangerous usage of strncat. Tip: the 3rd parameter means maximum number of characters to append");
6666
}
6767

6868
void CheckBufferOverrunClass::outOfBounds(const Token *tok, const std::string &what)
6969
{
70-
reportError(tok, "error", "outOfBounds", what + " is out of bounds");
70+
reportError(tok, Severity::error, "outOfBounds", what + " is out of bounds");
7171
}
7272

7373
void CheckBufferOverrunClass::sizeArgumentAsChar(const Token *tok)
7474
{
75-
reportError(tok, "all", "sizeArgumentAsChar", "The size argument is given as a char constant");
75+
reportError(tok, Severity::possibleError, "sizeArgumentAsChar", "The size argument is given as a char constant");
7676
}
7777

7878
//---------------------------------------------------------------------------

src/checkclass.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -774,42 +774,42 @@ void CheckClass::virtualDestructor()
774774

775775
void CheckClass::noConstructorError(const Token *tok, const std::string &classname)
776776
{
777-
reportError(tok, "style", "noConstructor", "The class '" + classname + "' has no constructor");
777+
reportError(tok, Severity::style, "noConstructor", "The class '" + classname + "' has no constructor");
778778
}
779779

780780
void CheckClass::uninitVarError(const Token *tok, const std::string &classname, const std::string &varname)
781781
{
782-
reportError(tok, "style", "uninitVar", "Member variable not initialized in the constructor '" + classname + "::" + varname + "'");
782+
reportError(tok, Severity::style, "uninitVar", "Member variable not initialized in the constructor '" + classname + "::" + varname + "'");
783783
}
784784

785785
void CheckClass::operatorEqVarError(const Token *tok, const std::string &classname, const std::string &varname)
786786
{
787-
reportError(tok, "all style", "operatorEqVarError", "Member variable '" + classname + "::" + varname + "' is not assigned a value in '" + classname + "::operator=" + "'");
787+
reportError(tok, Severity::possibleStyle, "operatorEqVarError", "Member variable '" + classname + "::" + varname + "' is not assigned a value in '" + classname + "::operator=" + "'");
788788
}
789789

790790
void CheckClass::unusedPrivateFunctionError(const Token *tok, const std::string &classname, const std::string &funcname)
791791
{
792-
reportError(tok, "style", "unusedPrivateFunction", "Unused private function '" + classname + "::" + funcname + "'");
792+
reportError(tok, Severity::style, "unusedPrivateFunction", "Unused private function '" + classname + "::" + funcname + "'");
793793
}
794794

795795
void CheckClass::memsetClassError(const Token *tok, const std::string &memfunc)
796796
{
797-
reportError(tok, "error", "memsetClass", "Using '" + memfunc + "' on class");
797+
reportError(tok, Severity::error, "memsetClass", "Using '" + memfunc + "' on class");
798798
}
799799

800800
void CheckClass::memsetStructError(const Token *tok, const std::string &memfunc, const std::string &classname)
801801
{
802-
reportError(tok, "error", "memsetStruct", "Using '" + memfunc + "' on struct that contains a 'std::" + classname + "'");
802+
reportError(tok, Severity::error, "memsetStruct", "Using '" + memfunc + "' on struct that contains a 'std::" + classname + "'");
803803
}
804804

805805
void CheckClass::operatorEqReturnError(const Token *tok)
806806
{
807-
reportError(tok, "style", "operatorEq", "'operator=' should return something");
807+
reportError(tok, Severity::style, "operatorEq", "'operator=' should return something");
808808
}
809809

810810
void CheckClass::virtualDestructorError(const Token *tok, const std::string &Base, const std::string &Derived)
811811
{
812-
reportError(tok, "error", "virtualDestructor", "Class " + Base + " which is inherited by class " + Derived + " does not have a virtual destructor");
812+
reportError(tok, Severity::error, "virtualDestructor", "Class " + Base + " which is inherited by class " + Derived + " does not have a virtual destructor");
813813
}
814814

815815

src/checkdangerousfunctions.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ void CheckDangerousFunctionsClass::dangerousFunctions()
5454

5555
void CheckDangerousFunctionsClass::dangerousFunctionmktemp(const Token *tok)
5656
{
57-
reportError(tok, "style", "dangerousFunctionmktemp", "Found 'mktemp'. You should use 'mkstemp' instead");
57+
reportError(tok, Severity::style, "dangerousFunctionmktemp", "Found 'mktemp'. You should use 'mkstemp' instead");
5858
}
5959

6060
void CheckDangerousFunctionsClass::dangerousFunctiongets(const Token *tok)
6161
{
62-
reportError(tok, "style", "dangerousFunctiongets", "Found 'gets'. You should use 'fgets' instead");
62+
reportError(tok, Severity::style, "dangerousFunctiongets", "Found 'gets'. You should use 'fgets' instead");
6363
}
6464

6565
void CheckDangerousFunctionsClass::dangerousFunctionscanf(const Token *tok)
6666
{
67-
reportError(tok, "style", "dangerousFunctionscanf", "Found 'scanf'. You should use 'fgets' instead");
67+
reportError(tok, Severity::style, "dangerousFunctionscanf", "Found 'scanf'. You should use 'fgets' instead");
6868
}

src/checkmemoryleak.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,37 +226,37 @@ void CheckMemoryLeak::memoryLeak(const Token *tok, const char varname[], AllocTy
226226

227227
void CheckMemoryLeak::memleakError(const Token *tok, const std::string &varname)
228228
{
229-
error(tok, "error", "memleak", "Memory leak: " + varname);
229+
error(tok, Severity::error, "memleak", "Memory leak: " + varname);
230230
}
231231

232232
void CheckMemoryLeak::memleakallError(const Token *tok, const std::string &varname)
233233
{
234-
error(tok, "all", "memleakall", "Memory leak: " + varname);
234+
error(tok, Severity::possibleError, "memleakall", "Memory leak: " + varname);
235235
}
236236

237237
void CheckMemoryLeak::resourceLeakError(const Token *tok, const std::string &varname)
238238
{
239-
error(tok, "error", "resourceLeak", "Resource leak: " + varname);
239+
error(tok, Severity::error, "resourceLeak", "Resource leak: " + varname);
240240
}
241241

242242
void CheckMemoryLeak::deallocDeallocError(const Token *tok, const std::string &varname)
243243
{
244-
error(tok, "error", "deallocDealloc", "Deallocating a deallocated pointer: " + varname);
244+
error(tok, Severity::error, "deallocDealloc", "Deallocating a deallocated pointer: " + varname);
245245
}
246246

247247
void CheckMemoryLeak::deallocuseError(const Token *tok, const std::string &varname)
248248
{
249-
error(tok, "error", "deallocuse", "Using '" + varname + "' after it is deallocated / released");
249+
error(tok, Severity::error, "deallocuse", "Using '" + varname + "' after it is deallocated / released");
250250
}
251251

252252
void CheckMemoryLeak::mismatchSizeError(const Token *tok, const std::string &sz)
253253
{
254-
error(tok, "error", "mismatchSize", "The given size " + sz + " is mismatching");
254+
error(tok, Severity::error, "mismatchSize", "The given size " + sz + " is mismatching");
255255
}
256256

257257
void CheckMemoryLeak::mismatchAllocDealloc(const std::list<const Token *> &callstack, const std::string &varname)
258258
{
259-
error(callstack, "error", "mismatchAllocDealloc", "Mismatching allocation and deallocation: " + varname);
259+
error(callstack, Severity::error, "mismatchAllocDealloc", "Mismatching allocation and deallocation: " + varname);
260260
}
261261

262262
CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Token *tok) const

src/checkmemoryleak.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ class CheckMemoryLeak
6565
void mismatchAllocDealloc(const std::list<const Token *> &callstack, const std::string &varname);
6666

6767
// error message
68-
virtual void error(const Token *tok, const std::string &severity, const std::string &id, const std::string &msg) = 0;
69-
virtual void error(const std::list<const Token *> &callstack, const std::string &severity, const std::string &id, const std::string &msg) = 0;
68+
virtual void error(const Token *tok, const Severity::e severity, const std::string &id, const std::string &msg) = 0;
69+
virtual void error(const std::list<const Token *> &callstack, const Severity::e severity, const std::string &id, const std::string &msg) = 0;
7070

7171
/** What type of allocated memory does the given function return? */
7272
AllocType functionReturnType(const Token *tok) const;
@@ -141,12 +141,12 @@ class CheckMemoryLeakInFunction : public CheckMemoryLeak, public Check
141141

142142
void checkScope(const Token *Tok1, const char varname[], bool classmember, unsigned int sz);
143143

144-
void error(const Token *tok, const std::string &severity, const std::string &id, const std::string &msg)
144+
void error(const Token *tok, const Severity::e severity, const std::string &id, const std::string &msg)
145145
{
146146
reportError(tok, severity, id, msg);
147147
}
148148

149-
void error(const std::list<const Token *> &callstack, const std::string &severity, const std::string &id, const std::string &msg)
149+
void error(const std::list<const Token *> &callstack, const Severity::e severity, const std::string &id, const std::string &msg)
150150
{
151151
reportError(callstack, severity, id, msg);
152152
}
@@ -197,12 +197,12 @@ class CheckMemoryLeakInClass : public CheckMemoryLeak, public Check
197197
void parseClass(const Token *tok1, std::vector<const char *> &classname);
198198
void variable(const char classname[], const Token *tokVarname);
199199

200-
void error(const Token *tok, const std::string &severity, const std::string &id, const std::string &msg)
200+
void error(const Token *tok, const Severity::e severity, const std::string &id, const std::string &msg)
201201
{
202202
reportError(tok, severity, id, msg);
203203
}
204204

205-
void error(const std::list<const Token *> &callstack, const std::string &severity, const std::string &id, const std::string &msg)
205+
void error(const std::list<const Token *> &callstack, const Severity::e severity, const std::string &id, const std::string &msg)
206206
{
207207
reportError(callstack, severity, id, msg);
208208
}
@@ -251,12 +251,12 @@ class CheckMemoryLeakStructMember : public CheckMemoryLeak, public Check
251251

252252
private:
253253

254-
void error(const Token *tok, const std::string &severity, const std::string &id, const std::string &msg)
254+
void error(const Token *tok, const Severity::e severity, const std::string &id, const std::string &msg)
255255
{
256256
reportError(tok, severity, id, msg);
257257
}
258258

259-
void error(const std::list<const Token *> &callstack, const std::string &severity, const std::string &id, const std::string &msg)
259+
void error(const std::list<const Token *> &callstack, const Severity::e severity, const std::string &id, const std::string &msg)
260260
{
261261
reportError(callstack, severity, id, msg);
262262
}

src/checkother.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -965,90 +965,90 @@ void CheckOther::checkZeroDivision()
965965

966966
void CheckOther::cstyleCastError(const Token *tok)
967967
{
968-
reportError(tok, "style", "cstyleCast", "C-style pointer casting");
968+
reportError(tok, Severity::style, "cstyleCast", "C-style pointer casting");
969969
}
970970

971971
void CheckOther::redundantIfDelete0Error(const Token *tok)
972972
{
973-
reportError(tok, "style", "redundantIfDelete0", "Redundant condition. It is safe to deallocate a NULL pointer");
973+
reportError(tok, Severity::style, "redundantIfDelete0", "Redundant condition. It is safe to deallocate a NULL pointer");
974974
}
975975

976976
void CheckOther::redundantIfRemoveError(const Token *tok)
977977
{
978-
reportError(tok, "style", "redundantIfRemove", "Redundant condition. The remove function in the STL will not do anything if element doesn't exist");
978+
reportError(tok, Severity::style, "redundantIfRemove", "Redundant condition. The remove function in the STL will not do anything if element doesn't exist");
979979
}
980980

981981
void CheckOther::dangerousUsageStrtolError(const Token *tok)
982982
{
983-
reportError(tok, "error", "dangerousUsageStrtol", "Invalid radix in call to strtol or strtoul. Must be 0 or 2-36");
983+
reportError(tok, Severity::error, "dangerousUsageStrtol", "Invalid radix in call to strtol or strtoul. Must be 0 or 2-36");
984984
}
985985

986986
void CheckOther::ifNoActionError(const Token *tok)
987987
{
988-
reportError(tok, "style", "ifNoAction", "Found redundant if condition - 'if (condition);'");
988+
reportError(tok, Severity::style, "ifNoAction", "Found redundant if condition - 'if (condition);'");
989989
}
990990

991991
void CheckOther::sprintfOverlappingDataError(const Token *tok, const std::string &varname)
992992
{
993-
reportError(tok, "error", "sprintfOverlappingData", "Overlapping data buffer " + varname + "\nWhen using sprintf the same buffer must not be used both for output and input. The behaviour is undefined when that happens.\nFor example: 'sprintf(str,\"<%s>\",str);'");
993+
reportError(tok, Severity::error, "sprintfOverlappingData", "Overlapping data buffer " + varname + "\nWhen using sprintf the same buffer must not be used both for output and input. The behaviour is undefined when that happens.\nFor example: 'sprintf(str,\"<%s>\",str);'");
994994
}
995995

996996
void CheckOther::udivError(const Token *tok)
997997
{
998-
reportError(tok, "error", "udivError", "Unsigned division. The result will be wrong.");
998+
reportError(tok, Severity::error, "udivError", "Unsigned division. The result will be wrong.");
999999
}
10001000

10011001
void CheckOther::udivWarning(const Token *tok)
10021002
{
1003-
reportError(tok, "all style", "udivWarning", "Warning: Division with signed and unsigned operators");
1003+
reportError(tok, Severity::possibleStyle, "udivWarning", "Warning: Division with signed and unsigned operators");
10041004
}
10051005

10061006
void CheckOther::unusedStructMemberError(const Token *tok, const std::string &structname, const std::string &varname)
10071007
{
1008-
reportError(tok, "style", "unusedStructMember", "struct or union member '" + structname + "::" + varname + "' is never used");
1008+
reportError(tok, Severity::style, "unusedStructMember", "struct or union member '" + structname + "::" + varname + "' is never used");
10091009
}
10101010

10111011
void CheckOther::passedByValueError(const Token *tok, const std::string &parname)
10121012
{
1013-
reportError(tok, "style", "passedByValue", "Function parameter '" + parname + "' is passed by value. It could be passed by reference instead.");
1013+
reportError(tok, Severity::style, "passedByValue", "Function parameter '" + parname + "' is passed by value. It could be passed by reference instead.");
10141014
}
10151015

10161016
void CheckOther::constStatementError(const Token *tok, const std::string &type)
10171017
{
1018-
reportError(tok, "style", "constStatement", "Redundant code: Found a statement that begins with " + type + " constant");
1018+
reportError(tok, Severity::style, "constStatement", "Redundant code: Found a statement that begins with " + type + " constant");
10191019
}
10201020

10211021
void CheckOther::charArrayIndexError(const Token *tok)
10221022
{
1023-
reportError(tok, "style", "charArrayIndex", "Warning - using char variable as array index");
1023+
reportError(tok, Severity::style, "charArrayIndex", "Warning - using char variable as array index");
10241024
}
10251025

10261026
void CheckOther::charBitOpError(const Token *tok)
10271027
{
1028-
reportError(tok, "style", "charBitOp", "Warning - using char variable in bit operation");
1028+
reportError(tok, Severity::style, "charBitOp", "Warning - using char variable in bit operation");
10291029
}
10301030

10311031
void CheckOther::variableScopeError(const Token *tok, const std::string &varname)
10321032
{
1033-
reportError(tok, "style", "variableScope", "The scope of the variable " + varname + " can be limited");
1033+
reportError(tok, Severity::style, "variableScope", "The scope of the variable " + varname + " can be limited");
10341034
}
10351035

10361036
void CheckOther::conditionAlwaysTrueFalse(const Token *tok, const std::string &truefalse)
10371037
{
1038-
reportError(tok, "style", "conditionAlwaysTrueFalse", "Condition is always " + truefalse);
1038+
reportError(tok, Severity::style, "conditionAlwaysTrueFalse", "Condition is always " + truefalse);
10391039
}
10401040

10411041
void CheckOther::strPlusChar(const Token *tok)
10421042
{
1043-
reportError(tok, "error", "strPlusChar", "Unusual pointer arithmetic");
1043+
reportError(tok, Severity::error, "strPlusChar", "Unusual pointer arithmetic");
10441044
}
10451045

10461046
void CheckOther::nullPointerError(const Token *tok)
10471047
{
1048-
reportError(tok, "error", "nullPointer", "Possible null pointer dereference");
1048+
reportError(tok, Severity::error, "nullPointer", "Possible null pointer dereference");
10491049
}
10501050

10511051
void CheckOther::zerodivError(const Token *tok)
10521052
{
1053-
reportError(tok, "error", "zerodiv", "Division by zero");
1053+
reportError(tok, Severity::error, "zerodiv", "Division by zero");
10541054
}

0 commit comments

Comments
 (0)