Commit 2412df4
committed
Fix a crash when reporting an error at the end of a file
The compiler crashes with a segmentation fault when an unterminated
C-style comment exists at the very end of a file.
The root cause is a buffer over-read in the error() function, which
attempts to construct a diagnostic message by reading the source line
containing the error. When the error is on the last line of a file
without a trailing newline, this logic would read past the end of the
source buffer.
Fix the issue by adding a bounds check to the loop, ensuring it does
not read beyond the source buffer's size. This allows the compiler to
correctly report the "Unenclosed C-style comment" error instead of
crashing.1 parent 4da0b6e commit 2412df4
1 file changed
+2
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1395 | 1395 | | |
1396 | 1396 | | |
1397 | 1397 | | |
1398 | | - | |
| 1398 | + | |
| 1399 | + | |
1399 | 1400 | | |
1400 | 1401 | | |
1401 | 1402 | | |
| |||
0 commit comments