Skip to content

Commit e29bf8c

Browse files
committed
Merge branch 'main' into html_safe
2 parents 8a3e255 + 6208071 commit e29bf8c

File tree

612 files changed

+3518
-3609
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

612 files changed

+3518
-3609
lines changed

cpp/ql/src/Best Practices/Unused Entities/UnusedStaticFunctions.ql

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,32 @@
1313

1414
import cpp
1515

16+
pragma[noinline]
17+
predicate possiblyIncompleteFile(File f) {
18+
exists(Diagnostic d | d.getFile() = f and d.getSeverity() >= 3)
19+
}
20+
1621
predicate immediatelyReachableFunction(Function f) {
17-
not f.isStatic() or
18-
exists(BlockExpr be | be.getFunction() = f) or
19-
f instanceof MemberFunction or
20-
f instanceof TemplateFunction or
21-
f.getFile() instanceof HeaderFile or
22-
f.getAnAttribute().hasName("constructor") or
23-
f.getAnAttribute().hasName("destructor") or
24-
f.getAnAttribute().hasName("used") or
22+
not f.isStatic()
23+
or
24+
exists(BlockExpr be | be.getFunction() = f)
25+
or
26+
f instanceof MemberFunction
27+
or
28+
f instanceof TemplateFunction
29+
or
30+
f.getFile() instanceof HeaderFile
31+
or
32+
f.getAnAttribute().hasName("constructor")
33+
or
34+
f.getAnAttribute().hasName("destructor")
35+
or
36+
f.getAnAttribute().hasName("used")
37+
or
2538
f.getAnAttribute().hasName("unused")
39+
or
40+
// a compiler error in the same file suggests we may be missing data
41+
possiblyIncompleteFile(f.getFile())
2642
}
2743

2844
predicate immediatelyReachableVariable(Variable v) {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Fixed false positives from the "Unused static function" (`cpp/unused-static-function`) query in files that had errors during compilation.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// semmle-extractor-options: --expect_errors
2+
3+
static void my_function1_called() {} // GOOD
4+
static void my_function2_called_after_error() {} // GOOD
5+
static void my_function3_not_called() {} // BAD [NOT DETECTED]
6+
7+
int main(void) {
8+
my_function1_called();
9+
10+
--- compilation stops here because this line is not valid C code ---
11+
12+
my_function2_called_after_error();
13+
14+
return 0;
15+
}

cpp/ql/test/query-tests/Best Practices/Unused Entities/UnusedStaticFunctions/unused_static_functions.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,16 @@ static void f6(void);
3333
static void f5(void) { f6(); }
3434
static void f6(void) { f5(); }
3535

36+
// f7 and f8 are reachable from `function_caller`
37+
static int f7() { return 1; } // GOOD
38+
static void f8() { } // GOOD
39+
40+
void function_caller()
41+
{
42+
auto my_lambda = []() {
43+
return f7();
44+
}();
45+
46+
f8();
47+
}
48+

docs/codeql/support/reusables/frameworks.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,4 +260,16 @@ and the CodeQL library pack ``codeql/ruby-all`` (`changelog <https://github.com/
260260
:widths: auto
261261

262262
Name, Category
263+
excon, HTTP client
264+
faraday, HTTP client
265+
http_client, HTTP client
266+
httparty, HTTP client
267+
libxml-ruby, XML processing library
268+
nokogiri, XML processing library
269+
open-uri, HTTP client
270+
posix-spawn, Utility library
271+
rest-client, HTTP client
263272
Ruby on Rails, Web framework
273+
rubyzip, Compression library
274+
typhoeus, HTTP client
275+

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 85 additions & 71 deletions
Large diffs are not rendered by default.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
test.kt:
2+
# 0| [CompilationUnit] test
3+
# 1| 1: [Interface] Ann
4+
# 1| 1: [Constructor] Ann
5+
#-----| 4: (Parameters)
6+
# 1| 0: [Parameter] arr1
7+
# 1| 0: [TypeAccess] String[]
8+
# 1| 0: [TypeAccess] String
9+
# 1| 1: [Parameter] arr2
10+
# 1| 0: [TypeAccess] int[]
11+
# 1| 5: [BlockStmt] { ... }
12+
# 1| 0: [SuperConstructorInvocationStmt] super(...)
13+
# 1| 1: [BlockStmt] { ... }
14+
# 1| 0: [ExprStmt] <Expr>;
15+
# 1| 0: [KtInitializerAssignExpr] ...=...
16+
# 1| 0: [VarAccess] arr1
17+
# 1| 1: [ExprStmt] <Expr>;
18+
# 1| 0: [KtInitializerAssignExpr] ...=...
19+
# 1| 0: [VarAccess] arr2
20+
# 1| 2: [Constructor] Ann
21+
#-----| 4: (Parameters)
22+
# 1| 0: [Parameter] p0
23+
# 1| 0: [TypeAccess] String[]
24+
# 1| 1: [Parameter] p1
25+
# 1| 0: [TypeAccess] int[]
26+
# 1| 2: [Parameter] p2
27+
# 1| 0: [TypeAccess] int
28+
# 1| 3: [Parameter] p3
29+
# 1| 0: [TypeAccess] DefaultConstructorMarker
30+
# 1| 5: [BlockStmt] { ... }
31+
# 1| 0: [IfStmt] if (...)
32+
# 1| 0: [EQExpr] ... == ...
33+
# 1| 0: [AndBitwiseExpr] ... & ...
34+
# 1| 0: [IntegerLiteral] 1
35+
# 1| 1: [VarAccess] p2
36+
# 1| 1: [IntegerLiteral] 0
37+
# 1| 1: [ExprStmt] <Expr>;
38+
# 1| 0: [AssignExpr] ...=...
39+
# 1| 0: [VarAccess] p0
40+
# 0| 1: [ArrayCreationExpr] new String[]
41+
# 0| -2: [ArrayInit] {...}
42+
# 0| 0: [StringLiteral] hello
43+
# 0| 1: [StringLiteral] world
44+
# 0| -1: [TypeAccess] String
45+
# 0| 0: [IntegerLiteral] 2
46+
# 1| 1: [IfStmt] if (...)
47+
# 1| 0: [EQExpr] ... == ...
48+
# 1| 0: [AndBitwiseExpr] ... & ...
49+
# 1| 0: [IntegerLiteral] 2
50+
# 1| 1: [VarAccess] p2
51+
# 1| 1: [IntegerLiteral] 0
52+
# 1| 1: [ExprStmt] <Expr>;
53+
# 1| 0: [AssignExpr] ...=...
54+
# 1| 0: [VarAccess] p1
55+
# 0| 1: [ArrayCreationExpr] new int[]
56+
# 0| -2: [ArrayInit] {...}
57+
# 0| 0: [IntegerLiteral] 1
58+
# 0| 1: [IntegerLiteral] 2
59+
# 0| 2: [IntegerLiteral] 3
60+
# 0| -1: [TypeAccess] int
61+
# 0| 0: [IntegerLiteral] 3
62+
# 1| 2: [ThisConstructorInvocationStmt] this(...)
63+
# 1| 0: [VarAccess] p0
64+
# 1| 1: [VarAccess] p1
65+
# 1| 3: [FieldDeclaration] String[] arr1;
66+
# 1| -1: [TypeAccess] String[]
67+
# 1| 0: [TypeAccess] String
68+
# 1| 0: [VarAccess] arr1
69+
# 1| 4: [Method] arr1
70+
# 1| 3: [TypeAccess] String[]
71+
# 1| 0: [TypeAccess] String
72+
# 1| 5: [BlockStmt] { ... }
73+
# 1| 0: [ReturnStmt] return ...
74+
# 1| 0: [VarAccess] this.arr1
75+
# 1| -1: [ThisAccess] this
76+
# 1| 5: [Method] arr2
77+
# 1| 3: [TypeAccess] int[]
78+
# 1| 5: [BlockStmt] { ... }
79+
# 1| 0: [ReturnStmt] return ...
80+
# 1| 0: [VarAccess] this.arr2
81+
# 1| -1: [ThisAccess] this
82+
# 1| 6: [FieldDeclaration] int[] arr2;
83+
# 1| -1: [TypeAccess] int[]
84+
# 1| 0: [VarAccess] arr2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle/code/java/PrintAst.ql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
annotation class Ann(val arr1: Array<String> = ["hello", "world"], val arr2: IntArray = [1, 2, 3]) { }

java/ql/test/kotlin/library-tests/methods/methods.expected

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
methods
2-
| clinit.kt:0:0:0:0 | ClinitKt | clinit.kt:0:0:0:0 | <clinit> | <clinit>() | | Compiler generated |
2+
| clinit.kt:0:0:0:0 | ClinitKt | clinit.kt:0:0:0:0 | <clinit> | <clinit>() | static | Compiler generated |
33
| clinit.kt:0:0:0:0 | ClinitKt | clinit.kt:3:1:3:24 | getTopLevelInt | getTopLevelInt() | public, static | Compiler generated |
44
| clinit.kt:0:0:0:0 | ClinitKt | clinit.kt:3:1:3:24 | setTopLevelInt | setTopLevelInt(int) | public, static | Compiler generated |
55
| dataClass.kt:1:1:1:47 | DataClass | dataClass.kt:0:0:0:0 | component1 | component1() | public | Compiler generated |
@@ -25,11 +25,11 @@ methods
2525
| delegates.kt:8:32:11:5 | new KMutableProperty1<MyClass,String>(...) { ... } | delegates.kt:8:32:11:5 | set | set(MyClass,java.lang.String) | override, public | |
2626
| delegates.kt:8:32:11:5 | new KMutableProperty1<MyClass,String>(...) { ... } | delegates.kt:8:32:11:5 | set | set(MyClass,java.lang.String) | override, public | |
2727
| delegates.kt:8:66:11:5 | new Function3<KProperty<?>,String,String,Unit>(...) { ... } | delegates.kt:8:66:11:5 | invoke | invoke(kotlin.reflect.KProperty,java.lang.String,java.lang.String) | override, public | |
28-
| enumClass.kt:1:1:4:1 | EnumClass | enumClass.kt:0:0:0:0 | <clinit> | <clinit>() | | Compiler generated |
28+
| enumClass.kt:1:1:4:1 | EnumClass | enumClass.kt:0:0:0:0 | <clinit> | <clinit>() | static | Compiler generated |
2929
| enumClass.kt:1:1:4:1 | EnumClass | enumClass.kt:0:0:0:0 | valueOf | valueOf(java.lang.String) | public, static | Compiler generated |
3030
| enumClass.kt:1:1:4:1 | EnumClass | enumClass.kt:0:0:0:0 | values | values() | public, static | Compiler generated |
3131
| enumClass.kt:1:1:4:1 | EnumClass | enumClass.kt:1:22:1:31 | getV | getV() | public | Compiler generated |
32-
| enumClass.kt:6:1:16:1 | EnumWithFunctions | enumClass.kt:0:0:0:0 | <clinit> | <clinit>() | | Compiler generated |
32+
| enumClass.kt:6:1:16:1 | EnumWithFunctions | enumClass.kt:0:0:0:0 | <clinit> | <clinit>() | static | Compiler generated |
3333
| enumClass.kt:6:1:16:1 | EnumWithFunctions | enumClass.kt:0:0:0:0 | valueOf | valueOf(java.lang.String) | public, static | Compiler generated |
3434
| enumClass.kt:6:1:16:1 | EnumWithFunctions | enumClass.kt:0:0:0:0 | values | values() | public, static | Compiler generated |
3535
| enumClass.kt:6:1:16:1 | EnumWithFunctions | enumClass.kt:13:12:13:29 | f | f(int) | public | |

0 commit comments

Comments
 (0)