Make an empty state on error rather than leaving something partially

created (which now is now a fatal() later).
This commit is contained in:
nicm 2016-11-02 13:35:36 +00:00
parent c83feeb6f8
commit 382e09bed1

25
cmd.c
View File

@ -451,8 +451,11 @@ cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag,
log_debug("%s: flag %c %d %#x", __func__, c, flag, targetflags); log_debug("%s: flag %c %d %#x", __func__, c, flag, targetflags);
error = cmd_find_current(&current, item, targetflags); error = cmd_find_current(&current, item, targetflags);
if (error != 0 && ~targetflags & CMD_FIND_QUIET) if (error != 0) {
return (-1); if (~targetflags & CMD_FIND_QUIET)
return (-1);
cmd_find_clear_state(&current, NULL, 0);
}
if (!cmd_find_empty_state(&current) && !cmd_find_valid_state(&current)) if (!cmd_find_empty_state(&current) && !cmd_find_valid_state(&current))
fatalx("invalid current state"); fatalx("invalid current state");
@ -467,8 +470,8 @@ cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag,
case CMD_SESSION_WITHPANE: case CMD_SESSION_WITHPANE:
error = cmd_find_target(fs, &current, item, target, error = cmd_find_target(fs, &current, item, target,
CMD_FIND_SESSION, targetflags); CMD_FIND_SESSION, targetflags);
if (error != 0 && ~targetflags & CMD_FIND_QUIET) if (error != 0)
return (-1); goto error;
break; break;
case CMD_MOVEW_R: case CMD_MOVEW_R:
error = cmd_find_target(fs, &current, item, target, error = cmd_find_target(fs, &current, item, target,
@ -482,21 +485,27 @@ cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag,
case CMD_WINDOW_INDEX: case CMD_WINDOW_INDEX:
error = cmd_find_target(fs, &current, item, target, error = cmd_find_target(fs, &current, item, target,
CMD_FIND_WINDOW, targetflags); CMD_FIND_WINDOW, targetflags);
if (error != 0 && ~targetflags & CMD_FIND_QUIET) if (error != 0)
return (-1); goto error;
break; break;
case CMD_PANE: case CMD_PANE:
case CMD_PANE_CANFAIL: case CMD_PANE_CANFAIL:
case CMD_PANE_MARKED: case CMD_PANE_MARKED:
error = cmd_find_target(fs, &current, item, target, error = cmd_find_target(fs, &current, item, target,
CMD_FIND_PANE, targetflags); CMD_FIND_PANE, targetflags);
if (error != 0 && ~targetflags & CMD_FIND_QUIET) if (error != 0)
return (-1); goto error;
break; break;
default: default:
fatalx("unknown %cflag %d", c, flag); fatalx("unknown %cflag %d", c, flag);
} }
return (0); return (0);
error:
if (~targetflags & CMD_FIND_QUIET)
return (-1);
cmd_find_clear_state(fs, NULL, 0);
return (0);
} }
int int