@@ -8,10 +8,6 @@ void sample1() {
8
8
// don't care about the qualifiers
9
9
char * s3 = "string" ; // NON_COMPLIANT: char* variable declared to hold a
10
10
// string literal
11
- s3 = "string" ; // NON_COMPLIANT: string literal assigned to a char* variable
12
- s2 = s3 ; // COMPLIANT: string literal (rvalue) assigned to a char* variable
13
- s3 =
14
- s2 ; // NON_COMPLIANT: string literal (rvalue) assigned to a char* variable
15
11
}
16
12
17
13
const char * sample2 (int x ) {
@@ -30,39 +26,14 @@ char *sample3(int x) {
30
26
return NULL ;
31
27
}
32
28
33
- const char * sample4 (int x ) {
34
- const char * result ;
35
- if (x == 1 )
36
- result = "string" ; // COMPLIANT: string literal assigned to a const char*
37
- // variable
38
- else
39
- result = NULL ;
40
-
41
- return result ; // COMPLIANT: `result` can be a string literal with return type
42
- // being const char*
43
- }
44
-
45
- char * sample5 (int x ) {
46
- const char * result ;
47
- if (x == 1 )
48
- result = "string" ; // COMPLIANT: string literal assigned to a const char*
49
- // variable
50
- else
51
- result = NULL ;
52
-
53
- return result ; // NON_COMPLIANT: `result` can be a string literal with return
54
- // type being char*
55
- }
56
- void sample6 (char * string ) {}
29
+ void sample4 (char * string ) {}
57
30
58
- void sample7 (const char * string ) {}
31
+ void sample5 (const char * string ) {}
59
32
60
33
void call45 () {
61
34
const char * literal = "string" ;
62
- sample6 (literal ); // NON_COMPLIANT: can't pass string literal to char*
63
- sample6 ("string" ); // NON_COMPLIANT: can't pass string literal to char*
64
- sample7 (literal ); // COMPLIANT: passing string literal to const char*
65
- sample7 ("string" ); // COMPLIANT: passing string literal to const char*
35
+ sample4 ("string" ); // NON_COMPLIANT: can't pass string literal to char*
36
+ sample5 ("string" ); // COMPLIANT: passing string literal to const char*
66
37
}
67
38
68
39
int main () { return 0 ; }
0 commit comments