Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit ccd4e3d

Browse files
committed
Fix issue where the parser crashes on empty unterminated comment.
Crashes on "/*"
1 parent 546cb85 commit ccd4e3d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/res_scanner.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,12 @@ let scanMultiLineComment scanner =
493493
scan ~depth
494494
in
495495
scan ~depth:0;
496+
let length = scanner.offset - 2 - contentStartOff in
497+
let length = if length < 0 (* in case of EOF *) then 0 else length in
496498
Token.Comment (
497499
Comment.makeMultiLineComment
498500
~loc:(Location.{loc_start = startPos; loc_end = (position scanner); loc_ghost = false})
499-
((String.sub [@doesNotRaise]) scanner.src contentStartOff (scanner.offset - 2 - contentStartOff))
501+
((String.sub [@doesNotRaise]) scanner.src contentStartOff length)
500502
)
501503

502504
let scanTemplateLiteralToken scanner =

0 commit comments

Comments
 (0)