Commit 7220240c authored by Douglas Bagnall's avatar Douglas Bagnall Committed by Rusty Russell

opt: Don't segfault if a string's default is NULL

Instead show '(nil)', like other people do. This is distinguishable
from a similar looking string value, because the latter is shown with
double quotes while NULL's nil has no quotes.
Signed-off-by: default avatarDouglas Bagnall <douglas@halo.gen.nz>
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 63b00556
......@@ -202,14 +202,19 @@ void opt_show_invbool(char buf[OPT_SHOW_LEN], const bool *b)
void opt_show_charp(char buf[OPT_SHOW_LEN], char *const *p)
{
size_t len = strlen(*p);
buf[0] = '"';
if (len > OPT_SHOW_LEN - 2)
len = OPT_SHOW_LEN - 2;
strncpy(buf+1, *p, len);
buf[1+len] = '"';
if (len < OPT_SHOW_LEN - 2)
buf[2+len] = '\0';
if (*p){
size_t len = strlen(*p);
buf[0] = '"';
if (len > OPT_SHOW_LEN - 2)
len = OPT_SHOW_LEN - 2;
strncpy(buf+1, *p, len);
buf[1+len] = '"';
if (len < OPT_SHOW_LEN - 2)
buf[2+len] = '\0';
}
else {
strncpy(buf, "(nil)", OPT_SHOW_LEN);
}
}
/* Show an integer value, various forms. */
......
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