Skip to content

Commit 1c71c74

Browse files
committed
C++: Tests showing problems with casts of typedefs
1 parent 10585e7 commit 1c71c74

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/PointlessComparison.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,23 @@ int negative_zero(double dbl) {
265265
}
266266
return 0;
267267
}
268+
269+
typedef unsigned char u8;
270+
271+
int widening_cast1(u8 c) {
272+
if (c == 0) {
273+
if ((int)c > 0) { // BAD [NOT DETECTED]
274+
return 1;
275+
}
276+
}
277+
return 0;
278+
}
279+
280+
int widening_cast2(u8 c) {
281+
if (c <= 10)
282+
return -1;
283+
else if ((c >= 11) /* BAD [NOT DETECTED] */ && (c <= 47))
284+
return 0;
285+
else
286+
return 1;
287+
}

0 commit comments

Comments
 (0)