mirror of
https://github.com/github/codeql.git
synced 2026-05-01 19:55:15 +02:00
[CPP-434] Address comments regarding .ql and .qhelp.
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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."
|
||||
|
||||
Reference in New Issue
Block a user