From 28b0cb9e718f79ad536fc7992fa5c2215dac9c63 Mon Sep 17 00:00:00 2001 From: philmoz Date: Tue, 24 Dec 2024 11:53:05 +1100 Subject: [PATCH] fix(radio): potential crash when writing .luac files (#5732) --- radio/src/lua/interface.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/radio/src/lua/interface.cpp b/radio/src/lua/interface.cpp index 5eeb5a3eccb..fc7a7e69670 100644 --- a/radio/src/lua/interface.cpp +++ b/radio/src/lua/interface.cpp @@ -358,6 +358,7 @@ FRESULT dresult = FR_OK; static int luaDumpWriter(lua_State * L, const void* p, size_t size, void* u) { UNUSED(L); + UINT written; const uint8_t* b = (const uint8_t*)p; while (size > 0) { int len; @@ -372,7 +373,7 @@ static int luaDumpWriter(lua_State * L, const void* p, size_t size, void* u) b += len; if (dpos >= DLEN) { // Write to SD when buffer full - dresult = f_write((FIL *)u, dbuf, dpos, nullptr); + dresult = f_write((FIL *)u, dbuf, dpos, &written); dpos = 0; if (dresult != FR_OK) break; @@ -402,7 +403,8 @@ static void luaDumpState(lua_State * L, const char * filename, const FILINFO * f lua_unlock(L); if (dpos > 0) { // Write last piece - dresult = f_write(&D, dbuf, dpos, nullptr); + UINT written; + dresult = f_write(&D, dbuf, dpos, &written); } if (dresult != FR_OK) { // Save failed, close file handle and delete file.