misra-test.c: Add more tests for rule 14.2 (including FP and FN) (#2399)

Adding more tests for rule 14.2 revealed a false negative when the
loop counter is changed inside the loop.
Corresponding line in the example suite:
https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/blob/master/R_14_02.c#L39
Also a false positive has been revealed when the loop counter is
initialized in a function that is called in the first `for` clause.
Corresponding line in the example suite:
https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/blob/master/R_14_02.c#L43
This commit is contained in:
Sebastian 2019-11-30 11:27:31 +01:00 committed by GitHub
parent c942c24289
commit 8d114a40e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 1 deletions

View File

@ -415,10 +415,26 @@ void misra_14_1() {
}
void misra_14_2() {
void misra_14_2_init_value(int32_t *var) {
*var = 0;
}
void misra_14_2(bool b) {
for (dostuff();a<10;a++) {} // 14.2
for (;i++<10;) {} // 14.2
for (;i<10;dostuff()) {} // TODO
int32_t g = 0;
for (int32_t i2 = 0; i2 < 8; ++i2) {
i2 += 2; // FIXME False negative for "14.2". Trac #9490
g += 2; // no-warning
}
for (misra_14_2_init_value(&i); i < 10; ++i) {} // no-warning FIXME: False positive for 14.2 Trac #9491
bool abort = false;
for (i = 0; (i < 10) && !abort; ++i) { // no-warning
if (b) {
abort = true;
}
}
for (;;) {} // no-warning
// TODO check more variants
}