Skip to content

Commit d6699f2

Browse files
committed
Check bounds when accesing last element of stack
In the scanner. Otherwise this triggers the undefined behavior sanitizer when the array is accessed with index -1.
1 parent be30d90 commit d6699f2

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)