Fix for builtin_test crash

https://github.com/fish-shell/fish-shell/issues/497
This commit is contained in:
ridiculousfish 2013-01-06 14:48:46 -08:00
parent 8a357e1866
commit bf3e4126b2
3 changed files with 11 additions and 10 deletions

View file

@ -772,7 +772,6 @@ static int builtin_set(parser_t &parser, wchar_t **argv)
else else
{ {
wcstring_list_t value; wcstring_list_t value;
// al_init(&value);
while (woptind < argc) while (woptind < argc)
{ {
@ -790,17 +789,9 @@ static int builtin_set(parser_t &parser, wchar_t **argv)
my_env_set(dest, result, scope); my_env_set(dest, result, scope);
// al_destroy( &value );
} }
} }
// al_foreach( &result, &free );
// al_destroy( &result );
// al_destroy(&indexes);
// al_destroy(&values);
} }
else else
{ {

View file

@ -334,11 +334,12 @@ expression *test_parser::parse_combining_expression(unsigned int start, unsigned
std::vector<expression *> subjects; std::vector<expression *> subjects;
std::vector<token_t> combiners; std::vector<token_t> combiners;
unsigned int idx = start; unsigned int idx = start;
bool first = true;
while (idx < end) while (idx < end)
{ {
if (! subjects.empty()) if (! first)
{ {
/* This is not the first expression, so we expect a combiner. */ /* This is not the first expression, so we expect a combiner. */
token_t combiner = token_for_string(arg(idx))->tok; token_t combiner = token_for_string(arg(idx))->tok;
@ -357,12 +358,18 @@ expression *test_parser::parse_combining_expression(unsigned int start, unsigned
if (! expr) if (! expr)
{ {
add_error(L"Missing argument at index %u", idx); add_error(L"Missing argument at index %u", idx);
if (! first)
{
/* Clean up the dangling combiner, since it never got its right hand expression */
combiners.pop_back();
}
break; break;
} }
/* Go to the end of this expression */ /* Go to the end of this expression */
idx = expr->range.end; idx = expr->range.end;
subjects.push_back(expr); subjects.push_back(expr);
first = false;
} }
if (! subjects.empty()) if (! subjects.empty())

View file

@ -922,6 +922,9 @@ static void test_test()
/* These should be errors */ /* These should be errors */
assert(run_test_test(1, L"foo bar")); assert(run_test_test(1, L"foo bar"));
assert(run_test_test(1, L"foo bar baz")); assert(run_test_test(1, L"foo bar baz"));
/* This crashed */
assert(run_test_test(1, L"1 = 1 -a = 1"));
} }
/** Testing colors */ /** Testing colors */