Hi Bram,

On 8/12/06, Bram Moolenaar <[EMAIL PROTECTED]> wrote:
[...]
You may have uncovered a bug that went unnoticed so far.  Please try to
discover what causes this problem.  I can't guess why the last character
is messed up, looks strange.

I think I solved the problem! That was caused by iconv.

      size_t iconv(iconv_t cd,
                    char **inbuf, size_t *inbytesleft,
                    char **outbuf, size_t *outbytesleft);

The parameter "inbytesleft" and "outbytesleft" should all include the
trailing '\0' byte. In the previous version of gvim, we passed the
parameter as the length of the string, excluding the trailing '\0'. So
it is 1 byte less than the correct value.

As we know, every Chinese character is presented with 2 bytes in GBK encoding:

 AABBCCDD
 \------/
 4 characters

Because we passed the parameter as the length of the string (8 in this
example), so iconv treated the input string as 1 byte less (7 in this
example), then the 2nd but last letter was not able to be converted
because it is only half of a character, so gvim changed it to a
question mark:

 AABBCC?D

After that, gvim tried to convert the remaining 1 byte to the target
encoding but also failed. Then vim changed it to a question mark, too.

 AABBCC??

That is why every last character of the tooltip became 2 question
marks. Menu doesn't get malformed because most of the menu items are
not ended with a Chinese character. In fact, some menu item ends with
Chinese character also get malformed.

[...]

It's quite simple after finding out the problem. Here is the patch, in
which I also alias GBK and GB18030 to cp936. That solved the previous
problem I requested:

*** src/mbyte.c        2006-05-14 20:32:49.000000000 +0800
--- ../vim7.build/vim7/src/mbyte.c 2006-08-12 19:22:06.000000000 +0800
***************
*** 372,377 ****
--- 372,379 ----
     {"5601",          IDX_EUC_KR},    /* Sun: KS C 5601 */
     {"euccn",         IDX_EUC_CN},
     {"gb2312",                IDX_EUC_CN},
+     {"gbk",           IDX_CP936},
+     {"gb18030",               IDX_CP936},
     {"euctw",         IDX_EUC_TW},
 #if defined(WIN3264) || defined(WIN32UNIX) || defined(MACOS)
     {"japan",         IDX_CP932},
***************
*** 3250,3256 ****
       }

       to = (char *)result + done;
!       tolen = len - done - 2;
       /* Avoid a warning for systems with a wrong iconv() prototype by
        * casting the second argument to void *. */
       if (iconv(vcp->vc_fd, (void *)&from, &fromlen, &to, &tolen)
--- 3252,3259 ----
       }

       to = (char *)result + done;
!       tolen = len - done - 1;
!         ++fromlen;
       /* Avoid a warning for systems with a wrong iconv() prototype by
        * casting the second argument to void *. */
       if (iconv(vcp->vc_fd, (void *)&from, &fromlen, &to, &tolen)



Best Regards,

Edward L. Fox

Reply via email to