Skip to content

Commit 4c6c550

Browse files
committed
4-8
1 parent 63d6bbd commit 4c6c550

File tree

9 files changed

+141
-4
lines changed

9 files changed

+141
-4
lines changed

c/misra/src/rules/RULE-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.ql renamed to c/misra/src/rules/DIR-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/**
22
* @id c/misra/object-with-no-pointer-dereference-should-be-opaque
3-
* @name RULE-4-8: The implementation of an object shall be hidden if a pointer to its structure or union is never dereferenced within a translation unit
3+
* @name DIR-4-8: The implementation of an object shall be hidden if a pointer to its structure or union is never dereferenced within a translation unit
44
* @description If a pointer to a structure or union is never dereferenced within a translation
55
* unit, then the implementation of the object should be hidden to prevent
66
* unintentional changes.
77
* @kind problem
88
* @precision very-high
99
* @problem.severity error
10-
* @tags external/misra/id/rule-4-8
10+
* @tags external/misra/id/dir-4-8
1111
* readability
1212
* maintainability
1313
* external/misra/obligation/advisory
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
| test.c:10:8:10:9 | s4 | $@ is not opaque but no pointer to it is dereferenced within the translation unit $@. | test.c:10:8:10:9 | s4 | s4 | test.c:0:0:0:0 | test.c | test.c |
2+
| test.h:3:8:3:9 | s1 | $@ is not opaque but no pointer to it is dereferenced within the translation unit $@. | test.h:3:8:3:9 | s1 | s1 | test.c:0:0:0:0 | test.c | test.c |
3+
| test_2.c:7:8:7:9 | s2 | $@ is not opaque but no pointer to it is dereferenced within the translation unit $@. | test_2.c:7:8:7:9 | s2 | s2 | test_2.c:0:0:0:0 | test_2.c | test_2.c |
4+
| test_shared.h:15:8:15:20 | only_test2_s2 | $@ is not opaque but no pointer to it is dereferenced within the translation unit $@. | test_shared.h:15:8:15:20 | only_test2_s2 | only_test2_s2 | test_2.c:0:0:0:0 | test_2.c | test_2.c |
5+
| test_shared.h:19:7:19:15 | shared_u1 | $@ is not opaque but no pointer to it is dereferenced within the translation unit $@. | test_shared.h:19:7:19:15 | shared_u1 | shared_u1 | test.c:0:0:0:0 | test.c | test.c |
6+
| test_shared.h:19:7:19:15 | shared_u1 | $@ is not opaque but no pointer to it is dereferenced within the translation unit $@. | test_shared.h:19:7:19:15 | shared_u1 | shared_u1 | test_2.c:0:0:0:0 | test_2.c | test_2.c |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/RULE-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.ql

c/misra/test/rules/DIR-4-8/test.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "test.h"
2+
#include "test_shared.h"
3+
struct s3 {
4+
int v1;
5+
struct s3_1 {
6+
int a;
7+
} v2; // COMPLIANT
8+
}; // COMPLIANT
9+
10+
struct s4 {
11+
int v1;
12+
}; // NON_COMPLIANT
13+
14+
typedef struct s3 s3_t;
15+
typedef struct s4 s4_t;
16+
17+
void *f1(struct s1 *p1) { return (void *)p1; }
18+
19+
void *f2(struct s2 *p1) {
20+
int v1 = p1->v1;
21+
return p1;
22+
}
23+
24+
s3_t *f3(s3_t *p1) {
25+
int v1 = p1[0].v1;
26+
return p1;
27+
}
28+
29+
void *f4(s4_t *p1) { return p1; }
30+
31+
void *f5(struct only_test1_s1 *p1) {
32+
int v1 = p1->v1;
33+
return (void *)p1;
34+
}
35+
36+
void *f6(struct shared_s1 *p1) {
37+
int v1 = p1->v1;
38+
return (void *)p1;
39+
}
40+
41+
void *f7(union shared_u1 *p1) { return (void *)p1; }
42+
43+
void *f8(union shared_u2 *p1) {
44+
int v1 = p1->v1;
45+
return (void *)p1;
46+
}

c/misra/test/rules/DIR-4-8/test.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef TEST_H_
2+
#define TEST_H_
3+
struct s1 {
4+
int v1;
5+
}; // NON_COMPLIANT
6+
7+
struct s2 {
8+
int v1;
9+
}; // COMPLIANT
10+
#endif // TEST_H_

c/misra/test/rules/DIR-4-8/test_2.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "test_shared.h"
2+
3+
struct s1 {
4+
float v1;
5+
}; // COMPLIANT
6+
7+
struct s2 {
8+
float v1;
9+
}; // NON_COMPLIANT
10+
11+
struct s3 {
12+
float v1;
13+
}; // COMPLIANT
14+
15+
void *f1(struct s1 *p1) {
16+
int v1 = p1->v1;
17+
return (void *)p1;
18+
}
19+
20+
void *f2(struct s2 *p1) { return (void *)p1; }
21+
22+
void *f3(struct only_test2_s1 *p1) {
23+
int v1 = (*p1).v1;
24+
return (void *)p1;
25+
}
26+
27+
void *f4(struct only_test2_s1 *p1) {
28+
int v1 = p1->v1;
29+
return (void *)p1;
30+
}
31+
32+
void *f5(struct only_test2_s2 *p1) { return (void *)p1; }
33+
34+
void *f6(union shared_u1 *p1) { return (void *)p1; }
35+
36+
void *f7(union shared_u2 *p1) {
37+
int v1 = p1->v1;
38+
return (void *)p1;
39+
}
40+
41+
void *f8(void) {
42+
struct s3 v1;
43+
return (void *)0;
44+
}
45+
46+
void *f9(struct s3 *p1) { return (void *)p1; }
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef TEST_SHARED_H_
2+
#define TEST_SHARED_H_
3+
struct shared_s1 {
4+
int v1;
5+
}; // COMPLIANT
6+
7+
struct only_test1_s1 {
8+
int v1;
9+
}; // COMPLIANT
10+
11+
struct only_test2_s1 {
12+
int v1;
13+
}; // COMPLIANT
14+
15+
struct only_test2_s2 {
16+
int v1;
17+
}; // NON_COMPLIANT
18+
19+
union shared_u1 {
20+
int v1;
21+
float v2;
22+
}; // NON_COMPLIANT
23+
24+
union shared_u2 {
25+
int v1;
26+
float v2;
27+
}; // COMPLIANT
28+
#endif // TEST_SHARED_H_

cpp/common/src/codingstandards/cpp/exclusions/c/Pointers1.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ predicate isPointers1QueryMetadata(Query query, string queryId, string ruleId) {
149149
queryId =
150150
// `@id` for the `objectWithNoPointerDereferenceShouldBeOpaque` query
151151
"c/misra/object-with-no-pointer-dereference-should-be-opaque" and
152-
ruleId = "RULE-4-8"
152+
ruleId = "DIR-4-8"
153153
or
154154
query =
155155
// `Query` instance for the `pointerShouldPointToConstTypeWhenPossible` query

rule_packages/c/Pointers1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@
294294
],
295295
"title": "The address of an object with automatic storage shall not be copied to another object that persists after the first object has ceased to exist"
296296
},
297-
"RULE-4-8": {
297+
"DIR-4-8": {
298298
"properties": {
299299
"obligation": "advisory"
300300
},

0 commit comments

Comments
 (0)