Skip to content

Commit a8638eb

Browse files
authored
Merge pull request stadelmanma#190 from codee-com/fixArrayIndex
Fix UB when when accesing last element of stack in scanner
2 parents be30d90 + d6699f2 commit a8638eb

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/scanner.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,12 @@ static bool scan_preproc_unary_operator(TSLexer *lexer) {
458458

459459
static void track_labeled_do(Scanner *scanner, int32_t label) {
460460
// check if label already exists
461-
int i = scanner->depth - 1;
462-
if (scanner->labels[i] == label) {
461+
if (scanner->depth > 0) {
462+
int i = scanner->depth - 1;
463+
if (scanner->labels[i] == label) {
463464
scanner->counts[i]++;
464465
return;
466+
}
465467
}
466468

467469
// not at top of stack, assume new label, add it to stack

0 commit comments

Comments
 (0)