Fixing LUA MemTextViewer calls.

This commit is contained in:
Nicholaos Mouzourakis 2025-03-23 18:12:06 -04:00 committed by d0k3
parent 35cf7898cc
commit 27c5a5c4f3

View File

@ -207,11 +207,15 @@ static int ui_show_text_viewer(lua_State* L) {
// validate text ourselves so we can return a better error // validate text ourselves so we can return a better error
// MemTextViewer calls ShowPrompt if it's bad, and i don't want that // MemTextViewer calls ShowPrompt if it's bad, and i don't want that
if (len >= STD_BUFFER_SIZE) {
return luaL_error(L, "text is too large");
}
if (!(ValidateText(text, len))) { if (!(ValidateText(text, len))) {
return luaL_error(L, "text validation failed"); return luaL_error(L, "text validation failed");
} }
if (!(MemTextViewer(text, len, 1, false))) { if (!(MemTextViewer(text, len, 1, false, 0, NULL))) {
return luaL_error(L, "failed to run MemTextViewer"); return luaL_error(L, "failed to run MemTextViewer");
} }
@ -226,6 +230,11 @@ static int ui_show_file_text_viewer(lua_State* L) {
// MemTextViewer calls ShowPrompt if it's bad, and i don't want that // MemTextViewer calls ShowPrompt if it's bad, and i don't want that
// and FileTextViewer calls the above function // and FileTextViewer calls the above function
size_t fileSize = FileGetSize(path);
if (fileSize >= STD_BUFFER_SIZE) {
return luaL_error(L, "text file is too large");
}
char* text = malloc(STD_BUFFER_SIZE); char* text = malloc(STD_BUFFER_SIZE);
if (!text) { if (!text) {
return luaL_error(L, "could not allocate memory"); return luaL_error(L, "could not allocate memory");
@ -233,16 +242,14 @@ static int ui_show_file_text_viewer(lua_State* L) {
// TODO: replace this with something that can detect file read errors and actual 0-length files // TODO: replace this with something that can detect file read errors and actual 0-length files
size_t flen = FileGetData(path, text, STD_BUFFER_SIZE - 1, 0); size_t flen = FileGetData(path, text, STD_BUFFER_SIZE - 1, 0);
text[flen] = '\0'; text[flen] = '\0';
u32 len = (ptrdiff_t)memchr(text, '\0', flen + 1) - (ptrdiff_t)text;
if (!(ValidateText(text, len))) { if (!(ValidateText(text, flen))) {
free(text); free(text);
return luaL_error(L, "text validation failed"); return luaL_error(L, "text validation failed");
} }
if (!(MemTextViewer(text, len, 1, false))) { if (!(MemTextViewer(text, flen, 1, false, STD_BUFFER_SIZE - 1, path))) {
free(text); free(text);
return luaL_error(L, "failed to run MemTextViewer"); return luaL_error(L, "failed to run MemTextViewer");
} }