Commit b61b4b2f authored by Rusty Russell's avatar Rusty Russell

opt: fix junk after string in opt_show_charp.

parent 457d4e1f
......@@ -147,6 +147,8 @@ void opt_show_charp(char buf[OPT_SHOW_LEN], char *const *p)
len = OPT_SHOW_LEN - 2;
strncpy(buf+1, *p, len);
buf[1+len] = '"';
if (len < OPT_SHOW_LEN - 2)
buf[2+len] = '\0';
}
/* Set an integer value, various forms. Sets to 1 on arg == NULL. */
......
......@@ -26,12 +26,18 @@ static void reset_options(void)
int main(int argc, char *argv[])
{
char *output;
char *longname = strdup("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
char *shortname = strdup("shortname");
plan_tests(42);
plan_tests(48);
opt_register_table(subtables, NULL);
opt_register_noarg("--kkk|-k", my_cb, NULL, "magic kkk option");
opt_register_noarg("-?", opt_usage_and_exit, "<MyArgs>...",
"This message");
opt_register_arg("--longname", opt_set_charp, opt_show_charp,
&longname, "a really long option default");
opt_register_arg("--shortname", opt_set_charp, opt_show_charp,
&shortname, "a short option default");
output = opt_usage("my name", "ExTrA Args");
diag("%s", output);
ok1(strstr(output, "Usage: my name"));
......@@ -77,6 +83,12 @@ int main(int argc, char *argv[])
ok1(strstr(output, " Description of hhh\n"));
ok1(strstr(output, "--kkk|-k"));
ok1(strstr(output, "magic kkk option"));
ok1(strstr(output, "--longname"));
ok1(strstr(output, "a really long option default"));
ok1(strstr(output, "(default: \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"...)"));
ok1(strstr(output, "--shortname"));
ok1(strstr(output, "a short option default"));
ok1(strstr(output, "(default: \"shortname\")"));
/* This entry is hidden. */
ok1(!strstr(output, "--mmm|-m"));
free(output);
......
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