Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: 3.1.5 - Re: BUG with associative arrays



On Nov 16,  2:20pm, Sven Wischnowsky wrote:
} Subject: BUG with associative arrays
} 
} Try:
} 
}   % foo[a]=a
}   % typeset -A foo
}   % foo[a]=a
}   % echo $foo      # or: $foo[(r)?]

It was worse than that:

    % foo=8
    % typeset -A foo
    % foo[a]=a
    segmentation fault

Here's the fix.  Note that typeset accepts the syntax

    % typeset -A foo=12

but simply throws away the value being assigned, because setsparam() does
nothing when handed an associative array.

Index: Src/builtin.c
===================================================================
--- builtin.c	1998/11/12 09:21:34	1.8
+++ builtin.c	1998/11/16 17:45:40
@@ -1501,6 +1501,8 @@
 	off |= PM_LOWER;
     if (on & PM_LOWER)
 	off |= PM_UPPER;
+    if (on & PM_HASHED)
+	off |= PM_ARRAY;
     on &= ~off;
 
     /* Given no arguments, list whatever the options specify. */
@@ -1543,6 +1545,12 @@
 			    if (PM_TYPE(pm->flags) == PM_ARRAY && (on & PM_UNIQUE) &&
 				!(pm->flags & PM_READONLY & ~off))
 				uniqarray((*pm->gets.afn) (pm));
+			    if ((on & ~pm->flags) & PM_HASHED) {
+				char *nam = ztrdup(pm->nam);
+				unsetparam(nam);
+				pm = createparam(nam, on & ~PM_READONLY);
+				DPUTS(!pm, "BUG: parameter not created");
+			    }
 			    pm->flags = (pm->flags | on) & ~off;
 			    if (PM_TYPE(pm->flags) != PM_ARRAY &&
 				PM_TYPE(pm->flags) != PM_HASHED) {
@@ -1594,7 +1602,8 @@
 	    (((pm->flags & PM_SPECIAL) && pm->level == locallevel) ||
 	     (!(pm->flags & PM_UNSET) &&
 	      ((locallevel == pm->level) || func == BIN_EXPORT) &&
-	      !(bit = ((off & pm->flags) | (on & ~pm->flags)) & PM_INTEGER)))) {
+	      !(bit = (((off & pm->flags) | (on & ~pm->flags)) &
+		       (PM_INTEGER|PM_HASHED)))))) {
 	    /* if no flags or values are given, just print this parameter */
 	    if (!on && !roff && !asg->value) {
 		paramtab->printnode((HashNode) pm, 0);

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



Messages sorted by: Reverse Date, Date, Thread, Author