Fix lexing out of bounds by one (#17168)

This commit is contained in:
Dylan Conway
2025-02-08 05:23:41 -08:00
committed by GitHub
parent 584db03a74
commit 2644bad5d4
2 changed files with 9 additions and 0 deletions

View File

@@ -391,6 +391,8 @@ function getBuildEnv(target, options) {
ENABLE_ASSERTIONS: release ? "OFF" : "ON",
ENABLE_LOGS: release ? "OFF" : "ON",
ABI: abi === "musl" ? "musl" : undefined,
CMAKE_TLS_VERIFY: "0",
};
}

View File

@@ -798,11 +798,18 @@ fn NewLexer_(
}
inline fn nextCodepointSlice(it: *LexerType) []const u8 {
if (it.current >= it.source.contents.len) {
return "";
}
const cp_len = strings.wtf8ByteSequenceLengthWithInvalid(it.source.contents.ptr[it.current]);
return if (!(cp_len + it.current > it.source.contents.len)) it.source.contents[it.current .. cp_len + it.current] else "";
}
inline fn nextCodepoint(it: *LexerType) CodePoint {
if (it.current >= it.source.contents.len) {
it.end = it.source.contents.len;
return -1;
}
const cp_len = strings.wtf8ByteSequenceLengthWithInvalid(it.source.contents.ptr[it.current]);
const slice = if (!(cp_len + it.current > it.source.contents.len)) it.source.contents[it.current .. cp_len + it.current] else "";