Skip to content

Commit 8e169d3

Browse files
geoffw0jketema
authored andcommitted
C++: Address an edge case for regex locations.
1 parent 9e52f28 commit 8e169d3

4 files changed

Lines changed: 15 additions & 8 deletions

File tree

‎cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ private module Impl implements RegexTreeViewSig {
222222
// Find the opening '"'.
223223
not re instanceof RawStringLiteral and
224224
result = 1 + min(int i | vt.charAt(i) = "\"")
225+
or
226+
// No opening '"'.
227+
not re instanceof RawStringLiteral and
228+
not exists(int i | vt.charAt(i) = "\"") and
229+
result = 0
225230
)
226231
}
227232

‎cpp/ql/test/library-tests/regex/locations.expected‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,5 @@
6464
| regexp.cpp:124:25:124:28 | a\\nc | regexp.cpp | 124 | 25 | 124 | 28 |
6565
| regexp.cpp:125:29:125:32 | a\\nc | regexp.cpp | 125 | 29 | 125 | 32 |
6666
| regexp.cpp:130:29:130:32 | abc1 | regexp.cpp | 130 | 29 | 130 | 32 |
67+
| regexp.cpp:131:35:131:38 | abc2 | regexp.cpp | 131 | 35 | 131 | 38 |
68+
| regexp.cpp:132:25:132:30 | xabc3x | regexp.cpp | 132 | 25 | 132 | 30 |

‎cpp/ql/test/library-tests/regex/parse.expected‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
#-----| [RegExpConstant, RegExpNormalChars] xabc3x
2-
3-
#-----| [RegExpConstant, RegExpNormalChars] abc2
4-
51
regexp.cpp:
62
# 19| [RegExpConstant, RegExpNormalChars] abc
73

@@ -653,3 +649,7 @@ regexp.cpp:
653649
# 125| [RegExpConstant, RegExpNormalChars] c
654650

655651
# 130| [RegExpConstant, RegExpNormalChars] abc1
652+
653+
# 131| [RegExpConstant, RegExpNormalChars] abc2
654+
655+
# 132| [RegExpConstant, RegExpNormalChars] xabc3x

‎cpp/ql/test/library-tests/regex/regexp.expected‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ groupNumber
44
| regexp.cpp:58:20:58:27 | (a\|b\|cd) | 1 |
55
| regexp.cpp:62:21:62:24 | (a+) | 1 |
66
term
7-
| file://:0:0:0:0 | abc2 | RegExpConstant,RegExpNormalChars |
8-
| file://:0:0:0:0 | xabc3x | RegExpConstant,RegExpNormalChars |
97
| regexp.cpp:19:19:19:21 | abc | RegExpConstant,RegExpNormalChars |
108
| regexp.cpp:22:20:22:20 | a | RegExpConstant,RegExpNormalChars |
119
| regexp.cpp:22:20:22:21 | a* | RegExpStar |
@@ -245,9 +243,9 @@ term
245243
| regexp.cpp:125:30:125:31 | \\n | RegExpConstant,RegExpEscape |
246244
| regexp.cpp:125:32:125:32 | c | RegExpConstant,RegExpNormalChars |
247245
| regexp.cpp:130:29:130:32 | abc1 | RegExpConstant,RegExpNormalChars |
246+
| regexp.cpp:131:35:131:38 | abc2 | RegExpConstant,RegExpNormalChars |
247+
| regexp.cpp:132:25:132:30 | xabc3x | RegExpConstant,RegExpNormalChars |
248248
regExpNormalCharValue
249-
| file://:0:0:0:0 | abc2 | abc2 |
250-
| file://:0:0:0:0 | xabc3x | xabc3x |
251249
| regexp.cpp:19:19:19:21 | abc | abc |
252250
| regexp.cpp:22:20:22:20 | a | a |
253251
| regexp.cpp:22:22:22:22 | b | b |
@@ -372,3 +370,5 @@ regExpNormalCharValue
372370
| regexp.cpp:125:30:125:31 | \\n | \n |
373371
| regexp.cpp:125:32:125:32 | c | c |
374372
| regexp.cpp:130:29:130:32 | abc1 | abc1 |
373+
| regexp.cpp:131:35:131:38 | abc2 | abc2 |
374+
| regexp.cpp:132:25:132:30 | xabc3x | xabc3x |

0 commit comments

Comments
 (0)