Skip to content

Commit 2ebcf85

Browse files
committed
Slim down test.c for 7-4
1 parent 14350d0 commit 2ebcf85

File tree

1 file changed

+4
-33
lines changed
  • c/misra/test/rules/RULE-7-4

1 file changed

+4
-33
lines changed

c/misra/test/rules/RULE-7-4/test.c

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ void sample1() {
88
// don't care about the qualifiers
99
char *s3 = "string"; // NON_COMPLIANT: char* variable declared to hold a
1010
// 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
1511
}
1612

1713
const char *sample2(int x) {
@@ -30,39 +26,14 @@ char *sample3(int x) {
3026
return NULL;
3127
}
3228

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) {}
5730

58-
void sample7(const char *string) {}
31+
void sample5(const char *string) {}
5932

6033
void call45() {
6134
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*
6637
}
6738

6839
int main() { return 0; }

0 commit comments

Comments
 (0)