Skip to content

Commit aca8aa9

Browse files
committed
C++: Fix off-by-one in \cX handling
1 parent b30d9d6 commit aca8aa9

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,12 +654,12 @@ private module Impl implements RegexTreeViewSig {
654654

655655
/**
656656
* Gets the unicode char for this escape.
657-
* E.g. for `\cA` this returns "a".
657+
* E.g. for `\cA` this returns `0x01`.
658658
*/
659659
private string getControl() {
660660
this.isControl() and
661661
exists(string letter | letter = this.getText().suffix(2).toUpperCase() |
662-
result = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(letter).toUnicode()
662+
result = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(letter) + 1).toUnicode()
663663
)
664664
}
665665
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,8 @@ regExpNormalCharValue
316316
| regexp.cpp:84:39:84:39 | f | f |
317317
| regexp.cpp:90:19:90:24 | \\u0061 | a |
318318
| regexp.cpp:93:19:93:22 | \\x61 | a |
319-
| regexp.cpp:96:21:96:23 | \\cA | \u0000 |
320-
| regexp.cpp:97:22:97:24 | \\cz | \u0019 |
319+
| regexp.cpp:96:21:96:23 | \\cA | \u0001 |
320+
| regexp.cpp:97:22:97:24 | \\cz | \u001a |
321321
| regexp.cpp:100:20:100:21 | \\0 | \u0000 |
322322
| regexp.cpp:101:21:101:22 | \\0 | \u0000 |
323323
| regexp.cpp:104:21:104:21 | a | a |

0 commit comments

Comments
 (0)