[CPP-434] Address comments regarding .ql and .qhelp.

This commit is contained in:
Ziemowit Laski
2019-10-25 14:08:30 -07:00
parent 1d052a8e62
commit f964fe8b0e
2 changed files with 12 additions and 12 deletions

View File

@@ -4,16 +4,16 @@
<qhelp>
<overview>
<p>
Testing for <code>signed</code> integer overflow by adding a
value to a variable and then comparing the result to that variable
is not defined by the C or C++ standards. The comparison may
produce an unintended result, or may be deleted by the compiler
entirely.
Testing for signed integer overflow by adding a
two signed values together and then comparing the result to one
of the values is ill-formed since the overflow check is undefined.
The comparison may produce an unintended result, or may be deleted
by the compiler entirely.
</p>
</overview>
<recommendation>
<p>
Make sure that the comparison in question uses <i>unsigned</i> values.
When checking for overflow, make sure that <code>unsigned</code> values are used.
</p>
</recommendation>
<example>

View File

@@ -2,7 +2,7 @@
* @name Undefined result of signed test for overflow
* @description Testing for overflow by adding a value to a variable
* to see if it "wraps around" works only for
* `unsigned` integer values.
* unsigned integer values.
* @kind problem
* @problem.severity warning
* @precision high
@@ -15,12 +15,12 @@ import cpp
private import semmle.code.cpp.valuenumbering.GlobalValueNumbering
private import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
from RelationalOperation ro, AddExpr add, VariableAccess va1, VariableAccess va2
from RelationalOperation ro, AddExpr add, Expr expr1, Expr expr2
where
ro.getAnOperand() = add and
add.getAnOperand() = va1 and
ro.getAnOperand() = va2 and
globalValueNumber(va1) = globalValueNumber(va2) and
add.getType().getUnspecifiedType().(IntegralType).isSigned() and
add.getAnOperand() = expr1 and
ro.getAnOperand() = expr2 and
globalValueNumber(expr1) = globalValueNumber(expr2) and
add.getUnspecifiedType().(IntegralType).isSigned() and
exprMightOverflowPositively(add)
select ro, "Testing for signed overflow may produce undefined results."