]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
connect: reshuffle Curl_timeleft_ms to avoid 'redundant condition'
authorDaniel Stenberg <daniel@haxx.se>
Fri, 14 Nov 2025 09:52:43 +0000 (10:52 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 14 Nov 2025 14:12:58 +0000 (15:12 +0100)
Line 143: "if(duringconnect)" would always equal true. While this is
harmless, I believe this minor tweak makes the flow slightly more
obvious to the reader and avoids the redundant condition.

Pointed out by CodeSonar

Closes #19523

lib/connect.c

index 18d9028c6cfa5048ca1e94489b75d7c8cdc09e3e..573b02952b10b9632410c91e34a5a0b144180956 100644 (file)
@@ -116,6 +116,7 @@ timediff_t Curl_timeleft_ms(struct Curl_easy *data,
 {
   timediff_t timeleft_ms = 0;
   timediff_t ctimeleft_ms = 0;
+  timediff_t ctimeout_ms;
   struct curltime now;
 
   /* The duration of a connect and the total transfer are calculated from two
@@ -136,20 +137,19 @@ timediff_t Curl_timeleft_ms(struct Curl_easy *data,
       curlx_timediff_ms(*nowp, data->progress.t_startop);
     if(!timeleft_ms)
       timeleft_ms = -1; /* 0 is "no limit", fake 1 ms expiry */
-    if(!duringconnect)
-      return timeleft_ms; /* no connect check, this is it */
   }
 
-  if(duringconnect) {
-    timediff_t ctimeout_ms = (data->set.connecttimeout > 0) ?
-      data->set.connecttimeout : DEFAULT_CONNECT_TIMEOUT;
-    ctimeleft_ms = ctimeout_ms -
-                   curlx_timediff_ms(*nowp, data->progress.t_startsingle);
-    if(!ctimeleft_ms)
-      ctimeleft_ms = -1; /* 0 is "no limit", fake 1 ms expiry */
-    if(!timeleft_ms)
-      return ctimeleft_ms; /* no general timeout, this is it */
-  }
+  if(!duringconnect)
+    return timeleft_ms; /* no connect check, this is it */
+  ctimeout_ms = (data->set.connecttimeout > 0) ?
+    data->set.connecttimeout : DEFAULT_CONNECT_TIMEOUT;
+  ctimeleft_ms = ctimeout_ms -
+    curlx_timediff_ms(*nowp, data->progress.t_startsingle);
+  if(!ctimeleft_ms)
+    ctimeleft_ms = -1; /* 0 is "no limit", fake 1 ms expiry */
+  if(!timeleft_ms)
+    return ctimeleft_ms; /* no general timeout, this is it */
+
   /* return minimal time left or max amount already expired */
   return (ctimeleft_ms < timeleft_ms) ? ctimeleft_ms : timeleft_ms;
 }