=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/options.c,v retrieving revision 1.41 retrieving revision 1.42 diff -c -r1.41 -r1.42 *** src/usr.bin/tmux/options.c 2019/04/23 20:36:55 1.41 --- src/usr.bin/tmux/options.c 2019/04/25 18:18:55 1.42 *************** *** 1,4 **** ! /* $OpenBSD: options.c,v 1.41 2019/04/23 20:36:55 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: options.c,v 1.42 2019/04/25 18:18:55 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott *************** *** 110,156 **** free(ov->string); } ! static const char * options_value_tostring(struct options_entry *o, union options_value *ov, int numeric) { ! static char s[1024]; ! const char *tmp; if (OPTIONS_IS_STYLE(o)) ! return (style_tostring(&ov->style)); if (OPTIONS_IS_NUMBER(o)) { - tmp = NULL; switch (o->tableentry->type) { case OPTIONS_TABLE_NUMBER: ! xsnprintf(s, sizeof s, "%lld", ov->number); break; case OPTIONS_TABLE_KEY: ! tmp = key_string_lookup_key(ov->number); break; case OPTIONS_TABLE_COLOUR: ! tmp = colour_tostring(ov->number); break; case OPTIONS_TABLE_FLAG: if (numeric) ! xsnprintf(s, sizeof s, "%lld", ov->number); else ! tmp = (ov->number ? "on" : "off"); break; case OPTIONS_TABLE_CHOICE: ! tmp = o->tableentry->choices[ov->number]; break; case OPTIONS_TABLE_STRING: case OPTIONS_TABLE_STYLE: ! break; } - if (tmp != NULL) - xsnprintf(s, sizeof s, "%s", tmp); return (s); } if (OPTIONS_IS_STRING(o)) ! return (ov->string); ! return (""); } struct options * --- 110,152 ---- free(ov->string); } ! static char * options_value_tostring(struct options_entry *o, union options_value *ov, int numeric) { ! char *s; if (OPTIONS_IS_STYLE(o)) ! return (xstrdup(style_tostring(&ov->style))); if (OPTIONS_IS_NUMBER(o)) { switch (o->tableentry->type) { case OPTIONS_TABLE_NUMBER: ! xasprintf(&s, "%lld", ov->number); break; case OPTIONS_TABLE_KEY: ! s = xstrdup(key_string_lookup_key(ov->number)); break; case OPTIONS_TABLE_COLOUR: ! s = xstrdup(colour_tostring(ov->number)); break; case OPTIONS_TABLE_FLAG: if (numeric) ! xasprintf(&s, "%lld", ov->number); else ! s = xstrdup(ov->number ? "on" : "off"); break; case OPTIONS_TABLE_CHOICE: ! s = xstrdup(o->tableentry->choices[ov->number]); break; case OPTIONS_TABLE_STRING: case OPTIONS_TABLE_STYLE: ! fatalx("not a number option type"); } return (s); } if (OPTIONS_IS_STRING(o)) ! return (xstrdup(ov->string)); ! return (xstrdup("")); } struct options * *************** *** 218,228 **** o = options_add(oo, oe->name); o->tableentry = oe; ! if (oe->flags & OPTIONS_TABLE_IS_ARRAY) { ! if (oe->type != OPTIONS_TABLE_STRING) ! fatalx("arrays can only be strings"); RB_INIT(&o->value.array); - } return (o); } --- 214,221 ---- o = options_add(oo, oe->name); o->tableentry = oe; ! if (oe->flags & OPTIONS_TABLE_IS_ARRAY) RB_INIT(&o->value.array); return (o); } *************** *** 443,459 **** return (OPTIONS_IS_STRING(o)); } ! const char * options_tostring(struct options_entry *o, int idx, int numeric) { struct options_array_item *a; if (OPTIONS_IS_ARRAY(o)) { if (idx == -1) ! return (NULL); a = options_array_item(o, idx); if (a == NULL) ! return (""); return (options_value_tostring(o, &a->value, numeric)); } return (options_value_tostring(o, &o->value, numeric)); --- 436,452 ---- return (OPTIONS_IS_STRING(o)); } ! char * options_tostring(struct options_entry *o, int idx, int numeric) { struct options_array_item *a; if (OPTIONS_IS_ARRAY(o)) { if (idx == -1) ! return (xstrdup("")); a = options_array_item(o, idx); if (a == NULL) ! return (xstrdup("")); return (options_value_tostring(o, &a->value, numeric)); } return (options_value_tostring(o, &o->value, numeric));