diff options
author | Peter Stephenson <pws@users.sourceforge.net> | 2008-10-09 13:46:45 +0000 |
---|---|---|
committer | Peter Stephenson <pws@users.sourceforge.net> | 2008-10-09 13:46:45 +0000 |
commit | ad3e2aa2157bc779b596d95987a80b28cf6928b9 (patch) | |
tree | ad186c4074d05c1b96832aac9c3c72c1def35e0d /Src | |
parent | 86ef4650dccad8dfa00f28c94296dae1ec13d84e (diff) | |
download | zsh-ad3e2aa2157bc779b596d95987a80b28cf6928b9.tar.gz zsh-ad3e2aa2157bc779b596d95987a80b28cf6928b9.tar.xz zsh-ad3e2aa2157bc779b596d95987a80b28cf6928b9.zip |
25831: fix empty return values from subscript matches with RC_EXPAND_PARAM
Diffstat (limited to 'Src')
-rw-r--r-- | Src/params.c | 10 | ||||
-rw-r--r-- | Src/zsh.h | 29 |
2 files changed, 24 insertions, 15 deletions
diff --git a/Src/params.c b/Src/params.c index 65b3ecff8..71cb2a907 100644 --- a/Src/params.c +++ b/Src/params.c @@ -1810,11 +1810,10 @@ fetchvalue(Value v, char **pptr, int bracks, int flags) /* Overload v->isarr as the flag bits for hashed arrays. */ v->isarr = flags | (isvarat ? SCANPM_ISVAR_AT : 0); /* If no flags were passed, we need something to represent * - * `true' yet differ from an explicit WANTVALS. This is a * - * bit of a hack, but makes some sense: When no subscript * - * is provided, all values are substituted. */ + * `true' yet differ from an explicit WANTVALS. Use a * + * special flag for this case. */ if (!v->isarr) - v->isarr = SCANPM_MATCHMANY; + v->isarr = SCANPM_ARRONLY; } v->pm = pm; v->flags = 0; @@ -2188,7 +2187,8 @@ setstrvalue(Value v, char *val) zsfree(val); return; } - if ((v->pm->node.flags & PM_HASHED) && (v->isarr & SCANPM_MATCHMANY)) { + if ((v->pm->node.flags & PM_HASHED) && + (v->isarr & (SCANPM_MATCHMANY|SCANPM_ARRONLY))) { zerr("%s: attempt to set slice of associative array", v->pm->node.nam); zsfree(val); return; diff --git a/Src/zsh.h b/Src/zsh.h index 2ceab1dca..94d4503e4 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -1532,16 +1532,25 @@ struct tieddata { #define TYPESET_OPTNUM "LRZiEF" /* Flags for extracting elements of arrays and associative arrays */ -#define SCANPM_WANTVALS (1<<0) -#define SCANPM_WANTKEYS (1<<1) -#define SCANPM_WANTINDEX (1<<2) -#define SCANPM_MATCHKEY (1<<3) -#define SCANPM_MATCHVAL (1<<4) -#define SCANPM_MATCHMANY (1<<5) -#define SCANPM_ASSIGNING (1<<6) -#define SCANPM_KEYMATCH (1<<7) -#define SCANPM_DQUOTED (1<<8) -#define SCANPM_ISVAR_AT ((-1)<<15) /* Only sign bit is significant */ +#define SCANPM_WANTVALS (1<<0) /* Return value includes hash values */ +#define SCANPM_WANTKEYS (1<<1) /* Return value includes hash keys */ +#define SCANPM_WANTINDEX (1<<2) /* Return value includes array index */ +#define SCANPM_MATCHKEY (1<<3) /* Subscript matched against key */ +#define SCANPM_MATCHVAL (1<<4) /* Subscript matched against value */ +#define SCANPM_MATCHMANY (1<<5) /* Subscript matched repeatedly, return all */ +#define SCANPM_ASSIGNING (1<<6) /* Assigning whole array/hash */ +#define SCANPM_KEYMATCH (1<<7) /* keys of hash treated as patterns */ +#define SCANPM_DQUOTED (1<<8) /* substitution was double-quoted + * (only used for testing early end of + * subscript) + */ +#define SCANPM_ARRONLY (1<<9) /* value is array but we don't + * necessarily want to match multiple + * elements + */ +#define SCANPM_ISVAR_AT ((-1)<<15) /* "$foo[@]"-style substitution + * Only sign bit is significant + */ /* * Flags for doing matches inside parameter substitutions, i.e. |