Skip to content

Commit 6490705

Browse files
committed
INT32-C: Add tests for ++,--
1 parent d3dc330 commit 6490705

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

c/cert/test/rules/INT32-C/SignedIntegerOverflow.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@
2020
| test.c:146:5:146:11 | ... % ... | Operation % of type int may overflow or underflow. |
2121
| test.c:147:5:147:12 | ... %= ... | Operation %= of type signed int may overflow or underflow. |
2222
| test.c:161:3:161:5 | - ... | Operation - of type signed int may overflow or underflow. |
23+
| test.c:173:3:173:6 | ... ++ | Operation ++ of type signed int may overflow or underflow. |
24+
| test.c:189:3:189:6 | ... -- | Operation -- of type signed int may overflow or underflow. |

c/cert/test/rules/INT32-C/test.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,36 @@ void test_negate_precheck(signed int i1) {
167167
} else {
168168
-i1; // COMPLIANT
169169
}
170+
}
171+
172+
void test_inc(signed int i1) {
173+
i1++; // NON_COMPLIANT
174+
}
175+
176+
void test_inc_guard(signed int i1) {
177+
if (i1 < INT_MAX) {
178+
i1++; // COMPLIANT
179+
}
180+
}
181+
182+
void test_inc_loop_guard() {
183+
for (signed int i1 = 0; i1 < 10; i1++) { // COMPLIANT
184+
// ...
185+
}
186+
}
187+
188+
void test_dec(signed int i1) {
189+
i1--; // NON_COMPLIANT
190+
}
191+
192+
void test_dec_guard(signed int i1) {
193+
if (i1 > INT_MIN) {
194+
i1--; // COMPLIANT
195+
}
196+
}
197+
198+
void test_dec_loop_guard() {
199+
for (signed int i1 = 10; i1 > 0; i1--) { // COMPLIANT
200+
// ...
201+
}
170202
}

0 commit comments

Comments
 (0)