Skip to content

Commit de751b0

Browse files
committed
C++: Correct UnsignedBitwiseAndExpr.
1 parent 01d3257 commit de751b0

File tree

3 files changed

+3
-4
lines changed

3 files changed

+3
-4
lines changed

cpp/ql/src/semmle/code/cpp/rangeanalysis/SimpleRangeAnalysis.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ private string getValue(Expr e) {
125125
private class UnsignedBitwiseAndExpr extends BitwiseAndExpr {
126126
UnsignedBitwiseAndExpr() {
127127
(
128-
getLeftOperand().getType().getUnderlyingType().(IntegralType).isUnsigned() or
128+
getLeftOperand().getFullyConverted().getType().getUnderlyingType().(IntegralType).isUnsigned() or
129129
getLeftOperand().getValue().toInt() >= 0
130130
) and
131131
(
132-
getRightOperand().getType().getUnderlyingType().(IntegralType).isUnsigned() or
132+
getRightOperand().getFullyConverted().getType().getUnderlyingType().(IntegralType).isUnsigned() or
133133
getRightOperand().getValue().toInt() >= 0
134134
)
135135
}

cpp/ql/test/query-tests/Security/CWE/CWE-190/semmle/ComparisonWithWiderType/ComparisonWithWiderType.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@
1313
| test.c:107:14:107:26 | ... < ... | Comparison between $@ of type unsigned char and $@ of wider type unsigned int. | test.c:83:16:83:16 | c | c | test.c:107:19:107:25 | ... >> ... | ... >> ... |
1414
| test.c:128:15:128:21 | ... < ... | Comparison between $@ of type unsigned char and $@ of wider type unsigned int. | test.c:121:16:121:17 | uc | uc | test.c:123:19:123:20 | sz | sz |
1515
| test.c:139:15:139:21 | ... < ... | Comparison between $@ of type unsigned char and $@ of wider type unsigned int. | test.c:121:16:121:17 | uc | uc | test.c:123:19:123:20 | sz | sz |
16-
| test.c:146:15:146:21 | ... < ... | Comparison between $@ of type unsigned char and $@ of wider type unsigned int. | test.c:121:16:121:17 | uc | uc | test.c:123:19:123:20 | sz | sz |

cpp/ql/test/query-tests/Security/CWE/CWE-190/semmle/ComparisonWithWiderType/test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,5 @@ void test13() {
143143
if (sx < 0) {sx = 0;}
144144
if (sx > 128) {sx = 128;}
145145
sz = (unsigned)sx & (unsigned)sy;
146-
for (uc = 0; uc < sz; uc++) {} // GOOD [FALSE POSITIVE]
146+
for (uc = 0; uc < sz; uc++) {} // GOOD
147147
}

0 commit comments

Comments
 (0)