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

Re: [bug-report] brace_ccl and $'\0' in ranges



Stephane Chazelas wrote:
> [message sent to Peter Stephenson and zsh-workers ML, even if
> it will probably never show up on the ML for a reason I don't
> know of]

Possibly @free.fr is not a very felicitous domain from the point of view
of the spam checker at Sunsite.  (I'm assuming you're reading the list
so haven't copied it.)

> ~$ setopt brace_ccl
> ~$ print -rn {$'\1'-$'\37'} | od -c # works OK
> 0000000 001     002     003     004     005     006      \a      \b
> 0000020  \t      \n      \v      \f      \r     016     017     020
> 0000040 021     022     023     024     025     026     027     030
> 0000060 031     032     033     034     035     036     037
> 0000075
> ~$ print -rn {$'\0'-$'\37'} | od -c
> 0000000  \0     037       -
> 0000005
> 
> tested with 4.1.1-dev-1, CVS tree from 2003/09/22.

Yes, the test for termination is pre-eight-bit and uses zero as the
termination condition instead of a number out of the range of an
unsigned char.  Hope I've got the signed/unsigned stuff right; gcc isn't
complaining, anyway.  There's a new test for this.

I got a bit worried there was somewhere that a $'\000' assigned to a
scalar parameter wasn't being expaned properly, but maybe I got confused.

Index: Src/glob.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/glob.c,v
retrieving revision 1.30
diff -u -r1.30 glob.c
--- Src/glob.c	1 Aug 2003 14:14:20 -0000	1.30
+++ Src/glob.c	6 Oct 2003 22:02:49 -0000
@@ -1867,12 +1867,13 @@
 	 * set of flags saying whether each character is present; *
 	 * the final list is in lexical order.                    */
 	char ccl[256], *p;
-	unsigned char c1, c2, lastch;
+	unsigned char c1, c2;
 	unsigned int len, pl;
+	int lastch = -1;
 
 	uremnode(list, node);
 	memset(ccl, 0, sizeof(ccl) / sizeof(ccl[0]));
-	for (p = str + 1, lastch = 0; p < str2;) {
+	for (p = str + 1; p < str2;) {
 	    if (itok(c1 = *p++))
 		c1 = ztokens[c1 - STOUC(Pound)];
 	    if ((char) c1 == Meta)
@@ -1881,22 +1882,21 @@
 		c2 = ztokens[c2 - STOUC(Pound)];
 	    if ((char) c2 == Meta)
 		c2 = 32 ^ p[1];
-	    if (c1 == '-' && lastch && p < str2 && (int)lastch <= (int)c2) {
-		while ((int)lastch < (int)c2)
+	    if (c1 == '-' && lastch >= 0 && p < str2 && lastch <= (int)c2) {
+		while (lastch < (int)c2)
 		    ccl[lastch++] = 1;
-		lastch = 0;
+		lastch = -1;
 	    } else
 		ccl[lastch = c1] = 1;
 	}
Index: Test/E01options.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/E01options.ztst,v
retrieving revision 1.11
diff -u -r1.11 E01options.ztst
--- Test/E01options.ztst	16 Mar 2002 19:43:36 -0000	1.11
+++ Test/E01options.ztst	6 Oct 2003 22:03:15 -0000
@@ -154,6 +154,19 @@
 >a b c d
 >{abcd}
 
+# Don't use NUL as a field separator in the following.
+  setopt braceccl
+  print {$'\0'-$'\5'} | IFS=' ' read -A chars
+  for c in $chars; do print $(( #c )); done
+  unsetopt braceccl
+0:BRACE_CCL option starting from NUL
+>0
+>1
+>2
+>3
+>4
+>5
+
   setopt bsdecho
   echo "histon\nimpington"
   echo -e "girton\ncottenham"

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxx>
Work: pws@xxxxxxx
Web: http://www.pwstephenson.fsnet.co.uk



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