File tree Expand file tree Collapse file tree 1 file changed +17
-6
lines changed
c/misra/test/rules/RULE-21-13 Expand file tree Collapse file tree 1 file changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -5,22 +5,33 @@ void sample() {
5
5
unsigned char c1 = 'c' ;
6
6
int r1 = isalnum (
7
7
c1 ); // COMPLIANT: ASCII 99 is within unsigned char range of [0, 255]
8
- unsigned char x1 = EOF ;
9
- unsigned char x2 = x1 ;
10
- unsigned char c2 = x2 ;
11
- int r2 = isdigit (c2 ); // COMPLIANT: EOF (-1)
8
+ int r2 = isdigit (EOF ); // COMPLIANT: EOF (-1)
12
9
13
10
int x3 = 256 ;
14
11
int x4 = x3 ;
15
12
int c3 = x4 ;
16
13
int r3 =
17
- islower (c3 ); // NON_COMPLIANT: is outside unsigned char range of[0, 255]
14
+ islower (c3 ); // NON_COMPLIANT: is outside unsigned char range of [0, 255]
18
15
19
16
unsigned char x5 = EOF ;
20
17
unsigned char x6 = x5 ;
21
18
int c4 = x6 + 10000 ;
22
19
int r4 =
23
- isdigit (c4 ); // NON_COMPLIANT: is outside unsigned char range of[0, 255]
20
+ isdigit (c4 ); // NON_COMPLIANT: is outside unsigned char range of [0, 255]
21
+
22
+ int c5 = getchar ();
23
+ int r5 = isdigit (c5 ); // COMPLIANT[FALSE_POSITIVE]: library functions like
24
+ // getchar needs to be modelled
25
+
26
+ unsigned char x7 = 1 ;
27
+ char c6 ;
28
+ if (x7 == 1 ) {
29
+ c6 = EOF ;
30
+ } else {
31
+ c6 = 'c' ;
32
+ }
33
+ int r6 =
34
+ isdigit (c6 ); // COMPLIANT: either control branch make this call compliant.
24
35
}
25
36
26
37
int main () { return 0 ; }
You can’t perform that action at this time.
0 commit comments