]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool_getparam: use memdup0() instead of malloc + copy
authorDaniel Stenberg <daniel@haxx.se>
Tue, 30 Dec 2025 22:19:01 +0000 (23:19 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 30 Dec 2025 22:53:24 +0000 (23:53 +0100)
Closes #20118

src/tool_getparam.c

index 89385af844366c455aef4fc07aaa084e1d54e71b..7a3f815dfff7bae4ee7efb4444af18552eb412b7 100644 (file)
@@ -36,6 +36,7 @@
 #include "tool_main.h"
 #include "tool_stderr.h"
 #include "tool_help.h"
+#include "tool_strdup.h"
 #include "var.h"
 
 #define ALLOW_BLANK TRUE
@@ -69,13 +70,10 @@ static ParameterError getstrn(char **str, const char *val,
   if(!allowblank && !val[0])
     return PARAM_BLANK_STRING;
 
-  *str = curlx_malloc(len + 1);
+  *str = memdup0(val, len);
   if(!*str)
     return PARAM_NO_MEM;
 
-  memcpy(*str, val, len);
-  (*str)[len] = 0; /* null-terminate */
-
   return PARAM_OK;
 }