]> git.ozlabs.org Git - ccan/blobdiff - ccan/tal/str/str.c
take, tal, tal/path, tal/str, tal/talloc: annotate APIs with TAKES.
[ccan] / ccan / tal / str / str.c
index 059817b6aa7e928b8e9ceeef372e2510b6ebd3f3..4b3b11aa603cf23733ec9aa24251e602c2c7723f 100644 (file)
@@ -11,7 +11,6 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <ccan/str/str.h>
-#include <ccan/take/take.h>
 
 char *tal_strdup(const tal_t *ctx, const char *p)
 {
@@ -26,11 +25,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, "[]"));
@@ -54,7 +51,7 @@ char *tal_fmt(const tal_t *ctx, const char *fmt, ...)
 static bool do_vfmt(char **buf, size_t off, const char *fmt, va_list ap)
 {
        /* A decent guess to start. */
-       size_t max = strlen(fmt) * 2;
+       size_t max = strlen(fmt) * 2 + 1;
        bool ok;
 
        for (;;) {