Skip to content

Commit 9193a81

Browse files
authored
Merge pull request #2534 from geoffw0/xml
C++: Fix characteristic predicate of `XMLParent`.
2 parents 45d0e59 + 0a1fa08 commit 9193a81

File tree

13 files changed

+28
-51
lines changed

13 files changed

+28
-51
lines changed

cpp/ql/src/semmle/code/cpp/XML.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ abstract class XMLLocatable extends @xmllocatable {
3131
* both of which can contain other elements.
3232
*/
3333
class XMLParent extends @xmlparent {
34+
XMLParent() {
35+
// explicitly restrict `this` to be either an `XMLElement` or an `XMLFile`;
36+
// the type `@xmlparent` currently also includes non-XML files
37+
this instanceof @xmlelement or xmlEncoding(this, _)
38+
}
39+
3440
/**
3541
* Gets a printable representation of this XML parent.
3642
* (Intended to be overridden in subclasses.)

cpp/ql/test/library-tests/files/FilePath.expected

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

cpp/ql/test/library-tests/files/FilePath.ql

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| c.c | library-tests/files/c.c | CFile, MetricFile | C | | |
2+
| files1.cpp | library-tests/files/files1.cpp | CppFile, MetricFile | C++ | swap | t |
3+
| files1.h | library-tests/files/files1.h | HeaderFile, MetricFile | | swap | |
4+
| files2.cpp | library-tests/files/files2.cpp | CppFile, MetricFile | C++ | g | x, y |
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import cpp
2+
3+
string describe(File f) {
4+
f.compiledAsC() and
5+
result = "C"
6+
or
7+
f.compiledAsCpp() and
8+
result = "C++"
9+
or
10+
f instanceof XMLParent and
11+
result = "XMLParent" // regression tests a bug in the characteristic predicate of XMLParent
12+
}
13+
14+
from File f
15+
where f.toString() != ""
16+
select f.toString(), f.getRelativePath(), concat(f.getAQlClass().toString(), ", "),
17+
concat(describe(f), ", "), concat(f.getATopLevelDeclaration().toString(), ", "),
18+
concat(LocalVariable v | f.getADeclaration() = v | v.toString(), ", ")

cpp/ql/test/library-tests/files/Files1.expected

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

cpp/ql/test/library-tests/files/Files1.ql

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

cpp/ql/test/library-tests/files/Files2.expected

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

cpp/ql/test/library-tests/files/Files2.ql

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

cpp/ql/test/library-tests/files/Files3.expected

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

0 commit comments

Comments
 (0)