Abort immediately on expansion error
Many other shells behave this way.
@@ -10,6 +10,9 @@ | ||
10 | 10 | ---------------------------------------------------------------------- |
11 | 11 | Yash 2.51 |
12 | 12 | |
13 | + = When an expansion error occurs, the shell now immediately stops | |
14 | + expansion rather than trying to expand the remaining part of the | |
15 | + word. | |
13 | 16 | = Quote removal in arithmetic expansion has been modified to match |
14 | 17 | the behavior defined in POSIX. It no longer allows things like |
15 | 18 | $(("2" + \5)). |
@@ -391,7 +391,6 @@ | ||
391 | 391 | quoting_T quoting, charcategory_T defaultcc, |
392 | 392 | struct expand_four_inner_T *restrict e) |
393 | 393 | { |
394 | - bool ok = true; | |
395 | 394 | bool indq = false; /* in a double quote? */ |
396 | 395 | bool first = true; /* is the first word unit? */ |
397 | 396 | const wchar_t *ss; |
@@ -487,7 +486,7 @@ | ||
487 | 486 | if (!expand_param(w->wu_param, |
488 | 487 | indq || quoting == Q_LITERAL || (defaultcc & CC_QUOTED), |
489 | 488 | e)) |
490 | - ok = false; | |
489 | + return false; | |
491 | 490 | break; |
492 | 491 | case WT_CMDSUB: |
493 | 492 | s = exec_command_substitution(&w->wu_cmdsub); |
@@ -497,18 +496,16 @@ | ||
497 | 496 | if (s != NULL) |
498 | 497 | s = evaluate_arithmetic(s); |
499 | 498 | cat_s: |
500 | - if (s != NULL) { | |
501 | - wb_catfree(&e->valuebuf, s); | |
502 | - fill_ccbuf(e, CC_SOFT_EXPANSION | | |
503 | - (indq * CC_QUOTED) | (defaultcc & CC_QUOTED)); | |
504 | - } else { | |
505 | - ok = false; | |
506 | - } | |
499 | + if (s == NULL) | |
500 | + return false; | |
501 | + wb_catfree(&e->valuebuf, s); | |
502 | + fill_ccbuf(e, CC_SOFT_EXPANSION | | |
503 | + (indq * CC_QUOTED) | (defaultcc & CC_QUOTED)); | |
507 | 504 | break; |
508 | 505 | } |
509 | 506 | } |
510 | 507 | |
511 | - return ok; | |
508 | + return true; | |
512 | 509 | } |
513 | 510 | |
514 | 511 | /* Appends to `e->ccbuf' as many `c's as needed to match the length with |
@@ -822,10 +819,13 @@ | ||
822 | 819 | break; |
823 | 820 | case PT_SUBST: |
824 | 821 | match = expand_single(p->pe_match, TT_SINGLE, Q_WORD, ES_QUOTED); |
822 | + if (match == NULL) { | |
823 | + plfree(values, free); | |
824 | + return false; | |
825 | + } | |
825 | 826 | subst = expand_single(p->pe_subst, TT_SINGLE, Q_WORD, ES_NONE); |
826 | - if (match == NULL || subst == NULL) { | |
827 | + if (subst == NULL) { | |
827 | 828 | free(match); |
828 | - free(subst); | |
829 | 829 | plfree(values, free); |
830 | 830 | return false; |
831 | 831 | } |