]> git.ozlabs.org Git - ccan/blobdiff - ccan/tal/str/str.c
tal/str: always create strings which have tal_count() == strlen() + 1.
[ccan] / ccan / tal / str / str.c
index b00775ab70fc4d652e8739027dc99d813a28d2c9..cec31c752bbe104b3a457ec25f62da7df4d172ef 100644 (file)
@@ -68,6 +68,8 @@ static bool do_vfmt(char **buf, size_t off, const char *fmt, va_list ap)
 
                if (ret < max) {
                        ok = true;
+                       /* Make sure tal_count() is correct! */
+                       tal_resize(buf, off + ret + 1);
                        break;
                }
                max *= 2;
@@ -222,6 +224,8 @@ char *tal_strjoin_(const tal_t *ctx,
                totlen += dlen;
        }
        ret[totlen] = '\0';
+       /* Make sure tal_count() is correct! */
+       tal_resize(&ret, totlen+1);
 out:
        if (taken(strings))
                tal_free(strings);