Skip to content

Commit b4adfec

Browse files
committed
CPP: Add test case.
1 parent dc3c5a6 commit b4adfec

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

cpp/ql/test/query-tests/Likely Bugs/Arithmetic/BadAdditionOverflowCheck/PointlessSelfComparison.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
| test.cpp:83:10:83:15 | ... == ... | Self comparison. |
44
| test.cpp:90:10:90:15 | ... == ... | Self comparison. |
55
| test.cpp:118:7:118:32 | ... != ... | Self comparison. |
6+
| test.cpp:145:2:145:30 | ... == ... | Self comparison. |

cpp/ql/test/query-tests/Likely Bugs/Arithmetic/BadAdditionOverflowCheck/test.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,24 @@ int isSmallEnough(unsigned long long x) {
123123
// get compiled away on others.
124124
return x == (size_t)x && x == (u64)x; // GOOD
125125
}
126+
127+
#define markRange(str, x, y) \
128+
if ((x) == (y)) { \
129+
str[x] = '^'; \
130+
} else { \
131+
int i; \
132+
str[x] = '<'; \
133+
for (i = x + 1; i < y; i++) { \
134+
str[i] = '-'; \
135+
} \
136+
str[y] = '>'; \
137+
}
138+
139+
void useMarkRange(int offs) {
140+
char buffer[100];
141+
142+
markRange(buffer, 10, 20);
143+
markRange(buffer, 30, 30);
144+
markRange(buffer, offs, offs + 10);
145+
markRange(buffer, offs, offs); // GOOD (comparison is in the macro) [FALSE POSITIVE]
146+
}

0 commit comments

Comments
 (0)