cc: [email protected]
Subject: Re: [ast-developers] ksh: problem with arrays
--------

> Hi,
> 
> one our user reported change in ksh's behavior. I've checked it and prepared 
> thi
> s simplified test case. Could you look at it? Thanks, Michal
> 
> Simplified test case:
> 
> typeset xx[7];
> echo ${#xx[@]}; 
> typeset -p xx; 
> xx[6]=hello; echo ${xx[6]}; 
> typeset -p xx; 
> xx[5]=world; echo ${xx[5]}; 
> typeset -p xx; 
> xx[8]=foo; typeset -p xx; 
> unset xx; typeset -p xx;
> echo ${#xx[@]}
> 
> ksh >=2010-10-10 prints: 
> 7 #why is that 7? bash,mksh, ksh<=2008-10-01 prints 0, ksh 2008-10-09 ... 
> 2010-0
> 9-24 prints 1
> typeset -a xx[7];xx=()
> <nothing> #should print hello
> typeset -a xx[7];xx=('' '' '' '' '' '' '') #definition unexpectedly changed 
> and 
> 'hello' is missing
> <nothing> #should print world
> typeset -a xx[7];xx=('' '' '' '' '' '' '')
> xx[5]: subscript out of range #why out of range? why xx[5] , this was 
> xx[8]=foo 
> assignment
> <nothing>
> 0
> 
> 
> ksh 2008-10-09 ... 2010-09-24 prints:
> 1
> typeset -a xx=([7]=)
> hello
> typeset -a xx=([6]=hello [7]=)
> world
> typeset -a xx=([5]=world [6]=hello [7]= [8]=foo)
> 0
> 
> 
> ksh <=2008-10-01 prints:
> 0
> typeset -a xx=([0]=)
> hello
> typeset -a xx=([6]=hello)
> world
> typeset -a xx=([5]=world [6]=hello [8]=foo)
> 0
> 
> 
> bash output for comparison:
> 0
> declare -a xx='()'
> hello
> declare -a xx='([6]="hello")'
> world
> declare -a xx='([5]="world" [6]="hello" [8]="foo")'
> bash: line 0: typeset: xx: not found
> 0
> 

This bug was already reported and is fixed for the first bug fix release of
ksh93u which will be distributed this quarter.

The problem is that the declaration

        typeset xx[7];

is incorrectly treating xx as a fixed size array of size 7 and currently
fixed sized arrays only for for fixed sized objects.  The declaration for
fixed size arrays should be
        typeset -a xx[7];
and the declaration
        typeset xx[7];
is not even necessary, but should not have been treated as a fixed array.

Therefore the workaround is to delete this declaration
or use the declaration
        typeset -a xx
instead.  This is also the cause of the core dump you reported with
typeset -p.

Here is a patch that should fix this problem.

========================cut here==========================
--- old/bltins/typeset.c        Thu Dec 30 19:15:57 2010
+++ new/bltins/typeset.c        Thu Mar  3 11:02:49 2011
@@ -568,7 +568,7 @@
                                
path_alias(np,path_absolute(shp,nv_name(np),NIL(Pathcomp_t*)));
                                continue;
                        }
-                       np = 
nv_open(name,troot,nvflags|((nvflags&NV_ASSIGN)?0:NV_ARRAY)|NV_FARRAY);
+                       np = 
nv_open(name,troot,nvflags|((nvflags&NV_ASSIGN)?0:NV_ARRAY)|(iarray?NV_FARRAY:0));
                        if(nv_isnull(np) && !nv_isarray(np) && 
nv_isattr(np,NV_NOFREE))
                                nv_offattr(np,NV_NOFREE);
                        if(tp->pflag)
========================cut here==========================


David Korn
[email protected]
_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers

Reply via email to