Suppress false positive warning "-Wmaybe-uninitialized" with GCC -O3
authorChirimen-Jako <chirimen.jako.luqina@gmail.com>
Wed, 31 Jul 2019 09:21:58 +0000 (18:21 +0900)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 1 Aug 2019 01:13:26 +0000 (10:43 +0930)
ccan/tal/path/path.c

index b50120667c0759649d35292578f627ef644988c3..75894240b49db73a2fcb85df05cbb5207ee5d177 100644 (file)
@@ -302,7 +302,7 @@ fail_take_to:
 
  char *path_readlink(const tal_t *ctx, const char *linkname)
  {
-       ssize_t len, maxlen = 64; /* good first guess. */
+       ssize_t maxlen = 64; /* good first guess. */
        char *ret = NULL;
 
        if (unlikely(!linkname) && is_taken(linkname))
@@ -311,19 +311,20 @@ fail_take_to:
        ret = tal_arr(ctx, char, maxlen + 1);
 
        while (ret) {
-               len = readlink(linkname, ret, maxlen);
+               ssize_t len = readlink(linkname, ret, maxlen);
+
                if (len < 0)
                        goto fail;
-               if (len < maxlen)
+
+               if (len < maxlen) {
+                       ret[len] = '\0';
                        break;
+               }
 
                if (!tal_resize(&ret, maxlen *= 2 + 1))
                        goto fail;
        }
 
-       if (ret)
-               ret[len] = '\0';
-
 out:
        if (taken(linkname))
                tal_free(linkname);