Skip to content

Commit 20db94f

Browse files
author
Nikita Kraiouchkine
committed
Fix RULE-9-4 bug, update test and metadata
1 parent 321a1e9 commit 20db94f

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

c/misra/src/rules/RULE-9-4/RepeatedInitializationOfAggregateObjectElement.ql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ string getNestedArrayIndexString(Expr e) {
4343
|
4444
elementIndex
4545
).toString() + "]"
46+
order by
47+
depth desc
4648
)
4749
}
4850

@@ -95,8 +97,7 @@ predicate hasMultipleInitializerExprsForSameIndex(ArrayAggregateLiteral root, Ex
9597
* that initialize the same Field and are part of the same `ClassAggregateLiteral`.
9698
* This predicate is therefore unable to distinguish the individual duplicate expressions.
9799
*/
98-
predicate hasMultipleInitializerExprsForSameField(ClassAggregateLiteral root, Expr expr, Field f) {
99-
expr = root.getFieldExpr(f) and
100+
predicate hasMultipleInitializerExprsForSameField(ClassAggregateLiteral root, Field f) {
100101
count(root.getFieldExpr(f)) > 1
101102
}
102103

@@ -116,7 +117,7 @@ where
116117
// we cannot distinguish between different aggregate field init expressions.
117118
// therefore, we only report the root aggregate rather than any child init expr.
118119
// see `hasMultipleInitializerExprsForSameField` documentation.
119-
hasMultipleInitializerExprsForSameField(root, _, f) and
120+
hasMultipleInitializerExprsForSameField(root, f) and
120121
e1 = root and
121122
e2 = root and
122123
elementDescription = f.getQualifiedName() and
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
| test.c:10:16:10:16 | 1 | $@ repeats initialization of element [0], which is already initialized $@. | test.c:9:14:10:26 | {...} | Array aggregate literal | test.c:10:7:10:7 | 0 | here |
22
| test.c:12:28:12:28 | 1 | $@ repeats initialization of element [0][0], which is already initialized $@. | test.c:12:17:16:29 | {...} | Array aggregate literal | test.c:16:28:16:28 | 1 | here |
3-
| test.c:24:34:24:34 | 1 | $@ repeats initialization of element [0][0][0], which is already initialized $@. | test.c:24:20:26:35 | {...} | Array aggregate literal | test.c:26:34:26:34 | 1 | here |
3+
| test.c:25:64:25:64 | 7 | $@ repeats initialization of element [1][1][0], which is already initialized $@. | test.c:24:20:26:35 | {...} | Array aggregate literal | test.c:26:34:26:34 | 1 | here |
44
| test.c:36:17:37:25 | {...} | $@ repeats initialization of element s1::a. | test.c:36:17:37:25 | {...} | Structure aggregate literal | test.c:36:17:37:25 | {...} | here |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void test_arrays(void) {
2323

2424
int a7[2][2][2] = {[0][0][0] = 1, [0][0][1] = 2, [0][1][0] = 3, [0][1][1] = 4,
2525
[1][0][0] = 5, [1][0][1] = 6, [1][1][0] = 7, [1][1][1] = 8,
26-
[0][0][0] = 1}; // NON_COMPLIANT
26+
[1][1][0] = 1}; // NON_COMPLIANT
2727
// - repeated
2828
// initialiation
2929
// of [0][0][0]

rule_packages/c/Memory1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"kind": "problem",
1111
"name": "The initializer for an aggregate or union shall be enclosed in braces",
1212
"precision": "high",
13-
"severity": "warning",
13+
"severity": "recommendation",
1414
"short_name": "InitializerForAggregateOrUnionNotEnclosedInBraces",
1515
"shared_implementation_short_name": "UseInitializerBracesToMatchAggregateTypeStructure",
1616
"tags": [

0 commit comments

Comments
 (0)