From b579d30ade2c66adab7990a818315136f9664f2a Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Wed, 19 Jun 2024 20:40:45 -0700 Subject: [PATCH] Fix read out of bounds with empty file. --- src/lparser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lparser.cpp b/src/lparser.cpp index 82ac34a1..f0eea74b 100644 --- a/src/lparser.cpp +++ b/src/lparser.cpp @@ -2326,8 +2326,8 @@ int luaY_parser(terra_State *T, ZIO *z, const char *name, int firstchar) { lexstate.output_buffer.data); } // loadbuffer doesn't like null terminators, so rewind to before them - while (lexstate.output_buffer.data[lexstate.output_buffer.N - 1] == '\0' && - lexstate.output_buffer.N > 0) { + while (lexstate.output_buffer.N > 0 && + lexstate.output_buffer.data[lexstate.output_buffer.N - 1] == '\0') { lexstate.output_buffer.N--; }