8000 Address review comments · github/codeql@7494eac · GitHub
[go: up one dir, main page]

Skip to content

Commit 7494eac

Browse files
committed
Address review comments
1 parent cd01bd0 commit 7494eac

File tree

3 files changed

+58
-57
lines changed

3 files changed

+58
-57
lines changed

rust/ql/lib/codeql/rust/elements/internal/LiteralExprImpl.qll

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ module Impl {
5353
* [1]: https://doc.rust-lang.org/reference/tokens.html#character-literals
5454
*/
5555
class CharLiteralExpr extends LiteralExpr {
56-
CharLiteralExpr() {
57-
// todo: proper implementation
58-
this.getTextValue().regexpMatch("'.*'")
59-
}
56+
CharLiteralExpr() { this.getTextValue().regexpMatch("'.*'") }
6057

6158
override string getAPrimaryQlClass() { result = "CharLiteralExpr" }
6259
}
@@ -71,10 +68,7 @@ module Impl {
7168
* [1]: https://doc.rust-lang.org/reference/tokens.html#string-literals
7269
*/
7370
class StringLiteralExpr extends LiteralExpr {
74-
StringLiteralExpr() {
75-
// todo: proper implementation
76-
this.getTextValue().regexpMatch("r?#*\".*\"#*")
77-
}
71+
StringLiteralExpr() { this.getTextValue().regexpMatch("r?#*\".*\"#*") }
7872

7973
override string getAPrimaryQlClass() { result = "StringLiteralExpr" }
8074
}
@@ -138,11 +132,10 @@ module Impl {
138132
* For example, `42u8` has the suffix `u8`.
139133
*/
140134
string getSuffix() {
141-
exists(string s, string reg, int last |
135+
exists(string s, string reg |
142136
s = this.getTextValue() and
143137
reg = IntegerLiteralRegexs::integerLiteral() and
144-
last = strictcount(reg.indexOf("(")) and
145-
result = s.regexpCapture(reg, last)
138+
result = s.regexpCapture(reg, 13)
146139
)
147140
}
148141

@@ -193,9 +186,8 @@ module Impl {
193186
class FloatLiteralExpr extends NumberLiteralExpr {
194187
FloatLiteralExpr() {
195188
this.getTextValue()
196-
.regexpMatch([
197< 8000 /td>-
FloatLiteralRegexs::floatLiteral(), FloatLiteralRegexs::integerSuffixLiteral()
198-
]) and
189+
.regexpMatch(IntegerLiteralRegexs::paren(FloatLiteralRegexs::floatLiteral()) + "|" +
190+
IntegerLiteralRegexs::paren(FloatLiteralRegexs::integerSuffixLiteral())) and
199191
// E.g. `0x01_f32` is an integer, not a float
200192
not this instanceof IntegerLiteralExpr
201193
}
@@ -206,15 +198,18 @@ module Impl {
206198
* For example, `42.0f32` has the suffix `f32`.
207199
*/
208200
string getSuffix() {
209-
exists(string s, string reg, int last |
201+
exists(string s, string reg, int group |
202+
reg = FloatLiteralRegexs::floatLiteralSuffix1() and
203+
group = 3
204+
or
205+
reg = FloatLiteralRegexs::floatLiteralSuffix2() and
206+
group = 9
207+
or
208+
reg = FloatLiteralRegexs::integerSuffixLiteral() and
209+
group = 13
210+
|
210211
s = this.getTextValue() and
211-
reg =
212-
[
213-
FloatLiteralRegexs::floatLiteralSuffix1(), FloatLiteralRegexs::floatLiteralSuffix2(),
214-
FloatLiteralRegexs::integerSuffixLiteral()
215-
] and
216-
last = strictcount(reg.indexOf("(")) and
217-
result = s.regexpCapture(reg, last)
212+
result = s.regexpCapture(reg, group)
218213
)
219214
}
220215

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,45 @@
11
charLiteral
22
| literal.rs:2:5:2:7 | 'a' |
33
| literal.rs:3:5:3:7 | 'b' |
4+
| literal.rs:4:5:4:8 | '\\'' |
5+
| literal.rs:5:5:5:8 | '\\n' |
6+
| literal.rs:6:5:6:15 | '\\u{1F600}' |
47
stringLiteral
5-
| literal.rs:8:5:8:9 | "foo" |
6-
| literal.rs:9:5:9:10 | r"foo" |
7-
| literal.rs:10:5:10:13 | "\\"foo\\"" |
8-
| literal.rs:11:5:11:14 | r#""foo""# |
9-
| literal.rs:13:5:13:18 | "foo #\\"# bar" |
10-
| literal.rs:14:5:14:22 | r##"foo #"# bar"## |
11-
| literal.rs:16:5:16:10 | "\\x52" |
12-
| literal.rs:17:5:17:7 | "R" |
13-
| literal.rs:18:5:18:8 | r"R" |
14-
| literal.rs:19:5:19:11 | "\\\\x52" |
15-
| literal.rs:20:5:20:11 | r"\\x52" |
8+
| literal.rs:11:5:11:9 | "foo" |
9+
| literal.rs:12:5:12:10 | r"foo" |
10+
| literal.rs:13:5:13:13 | "\\"foo\\"" |
11+
| literal.rs:14:5:14:14 | r#""foo""# |
12+
| literal.rs:16:5:16:18 | "foo #\\"# bar" |
13+
| literal.rs:17:5:17:22 | r##"foo #"# bar"## |
14+
| literal.rs:19:5:19:10 | "\\x52" |
15+
| literal.rs:20:5:20:7 | "R" |
16+
| literal.rs:21:5:21:8 | r"R" |
17+
| literal.rs:22:5:22:11 | "\\\\x52" |
18+
| literal.rs:23:5:23:11 | r"\\x52" |
1619
integerLiteral
17-
| literal.rs:25:5:25:7 | 123 | |
18-
| literal.rs:26:5:26:10 | 123i32 | i32 |
19-
| literal.rs:27:5:27:10 | 123u32 | u32 |
20-
| literal.rs:28:5:28:11 | 123_u32 | u32 |
21-
| literal.rs:30:5:30:8 | 0xff | |
22-
| literal.rs:31:5:31:11 | 0xff_u8 | u8 |
23-
| literal.rs:32:5:32:12 | 0x01_f32 | |
24-
| literal.rs:33:5:33:11 | 0x01_e3 | |
25-
| literal.rs:35:5:35:8 | 0o70 | |
26-
| literal.rs:36:5:36:12 | 0o70_i16 | i16 |
27-
| literal.rs:38:5:38:25 | 0b1111_1111_1001_0000 | |
28-
| literal.rs:39:5:39:28 | 0b1111_1111_1001_0000i64 | i64 |
29-
| literal.rs:40:5:40:15 | 0b________1 | |
30-
| literal.rs:42:5:42:10 | 0usize | usize |
31-
| literal.rs:45:5:46:10 | 128_i8 | i8 |
32-
| literal.rs:47:5:48:10 | 256_u8 | u8 |
20+
| literal.rs:28:5:28:7 | 123 | |
21+
| literal.rs:29:5:29:10 | 123i32 | i32 |
22+
| literal.rs:30:5:30:10 | 123u32 | u32 |
23+
| literal.rs:31:5:31:11 | 123_u32 | u32 |
24+
| literal.rs:33:5:33:8 | 0xff | |
25+
| literal.rs:34:5:34:11 | 0xff_u8 | u8 |
26+
| literal.rs:35:5:35:12 | 0x01_f32 | |
27+
| literal.rs:36:5:36:11 | 0x01_e3 | |
28+
| literal.rs:38:5:38:8 | 0o70 | |
29+
| literal.rs:39:5:39:12 | 0o70_i16 | i16 |
30+
| literal.rs:41:5:41:25 | 0b1111_1111_1001_0000 | |
31+
| literal.rs:42:5:42:28 | 0b1111_1111_1001_0000i64 | i64 |
32+
| literal.rs:43:5:43:15 | 0b________1 | |
33+
| literal.rs:45:5:45:10 | 0usize | usize |
34+
| literal.rs:48:5:49:10 | 128_i8 | i8 |
35+
| literal.rs:50:5:51:10 | 256_u8 | u8 |
3336
floatLiteral
34-
| literal.rs:53:5:53:8 | 5f32 | f32 |
35-
| literal.rs:55:5:55:12 | 123.0f64 | f64 |
36-
| literal.rs:56:5:56:10 | 0.1f64 | f64 |
37-
| literal.rs:57:5:57:10 | 0.1f32 | f32 |
38-
| literal.rs:58:5:58:14 | 12E+99_f64 | f64 |
39-
| literal.rs:59:18:59:19 | 2. | |
37+
| literal.rs:56:5:56:8 | 5f32 | f32 |
38+
| literal.rs:58:5:58:12 | 123.0f64 | f64 |
39+
| literal.rs:59:5:59:10 | 0.1f64 | f64 |
40+
| literal.rs:60:5:60:10 | 0.1f32 | f32 |
41+
| literal.rs:61:5:61:14 | 12E+99_f64 | f64 |
42+
| literal.rs:62:18:62:19 | 2. | |
4043
booleanLiteral
41-
| literal.rs:63:5:63:8 | true |
42-
| literal.rs:64:5:64:9 | false |
44+
| literal.rs:66:5:66:8 | true |
45+
| literal.rs:67:5:67:9 | false |

rust/ql/test/extractor-tests/literal/literal.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
fn char_literals() {
22
'a';
33
'b';
4+
'\'';
5+
'\n';
6+
'\u{1F600}';
47
}
58

69
fn string_literals() {

0 commit comments

Comments
 (0)
0