From 70eec3832f5009c3bc3fa7cf57a44902b5a16928 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 10 Oct 2012 08:56:47 +0200 Subject: [PATCH] MINOR: standard: make indent_msg() support empty messages indent_msg() is called with dynamically generated messages, so these may be empty (NULL) when an empty list is being dumped. Support this and return a NULL too. --- src/standard.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/standard.c b/src/standard.c index 49810fcca..287931adf 100644 --- a/src/standard.c +++ b/src/standard.c @@ -1840,7 +1840,8 @@ char *memprintf(char **out, const char *format, ...) /* Used to add spaces before each line of , unless there is only one line. * The input argument is automatically freed and reassigned. The result will have to be - * freed by the caller. + * freed by the caller. It also supports being passed a NULL which results in the same + * output. * Example of use : * parse(cmd, &err); (callee: memprintf(&err, ...)) * fprintf(stderr, "Parser said: %s\n", indent_error(&err)); @@ -1854,6 +1855,9 @@ char *indent_msg(char **out, int level) int lastlf = 0; int len; + if (!out || !*out) + return NULL; + in = *out - 1; while ((in = strchr(in + 1, '\n')) != NULL) { lastlf = in - *out;