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

Add some more tests for rule 10.1. They are given as examples in the
MISRA document. The 10.1 test that causes a false positive for 10.6 can be
found under the 10.6 tests.
Track ticket for false positive:
https://trac.cppcheck.net/ticket/9488
Trac ticket for the false negative:
https://trac.cppcheck.net/ticket/9489
This commit is contained in:
Sebastian 2019-11-27 09:09:17 +01:00 committed by GitHub
parent 937c82efbe
commit e46191e6e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -234,10 +234,16 @@ void misra_9_5() {
int x[] = {[0]=23}; // 9.5
}
void misra_10_1(uint8_t u) {
void misra_10_1(uint8_t u, char c1, char c2) {
int32_t i;
char c;
enum { E1 = 1 };
i = 3 << 1; // 10.1
i = (u & u) << 4; // no-warning
c = c1 & c2; // FIXME: This is not compliant to "10.1". Trac #9489
c = c1 << 1; // 10.1
i = c1 > c2; // no-warning
i = E1 + i; // no-warning
}
void misra_10_4(u32 x, s32 y) {
@ -253,10 +259,11 @@ void misra_10_4(u32 x, s32 y) {
z = (a == misra_10_4_A3) ? y : y; // no-warning
}
void misra_10_6(u8 x, u32 a, u32 b) {
void misra_10_6(u8 x, u32 a, u32 b, char c1, char c2) {
u16 y = x+x; // 10.6
u16 z = ~u8 x ;//10.6
u32 c = ( u16) ( u32 a + u32 b ); //10.6
s32 i = c1 - c2; // FIXME: False positive for 10.6 (this is compliant). Trac #9488
}
void misra_10_8(u8 x, s32 a, s32 b) {