Fix for crash with malformed switch statement. Fixes #1376

This commit is contained in:
ridiculousfish 2014-03-28 16:56:44 -07:00
parent 005edf71a8
commit 74b28f0a86

View file

@ -547,13 +547,15 @@ parse_execution_result_t parse_execution_context_t::run_switch_statement(const p
_(L"switch: Expected exactly one argument, got %lu\n"), _(L"switch: Expected exactly one argument, got %lu\n"),
switch_values_expanded.size()); switch_values_expanded.size());
} }
const wcstring &switch_value_expanded = switch_values_expanded.at(0).completion;
switch_block_t *sb = new switch_block_t();
parser->push_block(sb);
if (result == parse_execution_success) if (result == parse_execution_success)
{ {
const wcstring &switch_value_expanded = switch_values_expanded.at(0).completion;
switch_block_t *sb = new switch_block_t();
parser->push_block(sb);
/* Expand case statements */ /* Expand case statements */
const parse_node_t *case_item_list = get_child(statement, 3, symbol_case_item_list); const parse_node_t *case_item_list = get_child(statement, 3, symbol_case_item_list);
@ -597,16 +599,16 @@ parse_execution_result_t parse_execution_context_t::run_switch_statement(const p
} }
} }
} }
}
if (result == parse_execution_success && matching_case_item != NULL) if (result == parse_execution_success && matching_case_item != NULL)
{ {
/* Success, evaluate the job list */ /* Success, evaluate the job list */
const parse_node_t *job_list = get_child(*matching_case_item, 3, symbol_job_list); const parse_node_t *job_list = get_child(*matching_case_item, 3, symbol_job_list);
result = this->run_job_list(*job_list, sb); result = this->run_job_list(*job_list, sb);
} }
parser->pop_block(sb); parser->pop_block(sb);
}
return result; return result;
} }