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

Re: 3 bugs for zsh3.0.0



-----BEGIN PGP SIGNED MESSAGE-----

>2) bus error on:
>local undefined
>echo ${undefined#crap}

The parameter code, when asked for the value of an undefined parameter,
is returning a constant empty string.  The glob code assumes that it can
write into any parameter value.  The real solution would be to stop the
glob code writing into strings that it shouldn't modify, and I'd like
to do this as part of making zsh const-correct.  But for the moment it
will suffice to make the parameter code return an allocated empty string,
as it already does in some cases.

 -zefram

      *** Src/params.c	1997/03/17 00:38:10	1.36
      --- Src/params.c	1997/03/17 13:16:13
      ***************
      *** 677,685 ****
            char *s, **ss;
            static char buf[(SIZEOF_LONG * 8) + 4];
        
      -     if (!v)
      - 	return "";
            HEAPALLOC {
        	if (v->inv) {
        	    sprintf(buf, "%d", v->a);
        	    s = dupstring(buf);
      --- 677,685 ----
            char *s, **ss;
            static char buf[(SIZEOF_LONG * 8) + 4];
        
            HEAPALLOC {
      + 	if (!v)
      + 	    return dupstring("");
        	if (v->inv) {
        	    sprintf(buf, "%d", v->a);
        	    s = dupstring(buf);
      ***************
      *** 694,700 ****
        		ss = v->pm->gets.afn(v->pm);
        		if (v->a < 0)
        		    v->a += arrlen(ss);
      ! 		s = (v->a >= arrlen(ss) || v->a < 0) ? "" : ss[v->a];
        	    }
        	    LASTALLOC_RETURN s;
        	case PM_INTEGER:
      --- 694,700 ----
        		ss = v->pm->gets.afn(v->pm);
        		if (v->a < 0)
        		    v->a += arrlen(ss);
      ! 		s = (v->a >= arrlen(ss) || v->a < 0) ? dupstring("") : ss[v->a];
        	    }
        	    LASTALLOC_RETURN s;
        	case PM_INTEGER:
      ***************
      *** 1188,1194 ****
        char *
        strgetfn(Param pm)
        {
      !     return pm->u.str ? pm->u.str : "";
        }
        
        /* Function to set value of a scalar (string) parameter */
      --- 1188,1194 ----
        char *
        strgetfn(Param pm)
        {
      !     return pm->u.str ? pm->u.str : hcalloc(1);
        }
        
        /* Function to set value of a scalar (string) parameter */
      ***************
      *** 1314,1320 ****
            char *s = *((char **)pm->data);
        
            if (!s)
      ! 	return "";
            return s;
        }
        
      --- 1314,1320 ----
            char *s = *((char **)pm->data);
        
            if (!s)
      ! 	return hcalloc(1);
            return s;
        }
        

-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: ascii

iQCVAwUBMy1FZXD/+HJTpU/hAQE5kQP/aYmYQVr7bUhFhdjissNyzeFn1Bb6DpYG
Hs7X+VpQut8RkqoKXhe9Dqy3DW2xr1DhW9anNhOHkYf5Aqo0KhlNuB1stPrpi/tT
4pLIjxZUuGhQv3XShafyaxJoxGwWSnfXgBNa47zNVvsJAfMGs7UD+FR0KBAc7PXl
uPehnmaqnHg=
=ooJu
-----END PGP SIGNATURE-----



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