Skip to content

Commit 63d9f71

Browse files
committed
Fix get_column() segfault on EOF, don't do lookahead without EOF check first
1 parent 85a588b commit 63d9f71

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/src/lexer.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static void ts_lexer__advance(TSLexer *_self, bool skip) {
213213
} else {
214214
LOG("consume", self->data.lookahead);
215215
}
216-
216+
217217
ts_lexer__do_advance(self, skip);
218218
}
219219

@@ -245,9 +245,9 @@ static void ts_lexer__mark_end(TSLexer *_self) {
245245

246246
static uint32_t ts_lexer__get_column(TSLexer *_self) {
247247
Lexer *self = (Lexer *)_self;
248-
248+
249249
uint32_t goal_byte = self->current_position.bytes;
250-
250+
251251
self->did_get_column = true;
252252
self->current_position.bytes -= self->current_position.extent.column;
253253
self->current_position.extent.column = 0;
@@ -257,10 +257,13 @@ static uint32_t ts_lexer__get_column(TSLexer *_self) {
257257
}
258258

259259
uint32_t result = 0;
260-
ts_lexer__get_lookahead(self);
261-
while (self->current_position.bytes < goal_byte && !ts_lexer__eof(_self) && self->chunk) {
262-
ts_lexer__do_advance(self, false);
263-
result++;
260+
if (!ts_lexer__eof(_self)) {
261+
ts_lexer__get_lookahead(self);
262+
while (self->current_position.bytes < goal_byte && self->chunk) {
263+
result++;
264+
ts_lexer__do_advance(self, false);
265+
if (ts_lexer__eof(_self)) break;
266+
}
264267
}
265268

266269
return result;

0 commit comments

Comments
 (0)