Skip to content

Commit e140430

Browse files
Merge pull request #1029 from github/jeongsoolee09/MISRA-C++-Memory4
Add `Memory4` package
2 parents b9f6fed + fababd8 commit e140430

File tree

40 files changed

+461
-166
lines changed

40 files changed

+461
-166
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| test.c:36:3:36:18 | ... = ... | An object $@ assigned to overlapping object $@. | test.c:36:9:36:10 | m2 | m2 | test.c:36:17:36:18 | m1 | m1 |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// GENERATED FILE - DO NOT MODIFY
2+
import codingstandards.cpp.rules.objectassignedtoanoverlappingobject.ObjectAssignedToAnOverlappingObject
3+
4+
class TestFileQuery extends ObjectAssignedToAnOverlappingObjectSharedQuery, TestQuery { }
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
struct s1 {
2+
int m1[10];
3+
};
4+
struct s2 {
5+
int m1;
6+
struct s1 m2;
7+
};
8+
9+
union u {
10+
struct s1 m1;
11+
struct s2 m2;
12+
};
13+
14+
typedef struct {
15+
char buf[8];
16+
} Union_t;
17+
18+
typedef union {
19+
20+
unsigned char uc[24];
21+
22+
struct {
23+
Union_t prefix;
24+
Union_t suffix;
25+
} fnv;
26+
27+
struct {
28+
unsigned char padding[16];
29+
Union_t suffix;
30+
} diff;
31+
32+
} UnionSecret_t;
33+
34+
void overlapping_access() {
35+
union u u1;
36+
u1.m2.m2 = u1.m1; // NON_COMPLIANT, different struct. u1.m2 and u1.m1
37+
}
38+
39+
void cross_copy() {
40+
UnionSecret_t hash1;
41+
hash1.diff.suffix =
42+
hash1.fnv.suffix; // COMPLIANT (copy across structs), but safe.
43+
}
44+
45+
void internal_shift() {
46+
UnionSecret_t hash1;
47+
hash1.fnv.prefix = hash1.fnv.suffix; // COMPLIANT, same struct.
48+
}
49+
50+
void separate_access() {
51+
UnionSecret_t hash1, hash2;
52+
hash2.diff.suffix = hash1.fnv.suffix; // COMPLIANT, different union.
53+
}

c/misra/test/rules/RULE-19-1/ObjectCopiedToAnOverlappingObject.expected renamed to c/common/test/rules/objectcopiedtoanoverlappingobject/ObjectCopiedToAnOverlappingObject.expected

File renamed without changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// GENERATED FILE - DO NOT MODIFY
2+
import codingstandards.cpp.rules.objectcopiedtoanoverlappingobject.ObjectCopiedToAnOverlappingObject
3+
4+
class TestFileQuery extends ObjectCopiedToAnOverlappingObjectSharedQuery, TestQuery { }

c/misra/test/rules/RULE-19-1/test.c renamed to c/common/test/rules/objectcopiedtoanoverlappingobject/test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ void test_unions() {
5656

5757
memcpy(&u1.m2.m2, &u1.m1, sizeof(u1.m1)); // NON_COMPLIANT
5858
memcpy(&u2.diff.suffix, &u2.fnv.suffix, sizeof(u2.fnv.suffix)); // COMPLIANT
59-
}
59+
}

c/misra/src/rules/RULE-19-1/ObjectAssignedToAnOverlappingObject.ql

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @id c/misra/object-assigned-to-an-overlapping-object-misra-c
3+
* @name RULE-19-1: An object shall not be assigned to an overlapping object
4+
* @description An object shall not be copied or assigned to an overlapping object.
5+
* @kind problem
6+
* @precision high
7+
* @problem.severity error
8+
* @tags external/misra/id/rule-19-1
9+
* correctness
10+
* external/misra/c/2012/third-edition-first-revision
11+
* external/misra/obligation/mandatory
12+
*/
13+
14+
import cpp
15+
import codingstandards.c.misra
16+
import codingstandards.cpp.rules.objectassignedtoanoverlappingobject.ObjectAssignedToAnOverlappingObject
17+
18+
class ObjectAssignedToAnOverlappingObjectMisraCQuery extends ObjectAssignedToAnOverlappingObjectSharedQuery
19+
{
20+
ObjectAssignedToAnOverlappingObjectMisraCQuery() {
21+
this = Contracts7Package::objectAssignedToAnOverlappingObjectMisraCQuery()
22+
}
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @id c/misra/object-copied-to-an-overlapping-object-misra-c
3+
* @name RULE-19-1: An object shall not be copied to an overlapping object
4+
* @description An object shall not be copied to an overlapping object.
5+
* @kind problem
6+
* @precision high
7+
* @problem.severity error
8+
* @tags external/misra/id/rule-19-1
9+
* correctness
10+
* external/misra/c/2012/third-edition-first-revision
11+
* external/misra/obligation/mandatory
12+
*/
13+
14+
import cpp
15+
import codingstandards.c.misra
16+
import codingstandards.cpp.rules.objectcopiedtoanoverlappingobject.ObjectCopiedToAnOverlappingObject
17+
18+
class ObjectCopiedToAnOverlappingObjectMisraCQuery extends ObjectCopiedToAnOverlappingObjectSharedQuery
19+
{
20+
ObjectCopiedToAnOverlappingObjectMisraCQuery() {
21+
this = Contracts7Package::objectCopiedToAnOverlappingObjectMisraCQuery()
22+
}
23+
}

c/misra/test/rules/RULE-19-1/ObjectAssignedToAnOverlappingObject.expected

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)