Skip to content

Commit

Permalink
lib/gis: Refactor va_list usage in debug module (#4702)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ymdatta authored Nov 29, 2024
1 parent a9a4cec commit 0c3a9c7
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/gis/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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;
Expand Down

0 comments on commit 0c3a9c7

Please sign in to comment.