Commit 64e9e714 authored by Rusty Russell's avatar Rusty Russell

tal/str: fix infinite loop of tal_fmt() with empty string.

Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 97a1ba3d
...@@ -52,7 +52,7 @@ char *tal_fmt(const tal_t *ctx, const char *fmt, ...) ...@@ -52,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) static bool do_vfmt(char **buf, size_t off, const char *fmt, va_list ap)
{ {
/* A decent guess to start. */ /* A decent guess to start. */
size_t max = strlen(fmt) * 2; size_t max = strlen(fmt) * 2 + 1;
bool ok; bool ok;
for (;;) { for (;;) {
......
#include <ccan/tal/str/str.h>
#include <stdlib.h>
#include <stdio.h>
#include <ccan/tal/str/str.c>
#include <ccan/tap/tap.h>
#include "helper.h"
/* Empty format string: should still terminate! */
int main(int argc, char *argv[])
{
char *str;
const char *fmt = "";
plan_tests(1);
/* GCC complains about empty format string, complains about non-literal
* with no args... */
str = tal_fmt(NULL, fmt, "");
ok1(!strcmp(str, ""));
tal_free(str);
return exit_status();
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment