Skip to content

Commit 7982e0b

Browse files
authored
Merge pull request #686 from github/lcartey/rule-5-8-no-linkage
RULE-5-8: Only consider declarations conflicting if they occur in the same link target
2 parents 015872e + ec2a13c commit 7982e0b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

c/misra/src/rules/RULE-5-8/IdentifiersWithExternalLinkageNotUnique.ql

+19-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,25 @@ class NotUniqueExternalIdentifier extends ExternalIdentifiers {
4141

4242
Declaration getAConflictingDeclaration() {
4343
not result = this and
44-
isConflictingDeclaration(result, getName())
44+
isConflictingDeclaration(result, getName()) and
45+
// We only consider a declaration to be conflicting if it shares a link target with the external
46+
// identifier. This avoids reporting false positives where multiple binaries or libraries are
47+
// built in the same CodeQL database, but are not intended to be linked together.
48+
exists(LinkTarget lt |
49+
// External declaration can only be a function or global variable
50+
lt = this.(Function).getALinkTarget() or
51+
lt = this.(GlobalVariable).getALinkTarget()
52+
|
53+
lt = result.(Function).getALinkTarget()
54+
or
55+
lt = result.(GlobalVariable).getALinkTarget()
56+
or
57+
exists(Class c | c.getAMember() = result and c.getALinkTarget() = lt)
58+
or
59+
result.(LocalVariable).getFunction().getALinkTarget() = lt
60+
or
61+
result.(Class).getALinkTarget() = lt
62+
)
4563
}
4664
}
4765

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `RULE-5-8` - `IdentifiersWithExternalLinkageNotUnique.ql`
2+
- Remove false positives where conflicting declarations do not appear in the same link target.

0 commit comments

Comments
 (0)