zsh-workers
 help / color / mirror / code / Atom feed
* Infinite loop in dopadding() with doublewidth chars, probably since (mm)
@ 2010-09-28 22:51 Mikael Magnusson
  2010-10-02 18:41 ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Mikael Magnusson @ 2010-09-28 22:51 UTC (permalink / raw)
  To: zsh workers

Trying to pad a string to a width with a double-width character that
can't be done results in an infinite loop, where old versions just
left it one character too narrow. For example:
echo ${(ml:10::ま:):-hello}

dopadding() seems to consist mostly of special cases, but i ended up
around line 990,

 986 if ((m = f % lpremul)) {
here f is 5 "hello", lpremul is 2 "ま", so m is 1
 987     /*
 988      * Some fraction of the repeated string needed.
 989      */
 990     /* Need this much... */
 991     c = m;
 992     /* ...skipping this much first. */
 993     m = lpremul - m;
m is still 1 here
 994     MB_METACHARINIT();
 995     for (t = premul; m > 0; ) {
 996         t += MB_METACHARLENCONV(t, &cchar);
this advances t 3 bytes, pointing directly at the null after the ま
 997         m -= WCPADWIDTH(cchar, multi_width);
this subtracts 2 from m, leaving -1
 998     }
 999     /* Now the rest of the repeated string. */
1000     while (c > 0) {
c is still 1 here
1001         cl = MB_METACHARLENCONV(t, &cchar);
this is 0, remember t is ""
1002         while (cl--)
1003             *r++ = *t++;
1004         c -= WCPADWIDTH(cchar, multi_width);
which means c is decremented by 0 here
1005     }
1006 }

I didn't get much further than this. I didn't even dare look in how
many places some similar code exists in the function. :)

-- 
Mikael Magnusson


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

end of thread, other threads:[~2010-10-02 19:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-28 22:51 Infinite loop in dopadding() with doublewidth chars, probably since (mm) Mikael Magnusson
2010-10-02 18:41 ` 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).