From 6788de1d18e72b479ec3238e5aec826d8aba5cf3 Mon Sep 17 00:00:00 2001
From: Ivan Galkin
Date: Fri, 12 Jul 2019 23:42:20 +0200
Subject: [PATCH 1/2] Adjust cppcheck rules with the cppcheck 1.88
Use the up-to-date error descriptions from `cppcheck --errorlist`
close #1733
---
cxx-sensors/src/main/resources/cppcheck.xml | 67 +++++++++------------
1 file changed, 28 insertions(+), 39 deletions(-)
diff --git a/cxx-sensors/src/main/resources/cppcheck.xml b/cxx-sensors/src/main/resources/cppcheck.xml
index f2d10f6b08..f1c184c405 100644
--- a/cxx-sensors/src/main/resources/cppcheck.xml
+++ b/cxx-sensors/src/main/resources/cppcheck.xml
@@ -319,22 +319,15 @@ Buffer overrun possible for long command line arguments.
pointerOutOfBounds
- Undefined behaviour, pointer arithmetic 'expr' or index is out of bounds
+ Pointer arithmetic overflow
-Undefined behaviour, pointer arithmetic '' is out of bounds. From
-chapter 6.5.6 in the C specification:
-"When an expression that has
-integer type is added to or subtracted from a pointer, .." and then
-"If both the pointer operand and the result point to elements of the
-same array object, or one past the last element of the array object,
-the evaluation shall not produce an overflow; otherwise, the behavior
-is undefined."
+Pointer arithmetic overflow.
References
-CWE-398: Indicator of Poor Code Quality
-]]>
+CWE-758: Reliance on Undefined, Unspecified, or Implementation-Defined Behavior
+ ]]>
cwe
bug
@@ -2135,7 +2128,7 @@ string literal.
Calling sizeof for 'sizeof looks like a suspicious code and most
likely there should be just one 'sizeof'. The current code is
-equivalent to 'sizeof(T)'
+equivalent to 'sizeof(size_t)'
References
CWE-682: Incorrect Calculation
@@ -2355,16 +2348,11 @@ The code a+b?c:d
should be written as either (a+b)?c:d
clarifyCondition
Suspicious condition (assignment + comparison)
-
-Suspicious condition (assignment + comparison), it can be clarified with parentheses.
-Suspicious expression. Boolean result is used in bitwise operation. The operator '!'
-and the comparison operators have higher precedence than bitwise operators.
-It is recommended that the expression is clarified with parentheses.
-Suspicious condition (bitwise operator + comparison).
-Comparison operators have higher precedence than bitwise operators.
-Please clarify the condition with parentheses.
-
+
+Suspicious condition (assignment + comparison); Clarify expression
+with parentheses.
+
References
CWE-398: Indicator of Poor Code Quality
]]>
@@ -2717,15 +2705,15 @@ not properly checked.
stlIfStrFind
- Inefficient usage of string::find() in condition; string::compare() would be faster
+ Inefficient usage of string::find() in condition; string::starts_with() would be faster
-Either inefficient or wrong usage of string::find(). string::compare()
-will be faster if string::find's result is compared with 0, because it
-will not scan the whole string. If your intention is to check that
-there are no findings in the string, you should compare with
-std::string::npos.
+Either inefficient or wrong usage of string::find().
+string::starts_with() will be faster if string::find's result is
+compared with 0, because it will not scan the whole string. If your
+intention is to check that there are no findings in the string, you
+should compare with std::string::npos.
References
CWE-597: Use of Wrong Operator in String Comparison
@@ -3305,7 +3293,7 @@ invalid.
BOOST_FOREACH caches the end() iterator. It's undefined behavior if
- you modify the container inside.
+you modify the container inside.
References
CWE-664: Improper Control of a Resource Through its Lifetime
@@ -4264,9 +4252,11 @@ meaningless. Did you intend to write '(*A)++;'?
comparisonOfBoolWithInvalidComparator
- Comparison of a boolean value using relational (<, >, <= or >=) operator
+ Comparison of a boolean value using relational operator (<, >, <= or >=)
- Comparison of a boolean value using relational (<, >, <= or >=) operator.
+ , <= or >=) operator could cause unexpected results.
+ ]]>
comparisonOfBoolWithInvalidComparator
MINOR
@@ -4306,7 +4296,7 @@ unnamed namespace.
-The array 'buffer' is filled incompletely. The function 'function()'
+The array 'buffer' is filled incompletely. The function 'memset()'
needs the size given in bytes, but an element of the given array is
larger than one byte. Did you forget to multiply the size with
'sizeof(*buffer)'?
@@ -4651,7 +4641,7 @@ copy constructor instead of allocating new memory.
Invalid memory address freed
invalidFree
@@ -5695,12 +5685,11 @@ no effect.
-Array 'x[SZ]' accessed at larger index I, which is out of bounds. Otherwise
-condition '==I' is redundant.
+Array 'x[SZ]' accessed at larger index I, which is out of bounds.
References
-CWE-119: Improper Restriction of Operations within the Bounds of a Memory Buffer
-]]>
+CWE-788: Access of Memory Location After End of Buffer
+ ]]>
bug
cert
@@ -6632,8 +6621,8 @@ Unsafe allocation. If funcName() throws, memory could be leaked. Use
make_shared<T>() / make_unique<T>() instead.
References
-CWE-401: Improper Release of Memory Before Removing Last Reference ('Memory Leak')
- ]]>
+CWE-401: Improper Release of Memory Before Removing Last Reference
+ ]]>
cwe
leakUnsafeArgAlloc
From 209ba216efe4311a92793cba9d9147bc4fa98695 Mon Sep 17 00:00:00 2001
From: Ivan Galkin
Date: Fri, 12 Jul 2019 23:50:28 +0200
Subject: [PATCH 2/2] fix html notation
---
cxx-sensors/src/main/resources/cppcheck.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cxx-sensors/src/main/resources/cppcheck.xml b/cxx-sensors/src/main/resources/cppcheck.xml
index f1c184c405..c5636838a5 100644
--- a/cxx-sensors/src/main/resources/cppcheck.xml
+++ b/cxx-sensors/src/main/resources/cppcheck.xml
@@ -4255,7 +4255,7 @@ meaningless. Did you intend to write '(*A)++;'?
Comparison of a boolean value using relational operator (<, >, <= or >=)
, <= or >=) operator could cause unexpected results.
+ The result of the expression 'expression' is of type 'bool'. Comparing 'bool' value using relational (<, >, <= or >=) operator could cause unexpected results.
]]>
comparisonOfBoolWithInvalidComparator