From b1cd46c37c3d446d97dfb29d1f1bc920973358c2 Mon Sep 17 00:00:00 2001 From: EllipticEllipsis <73679967+EllipticEllipsis@users.noreply.github.com> Date: Tue, 7 Sep 2021 17:17:19 +0100 Subject: [PATCH] Add `va_end` and returns to variadic functions (#950) --- src/boot/is_debug.c | 6 ++++++ src/code/fault_drawer.c | 4 ++++ src/code/gfxprint.c | 7 ++++++- src/code/printutils.c | 7 ++++++- src/libultra_boot_O2/sprintf.c | 3 +++ 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/boot/is_debug.c b/src/boot/is_debug.c index 39544984d3..1c8e49e5d5 100644 --- a/src/boot/is_debug.c +++ b/src/boot/is_debug.c @@ -17,6 +17,8 @@ void osSyncPrintfUnused(const char* fmt, ...) { va_start(args, fmt); _Printf(is_proutSyncPrintf, NULL, fmt, args); + + va_end(args); } void osSyncPrintf(const char* fmt, ...) { @@ -24,6 +26,8 @@ void osSyncPrintf(const char* fmt, ...) { va_start(args, fmt); _Printf(is_proutSyncPrintf, NULL, fmt, args); + + va_end(args); } // assumption @@ -32,6 +36,8 @@ void rmonPrintf(const char* fmt, ...) { va_start(args, fmt); _Printf(is_proutSyncPrintf, NULL, fmt, args); + + va_end(args); } void* is_proutSyncPrintf(void* arg, const char* str, u32 count) { diff --git a/src/code/fault_drawer.c b/src/code/fault_drawer.c index 2a875ae5de..0885cacbdd 100644 --- a/src/code/fault_drawer.c +++ b/src/code/fault_drawer.c @@ -272,6 +272,8 @@ void FaultDrawer_Printf(const char* fmt, ...) { va_start(args, fmt); FaultDrawer_VPrintf(fmt, args); + + va_end(args); } void FaultDrawer_DrawText(s32 x, s32 y, const char* fmt, ...) { @@ -280,6 +282,8 @@ void FaultDrawer_DrawText(s32 x, s32 y, const char* fmt, ...) { FaultDrawer_SetCursor(x, y); FaultDrawer_VPrintf(fmt, args); + + va_end(args); } void FaultDrawer_SetDrawerFB(void* fb, u16 w, u16 h) { diff --git a/src/code/gfxprint.c b/src/code/gfxprint.c index 3dc385edfc..b526de9be3 100644 --- a/src/code/gfxprint.c +++ b/src/code/gfxprint.c @@ -357,8 +357,13 @@ s32 GfxPrint_VPrintf(GfxPrint* this, const char* fmt, va_list args) { } s32 GfxPrint_Printf(GfxPrint* this, const char* fmt, ...) { + s32 ret; va_list args; va_start(args, fmt); - return GfxPrint_VPrintf(this, fmt, args); + ret = GfxPrint_VPrintf(this, fmt, args); + + va_end(args); + + return ret; } diff --git a/src/code/printutils.c b/src/code/printutils.c index 1df6a4bfce..3fb8cf3672 100644 --- a/src/code/printutils.c +++ b/src/code/printutils.c @@ -5,8 +5,13 @@ s32 PrintUtils_VPrintf(PrintCallback* pfn, const char* fmt, va_list args) { } s32 PrintUtils_Printf(PrintCallback* pfn, const char* fmt, ...) { + s32 ret; va_list args; va_start(args, fmt); - return PrintUtils_VPrintf(pfn, fmt, args); + ret = PrintUtils_VPrintf(pfn, fmt, args); + + va_end(args); + + return ret; } diff --git a/src/libultra_boot_O2/sprintf.c b/src/libultra_boot_O2/sprintf.c index 386d9fa141..9868fb4dca 100644 --- a/src/libultra_boot_O2/sprintf.c +++ b/src/libultra_boot_O2/sprintf.c @@ -21,5 +21,8 @@ s32 sprintf(char* dst, const char* fmt, ...) { if (ret > -1) { dst[ret] = 0; } + + va_end(args); + return ret; }