zsh-workers
 help / color / mirror / code / Atom feed
* word[-1]= breaks on multibyte?
@ 2010-10-08 21:20 Mikael Magnusson
  2010-10-10 17:20 ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Mikael Magnusson @ 2010-10-08 21:20 UTC (permalink / raw)
  To: zsh workers

% word=abcま
% echo $word
abcま
% echo $word[-1]
ま

so far so good, but
% word[-1]=
% echo $word
abc¾
% word=abcま
% word[-1]=a
% echo $word
abca¾
% word=abcま
% word[-2]=
% echo $word
abま

It seems like it finds the correct index, but the actual assignment
goes wrong. Only for negative indices though. Which is weird, I would
have thought the actual assignment was the same once it found the
spot.
% word=abなま
% word[-2]=c
% echo $word
abcªま
% word=abなま
% word[-1]=c
% echo $word
abなc¾
% word=abなま
% word[3]=c
% echo $word
abcま
% word=abなま
% word[4]=d
% echo $word
abなd


-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: word[-1]= breaks on multibyte?
  2010-10-08 21:20 word[-1]= breaks on multibyte? Mikael Magnusson
@ 2010-10-10 17:20 ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2010-10-10 17:20 UTC (permalink / raw)
  To: zsh workers

On Fri, 8 Oct 2010 23:20:30 +0200
Mikael Magnusson <mikachu@gmail.com> wrote:
> % word=abcま
> % word[-1]=
> % echo $word
> abc¾

The end index is recorded as the last character, not one beyond it.  We
need to increment it when we use it.  For assignment that's not
done properly.

It looked like there might have been a problem with indexing off the end
even without multibyte characters at that point.

There are no other references to MULTIBYTE_SUPPORT in params.c, so I
wouldn't be surprised if there were other problems like this.

Index: Src/params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/params.c,v
retrieving revision 1.162
diff -p -u -r1.162 params.c
--- Src/params.c	31 Aug 2010 19:32:57 -0000	1.162
+++ Src/params.c	10 Oct 2010 17:16:40 -0000
@@ -2275,9 +2275,22 @@ setstrvalue(Value v, char *val)
 	    if (v->start > zlen)
 		v->start = zlen;
 	    if (v->end < 0) {
-		v->end += zlen + 1;
-		if (v->end < 0)
+		v->end += zlen;
+		if (v->end < 0) {
 		    v->end = 0;
+		} else if (v->end >= zlen) {
+		    v->end = zlen;
+		} else {
+#ifdef MULTIBYTE_SUPPORT
+		    if (isset(MULTIBYTE)) {
+			v->end += MB_METACHARLEN(z + v->end);
+		    } else {
+			v->end++;
+		    }
+#else
+		    v->end++;
+#endif
+		}
 	    }
 	    else if (v->end > zlen)
 		v->end = zlen;
Index: Test/D07multibyte.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D07multibyte.ztst,v
retrieving revision 1.34
diff -p -u -r1.34 D07multibyte.ztst
--- Test/D07multibyte.ztst	24 Jul 2009 18:35:53 -0000	1.34
+++ Test/D07multibyte.ztst	10 Oct 2010 17:16:40 -0000
@@ -447,3 +447,21 @@
   print $(( [#16] #REPLY ))
 0:read passes through invalid multibyte characters
 >0xC5
+
+  word=abcま          
+  word[-1]=
+  print $word
+  word=abcま 
+  word[-2]=
+  print $word
+  word=abcま 
+  word[4]=d
+  print $word
+  word=abcま 
+  word[3]=not_c
+  print $word  
+0:assignment with negative indices
+>abc
+>abま
+>abcd
+>abnot_cま

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-10-10 17:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-08 21:20 word[-1]= breaks on multibyte? Mikael Magnusson
2010-10-10 17:20 ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).