X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftal%2Fstr%2Fstr.c;h=7adb9ef5aefbf990067a1dc80569dbba6f679587;hb=64e9e7145aac9502655c5799ab711b9766c1da57;hp=059817b6aa7e928b8e9ceeef372e2510b6ebd3f3;hpb=c8e75cdce11b3ad7db6c1fff580c587395b59965;p=ccan diff --git a/ccan/tal/str/str.c b/ccan/tal/str/str.c index 059817b6..7adb9ef5 100644 --- a/ccan/tal/str/str.c +++ b/ccan/tal/str/str.c @@ -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, "[]")); @@ -54,7 +52,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 (;;) {