-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Declaration command names break 2D indexed array assignments #792
Comments
This bug has been in ksh since forever as well. It also happens when |
The problem is that The diff --git a/src/cmd/ksh93/bltins/typeset.c b/src/cmd/ksh93/bltins/typeset.c
index 64880f865..d66a97c61 100644
--- a/src/cmd/ksh93/bltins/typeset.c
+++ b/src/cmd/ksh93/bltins/typeset.c
@@ -90,6 +90,7 @@ static void(*nullscan)(Namval_t*,void*);
#endif
int b_readonly(int argc,char *argv[],Shbltin_t *context)
{
+abort();
int flag;
char *command = argv[0];
struct tdata tdata;
|
So, the first thing that stands out is that However, on line 262, the This patch should fix that, and (in my testing) fixes the reproducer: diff --git a/src/cmd/ksh93/sh/name.c b/src/cmd/ksh93/sh/name.c
index 25d383b87..72b42cbbc 100644
--- a/src/cmd/ksh93/sh/name.c
+++ b/src/cmd/ksh93/sh/name.c
@@ -488,7 +488,7 @@ void nv_setlist(struct argnod *arg,int flags, Namval_t *typ)
if(!(array&NV_IARRAY) && !(tp->com.comset->argflag&ARG_MESSAGE))
nv_setarray(np,nv_associative);
}
- nv_setlist(tp->com.comset,flags&~NV_STATIC,0);
+ nv_setlist(tp->com.comset, flags & ~NV_STATIC | array & NV_IARRAY, 0);
sh.prefix = prefix;
if(tp->com.comset->argval[1]!='[')
nv_setvtree(np); |
Unfortunately, while the patch fixes the reproducer, it also causes regressions in compound variable handling. test comvar begins at 2024-11-05+20:35:13
comvar.sh[542]: FAIL: typeset -p with nested compound indexed array not working
/usr/local/src/ksh93/ksh/src/cmd/ksh93/tests/comvar.sh[587]: eval: syntax error at line 1: `)' unexpected
comvar.sh[588]: FAIL: print -C with multidimensional array not working
/usr/local/src/ksh93/ksh/src/cmd/ksh93/tests/comvar.sh[589]: eval: syntax error at line 2: `)' unexpected
comvar.sh[590]: FAIL: print -v with multidimensional array not working
comvar.sh[599]: FAIL: typeset -m not working with compound -a variable
comvar.sh[631]: FAIL: moving compound indexed array element to a compound associative array element fails
test comvar failed at 2024-11-05+20:35:13 with exit code 5 [ 104 tests 5 errors ]
test comvario begins at 2024-11-05+20:35:13
/usr/local/src/ksh93/ksh/src/cmd/ksh93/tests/comvario.sh[407]: test6[398]: read: syntax error at line 409: `)' unexpected
comvario.sh[398]: FAIL: test2/18: read -C val failed with exit code 3
/usr/local/src/ksh93/ksh/src/cmd/ksh93/tests/comvario.sh[407]: test6: line 400: aa: parameter not set
test comvario failed at 2024-11-05+20:35:15 with exit code 1 [ 72 tests 1 error ] |
Thankfully, compound variable assignments are conveniently flagged with the diff --git a/src/cmd/ksh93/sh/name.c b/src/cmd/ksh93/sh/name.c
index 25d383b87..ceaad5161 100644
--- a/src/cmd/ksh93/sh/name.c
+++ b/src/cmd/ksh93/sh/name.c
@@ -478,6 +478,7 @@ void nv_setlist(struct argnod *arg,int flags, Namval_t *typ)
{
if(tp->tre.tretyp!=TLST && !tp->com.comnamp && tp->com.comset && tp->com.comset->argval[0]==0 && tp->com.comset->argchn.ap)
{
+ int multidim_iarray;
if(prefix || np)
cp = stkcopy(sh.stk,nv_name(np));
sh.prefix = cp;
@@ -488,7 +489,8 @@ void nv_setlist(struct argnod *arg,int flags, Namval_t *typ)
if(!(array&NV_IARRAY) && !(tp->com.comset->argflag&ARG_MESSAGE))
nv_setarray(np,nv_associative);
}
- nv_setlist(tp->com.comset,flags&~NV_STATIC,0);
+ multidim_iarray = (flags & NV_COMVAR) ? 0 : (array & NV_IARRAY);
+ nv_setlist(tp->com.comset, flags & ~NV_STATIC | multidim_iarray, 0);
sh.prefix = prefix;
if(tp->com.comset->argval[1]!='[')
nv_setvtree(np); |
Sigh. Unfortunately, the fix is still incomplete at best:
Pre-patch output:
Expected output:
|
Repeating the abort() trick with the latest reproducer, we get the following call trace:
|
A declaration command name like
export
ortypeset
breaks multidimensional indexed array assignments, e.g.:Expected output:
Originally reported by @TristanJamesBall in #790 (comment)
The text was updated successfully, but these errors were encountered: