]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool_msgs: make voutf() use stack instead of heap
authorDaniel Stenberg <daniel@haxx.se>
Sat, 22 Nov 2025 21:44:39 +0000 (22:44 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Sun, 23 Nov 2025 11:52:00 +0000 (12:52 +0100)
For printf()ing the message to show.

Closes #19651

src/tool_msgs.c

index 896788745c7cfca3672d9844f66c6d777a0c9474..ae0b6b983586f30b6956833521bbc32f7542599e 100644 (file)
@@ -42,18 +42,15 @@ static void voutf(const char *prefix,
                   const char *fmt,
                   va_list ap)
 {
-  size_t width = (get_terminal_columns() - strlen(prefix));
   size_t len;
   char *ptr;
-  char *print_buffer;
+  char buffer[1024];
+  size_t termw = get_terminal_columns();
+  size_t prefw = strlen(prefix);
+  size_t width = termw > prefw ? termw - prefw : SIZE_MAX;
   DEBUGASSERT(!strchr(fmt, '\n'));
-
-  print_buffer = curl_mvaprintf(fmt, ap);
-  if(!print_buffer)
-    return;
-  len = strlen(print_buffer);
-
-  ptr = print_buffer;
+  len = curl_mvsnprintf(buffer, sizeof(buffer), fmt, ap);
+  ptr = buffer;
   while(len > 0) {
     fputs(prefix, tool_stderr);
 
@@ -79,7 +76,6 @@ static void voutf(const char *prefix,
       len = 0;
     }
   }
-  curl_free(print_buffer);
 }
 
 /*