=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/options.c,v retrieving revision 1.53 retrieving revision 1.54 diff -c -r1.53 -r1.54 *** src/usr.bin/tmux/options.c 2019/10/14 08:38:07 1.53 --- src/usr.bin/tmux/options.c 2019/10/15 08:30:36 1.54 *************** *** 1,4 **** ! /* $OpenBSD: options.c,v 1.53 2019/10/14 08:38:07 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: options.c,v 1.54 2019/10/15 08:30:36 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott *************** *** 321,326 **** --- 321,337 ---- return (RB_FIND(options_array, &o->value.array, &a)); } + static struct options_array_item * + options_array_new(struct options_entry *o, u_int idx) + { + struct options_array_item *a; + + a = xcalloc(1, sizeof *a); + a->index = idx; + RB_INSERT(options_array, &o->value.array, a); + return (a); + } + static void options_array_free(struct options_entry *o, struct options_array_item *a) { *************** *** 368,374 **** return (-1); } ! if (OPTIONS_IS_COMMAND(o) && value != NULL) { pr = cmd_parse_from_string(value, NULL); switch (pr->status) { case CMD_PARSE_EMPTY: --- 379,392 ---- return (-1); } ! if (value == NULL) { ! a = options_array_item(o, idx); ! if (a != NULL) ! options_array_free(o, a); ! return (0); ! } ! ! if (OPTIONS_IS_COMMAND(o)) { pr = cmd_parse_from_string(value, NULL); switch (pr->status) { case CMD_PARSE_EMPTY: *************** *** 384,417 **** case CMD_PARSE_SUCCESS: break; } - } ! a = options_array_item(o, idx); ! if (value == NULL) { ! if (a != NULL) ! options_array_free(o, a); return (0); } if (OPTIONS_IS_STRING(o)) { if (a != NULL && append) xasprintf(&new, "%s%s", a->value.string, value); else new = xstrdup(value); } ! if (a == NULL) { ! a = xcalloc(1, sizeof *a); ! a->index = idx; ! RB_INSERT(options_array, &o->value.array, a); ! } else ! options_value_free(o, &a->value); ! ! if (OPTIONS_IS_STRING(o)) ! a->value.string = new; ! else if (OPTIONS_IS_COMMAND(o)) ! a->value.cmdlist = pr->cmdlist; ! return (0); } int --- 402,434 ---- case CMD_PARSE_SUCCESS: break; } ! a = options_array_item(o, idx); ! if (a == NULL) ! a = options_array_new(o, idx); ! else ! options_value_free(o, &a->value); ! a->value.cmdlist = pr->cmdlist; return (0); } if (OPTIONS_IS_STRING(o)) { + a = options_array_item(o, idx); if (a != NULL && append) xasprintf(&new, "%s%s", a->value.string, value); else new = xstrdup(value); + if (a == NULL) + a = options_array_new(o, idx); + else + options_value_free(o, &a->value); + a->value.string = new; + return (0); } ! if (cause != NULL) ! *cause = xstrdup("wrong array type"); ! return (-1); } int