]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
urlapi: remove redundant condition in dedotdotify
authorDaniel Stenberg <daniel@haxx.se>
Sun, 22 Mar 2026 22:53:35 +0000 (23:53 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 23 Mar 2026 07:26:02 +0000 (08:26 +0100)
Bonus: remove two variables, clear up some comments.

Poined out by CodeSonar

Closes #21065

lib/urlapi.c

index a300477a1b52b1b81b3f100a3abd7b650e0e0ac9..a882473141f628f2367d89d9eb04a71bf9d60ed7 100644 (file)
@@ -731,31 +731,25 @@ UNITTEST int dedotdotify(const char *input, size_t clen, char **outp)
 
   curlx_dyn_init(&out, clen + 1);
 
-  /*  A. If the input buffer begins with a prefix of "../" or "./", then
-      remove that prefix from the input buffer; otherwise, */
+  /* if the input buffer begins with a prefix of "../" or "./", then remove
+     that prefix from the input buffer; otherwise, */
   if(is_dot(&dinput, &dlen)) {
-    const char *p = dinput;
-    size_t blen = dlen;
-
-    if(!clen)
-      /* . [end] */
-      goto end;
-    else if(ISSLASH(*p)) {
+    if(ISSLASH(*dinput)) {
       /* one dot followed by a slash */
-      input = p + 1;
+      input = dinput + 1;
       clen = dlen - 1;
     }
 
-    /*  D. if the input buffer consists only of "." or "..", then remove
-        that from the input buffer; otherwise, */
-    else if(is_dot(&p, &blen)) {
-      if(!blen)
+    /* if the input buffer consists only of "." or "..", then remove
+       that from the input buffer; otherwise, */
+    else if(is_dot(&dinput, &dlen)) {
+      if(!dlen)
         /* .. [end] */
         goto end;
-      else if(ISSLASH(*p)) {
+      else if(ISSLASH(*dinput)) {
         /* ../ */
-        input = p + 1;
-        clen = blen - 1;
+        input = dinput + 1;
+        clen = dlen - 1;
       }
     }
   }
@@ -764,9 +758,9 @@ UNITTEST int dedotdotify(const char *input, size_t clen, char **outp)
     if(ISSLASH(*input)) {
       const char *p = &input[1];
       size_t blen = clen - 1;
-      /*  B. if the input buffer begins with a prefix of "/./" or "/.", where
-          "."  is a complete path segment, then replace that prefix with "/" in
-          the input buffer; otherwise, */
+      /* if the input buffer begins with a prefix of "/./" or "/.", where "."
+         is a complete path segment, then replace that prefix with "/" in the
+         input buffer; otherwise, */
       if(is_dot(&p, &blen)) {
         if(!blen) { /* /. */
           result = curlx_dyn_addn(&out, "/", 1);
@@ -778,10 +772,10 @@ UNITTEST int dedotdotify(const char *input, size_t clen, char **outp)
           continue;
         }
 
-        /*  C. if the input buffer begins with a prefix of "/../" or "/..",
-            where ".." is a complete path segment, then replace that prefix
-            with "/" in the input buffer and remove the last segment and its
-            preceding "/" (if any) from the output buffer; otherwise, */
+        /* if the input buffer begins with a prefix of "/../" or "/..", where
+           ".." is a complete path segment, then replace that prefix with "/"
+           in the input buffer and remove the last segment and its preceding
+           "/" (if any) from the output buffer; otherwise, */
         else if(is_dot(&p, &blen) && (ISSLASH(*p) || !blen)) {
           /* remove the last segment from the output buffer */
           size_t len = curlx_dyn_len(&out);
@@ -804,10 +798,10 @@ UNITTEST int dedotdotify(const char *input, size_t clen, char **outp)
       }
     }
 
-    /*  E. move the first path segment in the input buffer to the end of
-        the output buffer, including the initial "/" character (if any) and
-        any subsequent characters up to, but not including, the next "/"
-        character or the end of the input buffer. */
+    /* move the first path segment in the input buffer to the end of the
+       output buffer, including the initial "/" character (if any) and any
+       subsequent characters up to, but not including, the next "/" character
+       or the end of the input buffer. */
 
     result = curlx_dyn_addn(&out, input, 1);
     input++;