]> git.ozlabs.org Git - ccan/blobdiff - ccan/tal/str/str.c
tal/str: fix error in tal_strndup()
[ccan] / ccan / tal / str / str.c
index 059817b6aa7e928b8e9ceeef372e2510b6ebd3f3..83dac663f7175d6c95a21a17f3337f61e26aebc0 100644 (file)
@@ -26,11 +26,9 @@ char *tal_strndup(const tal_t *ctx, const char *p, size_t n)
        char *ret;
 
        /* We have to let through NULL for take(). */
-       if (likely(p)) {
-               len = strlen(p);
-               if (len > n)
-                       len = n;
-       } else
+       if (likely(p))
+               len = strnlen(p, n);
+       else
                len = n;
 
        ret = tal_dup_(ctx, p, 1, len, 1, false, TAL_LABEL(char, "[]"));