From 0c3a9c74d52c0c9efb9ba62832dfea203294041b Mon Sep 17 00:00:00 2001 From: Mohan Yelugoti Date: Fri, 29 Nov 2024 11:51:03 -0500 Subject: [PATCH] lib/gis: Refactor va_list usage in debug module (#4702) va_list() macro initializes va_list structure before it's usage, and each va_list() call has to be accompanied by corresponding va_end() macro call on the same va_list structure. By having these macros directly before and after the va_list structure usage, reduces the number of places we need to keep track of whether the va_list structure was properly inintialized or closed. Signed-off-by: Mohan Yelugoti --- lib/gis/debug.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/gis/debug.c b/lib/gis/debug.c index 034ab8dc690..b0d42260528 100644 --- a/lib/gis/debug.c +++ b/lib/gis/debug.c @@ -72,8 +72,6 @@ int G_debug(int level, const char *msg, ...) G_init_debug(); if (grass_debug_level >= level) { - va_start(ap, msg); - filen = getenv("GRASS_DEBUG_FILE"); if (filen != NULL) { fd = fopen(filen, "a"); @@ -87,14 +85,14 @@ int G_debug(int level, const char *msg, ...) } fprintf(fd, "D%d/%d: ", level, grass_debug_level); + va_start(ap, msg); vfprintf(fd, msg, ap); + va_end(ap); fprintf(fd, "\n"); fflush(fd); if (filen != NULL) fclose(fd); - - va_end(ap); } return 1;