Skip to content

Commit 39ef003

Browse files
Update to use features from codeql-qtil
1 parent b47ec45 commit 39ef003

File tree

6 files changed

+25
-155
lines changed

6 files changed

+25
-155
lines changed

cpp/common/src/codingstandards/cpp/util/CondensedList.qll

Lines changed: 0 additions & 105 deletions
This file was deleted.

cpp/common/src/codingstandards/cpp/util/Pair.qll

Lines changed: 0 additions & 21 deletions
This file was deleted.

cpp/misra/src/codeql-pack.lock.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
lockVersion: 1.0.0
33
dependencies:
4+
advanced-security/qtil:
5+
version: 0.0.1
46
codeql/cpp-all:
57
version: 2.1.1
68
codeql/dataflow:

cpp/misra/src/qlpack.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ license: MIT
66
dependencies:
77
codeql/common-cpp-coding-standards: '*'
88
codeql/cpp-all: 2.1.1
9+
advanced-security/qtil: 0.0.1

cpp/misra/src/rules/RULE-19-0-4/UndefOfMacroNotDefinedInFile.ql

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,15 @@
1616

1717
import cpp
1818
import codingstandards.cpp.misra
19-
import codingstandards.cpp.util.CondensedList
20-
import codingstandards.cpp.util.Pair
19+
import qtil.Qtil
2120

2221
class DefOrUndef extends PreprocessorDirective {
23-
string name;
22+
DefOrUndef() { this instanceof PreprocessorUndef or this instanceof Macro }
2423

25-
DefOrUndef() {
26-
name = this.(PreprocessorUndef).getName() or
27-
name = this.(Macro).getName()
24+
string getName() {
25+
result = this.(PreprocessorUndef).getName() or
26+
result = this.(Macro).getName()
2827
}
29-
30-
string getName() { result = name }
3128
}
3229

3330
predicate relevantNameAndFile(string name, File file) {
@@ -37,30 +34,24 @@ predicate relevantNameAndFile(string name, File file) {
3734
)
3835
}
3936

40-
class StringFilePair = Pair<string, File>::Where<relevantNameAndFile/2>::Pair;
41-
42-
module DefUndefListConfig implements CondensedListSig {
43-
class Division = StringFilePair;
37+
class StringFilePair = Qtil::Pair<string, File, relevantNameAndFile/2>::Pair;
4438

45-
class Item = DefOrUndef;
39+
/**
40+
* Defs and undefs ordered by location, grouped by name and file.
41+
*/
42+
class OrderedDefOrUndef extends Qtil::Ordered<DefOrUndef>::GroupBy<StringFilePair>::Type {
43+
override int getOrder() { result = getLocation().getStartLine() }
4644

47-
int getSparseIndex(StringFilePair division, DefOrUndef directive) {
48-
directive.getName() = division.getFirst() and
49-
directive.getFile() = division.getSecond() and
50-
result = directive.getLocation().getStartLine()
45+
override StringFilePair getGroup() {
46+
result.getFirst() = getName() and result.getSecond() = getFile()
5147
}
5248
}
5349

54-
class ListEntry = Condense<DefUndefListConfig>::ListEntry;
55-
56-
from PreprocessorUndef undef, ListEntry defUndefListEntry
50+
from OrderedDefOrUndef defOrUndef
5751
where
58-
not isExcluded(undef, PreprocessorPackage::undefOfMacroNotDefinedInFileQuery()) and
59-
// There exists a def or undef for a given name and file, and it is an #undef
60-
undef = defUndefListEntry.getItem() and
61-
// Exclude cases where the previous def or undef with the same name in the same file is a #define
62-
not exists(ListEntry prev |
63-
prev = defUndefListEntry.getPrev() and
64-
prev.getItem() instanceof Macro
65-
)
66-
select undef, "Undef of name '" + undef.getName() + "' not defined in the same file."
52+
not isExcluded(defOrUndef, PreprocessorPackage::undefOfMacroNotDefinedInFileQuery()) and
53+
// There exists an #undef for a given name and file
54+
defOrUndef instanceof PreprocessorUndef and
55+
// A previous def or undef of this name must exist in this file, and it must be a #define
56+
not defOrUndef.getPrevious() instanceof Macro
57+
select defOrUndef, "Undef of name '" + defOrUndef.getName() + "' not defined in the same file."

cpp/misra/test/codeql-pack.lock.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
lockVersion: 1.0.0
33
dependencies:
4+
advanced-security/qtil:
5+
version: 0.0.1
46
codeql/cpp-all:
57
version: 2.1.1
68
codeql/dataflow:

0 commit comments

Comments
 (0)