• R/O
  • SSH
  • HTTPS

yash: 提交


Commit MetaInfo

修訂4091 (tree)
時間2020-09-29 00:20:58
作者magicant

Log Message

Abort immediately on expansion error

Many other shells behave this way.

Change Summary

差異

--- yash/trunk/NEWS (revision 4090)
+++ yash/trunk/NEWS (revision 4091)
@@ -10,6 +10,9 @@
1010 ----------------------------------------------------------------------
1111 Yash 2.51
1212
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.
1316 = Quote removal in arithmetic expansion has been modified to match
1417 the behavior defined in POSIX. It no longer allows things like
1518 $(("2" + \5)).
--- yash/trunk/expand.c (revision 4090)
+++ yash/trunk/expand.c (revision 4091)
@@ -391,7 +391,6 @@
391391 quoting_T quoting, charcategory_T defaultcc,
392392 struct expand_four_inner_T *restrict e)
393393 {
394- bool ok = true;
395394 bool indq = false; /* in a double quote? */
396395 bool first = true; /* is the first word unit? */
397396 const wchar_t *ss;
@@ -487,7 +486,7 @@
487486 if (!expand_param(w->wu_param,
488487 indq || quoting == Q_LITERAL || (defaultcc & CC_QUOTED),
489488 e))
490- ok = false;
489+ return false;
491490 break;
492491 case WT_CMDSUB:
493492 s = exec_command_substitution(&w->wu_cmdsub);
@@ -497,18 +496,16 @@
497496 if (s != NULL)
498497 s = evaluate_arithmetic(s);
499498 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));
507504 break;
508505 }
509506 }
510507
511- return ok;
508+ return true;
512509 }
513510
514511 /* Appends to `e->ccbuf' as many `c's as needed to match the length with
@@ -822,10 +819,13 @@
822819 break;
823820 case PT_SUBST:
824821 match = expand_single(p->pe_match, TT_SINGLE, Q_WORD, ES_QUOTED);
822+ if (match == NULL) {
823+ plfree(values, free);
824+ return false;
825+ }
825826 subst = expand_single(p->pe_subst, TT_SINGLE, Q_WORD, ES_NONE);
826- if (match == NULL || subst == NULL) {
827+ if (subst == NULL) {
827828 free(match);
828- free(subst);
829829 plfree(values, free);
830830 return false;
831831 }
Show on old repository browser