]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cookie: get_top_domain() sets zero length for null domains
authorPatrick Monnerat <patrick@monnerat.net>
Tue, 28 Jan 2020 09:23:41 +0000 (10:23 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Sun, 8 Mar 2020 16:30:55 +0000 (17:30 +0100)
This silents a compilation warning with gcc -O3.

lib/cookie.c

index 69bc04260aab0e6a33409569629342c3edb9f7b9..68054e1c4c7f9f62d1d9cf074ffddab7dde0c3e6 100644 (file)
@@ -245,18 +245,17 @@ pathmatched:
  */
 static const char *get_top_domain(const char * const domain, size_t *outlen)
 {
-  size_t len;
+  size_t len = 0;
   const char *first = NULL, *last;
 
-  if(!domain)
-    return NULL;
-
-  len = strlen(domain);
-  last = memrchr(domain, '.', len);
-  if(last) {
-    first = memrchr(domain, '.', (last - domain));
-    if(first)
-      len -= (++first - domain);
+  if(domain) {
+    len = strlen(domain);
+    last = memrchr(domain, '.', len);
+    if(last) {
+      first = memrchr(domain, '.', (last - domain));
+      if(first)
+        len -= (++first - domain);
+    }
   }
 
   if(outlen)