Skip to content

Commit 53f6f6c

Browse files
committed
Apply review comments externallinkagearraywithoutexplicitsize
1 parent 179e8b7 commit 53f6f6c

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

cpp/common/src/codingstandards/cpp/rules/externallinkagearraywithoutexplicitsize/ExternalLinkageArrayWithoutExplicitSize.qll

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/**
22
* Provides a library with a `problems` predicate for the following issue:
3-
* Introducing a function or object with external linkage outside of a header file can
4-
* cause developer confusion about its translation unit access semantics.
3+
* Declaring an array with external linkage without its size being explicitly specified can disallow consistency and range checks on the array size and usage.
54
*/
65

76
import cpp
@@ -21,9 +20,9 @@ query predicate problems(DeclarationEntry declEntry, string message) {
2120
"' with external linkage doesn't specify the size explicitly." and
2221
hasExternalLinkage(v) and
2322
not arrayType.hasArraySize() and
24-
// Holds is if declEntry is an array variable declaration (not a definition)
23+
// Holds if declEntry is an array variable declaration (not a definition)
2524
v.getADeclarationEntry() = declEntry and
2625
not declEntry.isDefinition() and
27-
arrayType = v.getType().stripTopLevelSpecifiers()
26+
arrayType = declEntry.getType().stripTopLevelSpecifiers()
2827
)
2928
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
| test.cpp:19:14:19:15 | declaration of e1 | The declared array 'e1' with external linkage doesn't specify the size explicitly. |
2+
| test.hpp:2:13:2:26 | declaration of header_and_cpp | The declared array 'header_and_cpp' with external linkage doesn't specify the size explicitly. |

cpp/common/test/rules/externallinkagearraywithoutexplicitsize/test.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ struct s {
2424
int foo;
2525

2626
// static data members have external linkage - but not currently detected in
27-
// our external linkage lib - also FAMs are not in scope for this rule
28-
static const int flexibleArrayMember[]; // COMPLIANT
29-
};
27+
// our external linkage lib - also FAMs are expected to be detected
28+
// specifically in RULE-18-7
29+
static const int flexibleArrayMember[]; // NON_COMPLIANT[FALSE_NEGATIVE]
30+
static int flexibleArrayMember2[]; // NON_COMPLIANT[FALSE_NEGATIVE]
31+
};
32+
33+
// test.cpp
34+
#include "test.hpp"
35+
// definition associated with a declaration from test.hpp
36+
int header_and_cpp[1] = {1};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// test.hpp
2+
extern int header_and_cpp[]; // NON_COMPLIANT

0 commit comments

Comments
 (0)