Skip to content

Commit 892fab6

Browse files
committed
Improved test cases
1 parent abe99ba commit 892fab6

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

c/misra/src/rules/RULE-12-2/RightHandOperandOfAShiftRange.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ where
2929
lowerBound(right) < 0 or
3030
upperBound(right) > max_val
3131
)
32-
select right, "The shift right hand operand shall lie in the range 0 to " + max_val + "."
32+
select right, "The right hand operand of the shift operator shall lie in the range 0 to " + max_val + "."
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
| test.c:8:10:8:10 | 8 | The shift right hand operand shall lie in the range 0 to 7. |
2-
| test.c:10:10:10:14 | ... + ... | The shift right hand operand shall lie in the range 0 to 7. |
3-
| test.c:11:10:11:14 | ... + ... | The shift right hand operand shall lie in the range 0 to 7. |
4-
| test.c:15:9:15:9 | 8 | The shift right hand operand shall lie in the range 0 to 7. |
5-
| test.c:20:9:20:10 | 64 | The shift right hand operand shall lie in the range 0 to 63. |
6-
| test.c:23:10:23:11 | 10 | The shift right hand operand shall lie in the range 0 to 7. |
7-
| test.c:24:10:24:11 | 64 | The shift right hand operand shall lie in the range 0 to 7. |
1+
| test.c:8:10:8:10 | 8 | The right hand operand of the shift operator shall lie in the range 0 to 7. |
2+
| test.c:9:10:9:11 | - ... | The right hand operand of the shift operator shall lie in the range 0 to 7. |
3+
| test.c:10:10:10:14 | ... + ... | The right hand operand of the shift operator shall lie in the range 0 to 7. |
4+
| test.c:11:10:11:14 | ... + ... | The right hand operand of the shift operator shall lie in the range 0 to 7. |
5+
| test.c:13:21:13:22 | 16 | The right hand operand of the shift operator shall lie in the range 0 to 15. |
6+
| test.c:16:9:16:9 | 8 | The right hand operand of the shift operator shall lie in the range 0 to 7. |
7+
| test.c:21:9:21:10 | 64 | The right hand operand of the shift operator shall lie in the range 0 to 63. |
8+
| test.c:25:10:25:10 | 8 | The right hand operand of the shift operator shall lie in the range 0 to 7. |
9+
| test.c:26:10:26:11 | 64 | The right hand operand of the shift operator shall lie in the range 0 to 7. |
10+
| test.c:30:16:30:17 | 64 | The right hand operand of the shift operator shall lie in the range 0 to 63. |

c/misra/test/rules/RULE-12-2/test.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
1+
#include <limits.h>
12
#include <stdint.h>
2-
33
void f1() {
44
uint8_t ui8;
55
int b = 4;
66

7-
ui8 << 7; // COMPLIANT
8-
ui8 >> 8; // NON_COMPLIANT
9-
ui8 << 3 + 3; // COMPLIANT
10-
ui8 >> 4 + b; // NON_COMPLIANT
11-
ui8 << b + b; // NON_COMPLIANT
12-
(uint16_t) ui8 << 9; // COMPLIANT
7+
ui8 << 7; // COMPLIANT
8+
ui8 >> 8; // NON_COMPLIANT
9+
ui8 >> -1; // NON_COMPLIANT
10+
ui8 >> 4 + b; // NON_COMPLIANT
11+
ui8 << b + b; // NON_COMPLIANT
12+
(uint16_t) ui8 << 8; // COMPLIANT
13+
(uint16_t) ui8 << 16; // NON_COMPLIANT
1314

1415
// 0u essential type is essentially unsigned char
1516
0u << 8; // NON_COMPLIANT
1617
(uint16_t)0u << 8; // COMPLIANT
1718

1819
unsigned long ul;
19-
ul << 10; // COMPLIANT
20+
ul << 8; // COMPLIANT
2021
ul << 64; // NON_COMPLIANT
2122

22-
// 1UL essential type is essentially unsigned long
23-
1UL << 10; // COMPLIANT[FALSE_POSITIVE]
24-
1UL << 64; // NON_COMPLIANT
23+
// 1UL essential type is essentially unsigned char
24+
1UL << 7; // COMPLIANT
25+
1UL << 8; // NON_COMPLIANT
26+
1UL << 64; // NON_COMPLIANT
27+
28+
// ULONG_MAX essential type is essentially unsigned long
29+
ULONG_MAX << 8; // COMPLIANT
30+
ULONG_MAX << 64; // NON_COMPLIANT
2531
}

0 commit comments

Comments
 (0)