]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool_operate: fix scanbuild compiler warning
authorJay Satiro <raysatiro@yahoo.com>
Sat, 18 Feb 2023 21:06:11 +0000 (16:06 -0500)
committerJay Satiro <raysatiro@yahoo.com>
Sun, 19 Feb 2023 00:02:40 +0000 (19:02 -0500)
Prior to this change Azure CI scanbuild warned of a potential NULL
pointer string passed to strtol when CURLDEBUG enabled, even though the
way the code was written it wouldn't have happened.

Bug: https://github.com/curl/curl/commit/5479d991#r101159711
Reported-by: Marcel Raad
Closes https://github.com/curl/curl/pull/10559

src/tool_operate.c

index 8bd094885a39d9846cdd4960a0c51b6caea3225f..195159229af660228c56335f1b8c1576dd085198 100644 (file)
@@ -1301,15 +1301,16 @@ static CURLcode single_transfer(struct GlobalConfig *global,
         my_setopt(curl, CURLOPT_SEEKDATA, input);
         my_setopt(curl, CURLOPT_SEEKFUNCTION, tool_seek_cb);
 
+        {
 #ifdef CURLDEBUG
-        if(getenv("CURL_BUFFERSIZE")) {
-          long size = strtol(getenv("CURL_BUFFERSIZE"), NULL, 10);
-          if(size)
-            my_setopt(curl, CURLOPT_BUFFERSIZE, size);
-        }
-        else
+          char *env = getenv("CURL_BUFFERSIZE");
+          if(env) {
+            long size = strtol(env, NULL, 10);
+            if(size)
+              my_setopt(curl, CURLOPT_BUFFERSIZE, size);
+          }
+          else
 #endif
-        {
           if(config->recvpersecond &&
              (config->recvpersecond < BUFFER_SIZE))
             /* use a smaller sized buffer for better sleeps */