From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25316 invoked from network); 16 Jun 1997 18:47:05 -0000 Received: from euclid.skiles.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 16 Jun 1997 18:47:05 -0000 Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id OAA03937; Mon, 16 Jun 1997 14:30:04 -0400 (EDT) Resent-Date: Mon, 16 Jun 1997 14:30:04 -0400 (EDT) Date: Mon, 16 Jun 1997 19:33:56 +0100 (BST) From: Zefram Message-Id: <8796.199706161833@stone.dcs.warwick.ac.uk> Subject: paramsubst bug X-Patch: 262 Resent-Message-ID: <"-YEPt3.0.Sz.iOOfp"@euclid> To: zsh-workers@math.gatech.edu Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/3250 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu -----BEGIN PGP SIGNED MESSAGE----- % zsh <<< ' set a b c d e echo "$@" set "$@" echo "$@" ' | cat -v a b c d e a HM-^B^N^HPM-^B^N^H M-x[^N^H@M-^B^N^Hks PM-^B^N^H0M-^B^N^HM-0M-^A^N^HM-x[^N^HM-x[^N^H@M-^B^N^Hks e The bug is that the substitution of `"$@"' returns the original strings from pparams, rather than duplicating them. bin_set() frees pparams and then duplicates its arguments -- but freeing pparams also freed some of its arguments. set has had this behaviour that tickles this bug since 3.0.1-test, but the subst.c code is far older and there are undoubtedly other ways in which in can cause wrong behaviour. I think the correct solution is for paramsubst() to always duplicate the strings, rather than attempting this optimisation. The patch below fixes the array case, but there are very many code paths and I'm not sure if any others might fail to duplicate. (Look at the `copied' variable.) We could do with some comments in subst.c to indicate which functions can return their arguments unmodified. This patch applies to both 3.1.2 and 3.0.3. -zefram *** Src/subst.c 1997/06/14 00:25:43 1.29 --- Src/subst.c 1997/06/16 14:03:41 *************** *** 1453,1462 **** return NULL; if (qt && !*x && isarr != 2) y = dupstring(nulstring); ! else if (globsubst) ! tokenize(y = dupstring(x)); ! else ! y = x; insertlinknode(l, n, (void *) y), incnode(n); } --- 1453,1463 ---- return NULL; if (qt && !*x && isarr != 2) y = dupstring(nulstring); ! else { ! y = dupstring(x); ! if (globsubst) ! tokenize(y); ! } insertlinknode(l, n, (void *) y), incnode(n); } -----BEGIN PGP SIGNATURE----- Version: 2.6.3ia Charset: ascii iQEUAwUBM6VKHJmk9GeOHh7BAQH8TQf2PWpPMTKm0JjalDwMxFBeWkRJOTsMAllI ROeaTAhg6aULvbCIMBj/8hHWIz76/FA+ihaEkRQqFGm9QIa3VS1xmy+CE3+XoXH9 satQ5KUzabGL6doKrakb2v14ALrQZVCYKt7Mb4UeWU+FadMLtA0QeKp7XUBfMpNf ijh+x1bUnrHymyVuE0zFzrCbFubhcQ3U/BZNRNBSPntAQM5KHXN6t9WiBXzHzaPr RBbMTJPKzAPecPxXO2kgPA7Z5Qs2QcpPbg4/gCuNBEG4bPRPen/RziDpF6wzkTi8 kCThXm5Wk2wavQDgM6Vzb72FxA6jnmj/i+sQZIL9kFS7cU658gP3 =NbPr -----END PGP SIGNATURE-----