[CPP-434] Improved query and test suite.

This commit is contained in:
Ziemowit Laski
2019-10-10 18:11:35 -07:00
parent 1ab965761b
commit 33cd6de729
2 changed files with 26 additions and 2 deletions

View File

@@ -14,12 +14,17 @@
import cpp
import semmle.code.cpp.valuenumbering.GlobalValueNumbering
private predicate isSignedWithoutUnsignedCast(Expr e) {
e.getType().getUnspecifiedType().(IntegralType).isSigned() and
not e.getExplicitlyConverted().getType().getUnspecifiedType().(IntegralType).isUnsigned()
}
from RelationalOperation ro, AddExpr add, VariableAccess va1, VariableAccess va2
where
ro.getAnOperand() = add and
add.getAnOperand() = va1 and
ro.getAnOperand() = va2 and
globalValueNumber(va1) = globalValueNumber(va2) and
add.getFullyConverted().getType().getUnspecifiedType().(IntegralType).isSigned() and
not add.getExplicitlyConverted().getType().getUnspecifiedType().(IntegralType).isUnsigned()
isSignedWithoutUnsignedCast(add) and
isSignedWithoutUnsignedCast(va2)
select ro, "Testing for signed overflow may produce undefined results."