Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 Nov 2004 06:18:19 +0900
From:      Wataru Gotoh <gotow@nifty.com>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   ports/74537: editors/vim issue: report invalid size of multi-byte character
Message-ID:  <20041129211819.GA34557%gotow@nifty.com>
Resent-Message-ID: <200411292120.iATLK1nE008090@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         74537
>Category:       ports
>Synopsis:       editors/vim issue: report invalid size of multi-byte character
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Nov 29 21:20:01 GMT 2004
>Closed-Date:
>Last-Modified:
>Originator:     Wataru Gotoh
>Release:        FreeBSD 5.3-RELEASE-p1 i386
>Organization:
>Environment:
System: GENERIC kernel.

>Description:
editors/vim on FreeBSD 5-stable (include 5.3R) report invalid size of multi-byte character.
this issue poses some problem, on display text, on moving cursor, and more.
vim call "mblen()" for make "mb_bytelen_tab" table at vim63/src/mbyte.c in function named mb_init().
current spec of mblen() is not suppose for make this table.

>How-To-Repeat:
test code of make table.

#include <stdio.h>
#include <stdlib.h>
#include <locale.h>

int main(void)
{
   int i, n;
   char buf[2];

   fprintf(stdout, "%s\n", setlocale(LC_ALL, "ja_JP.eucJP"));
   
   for (i = 0; i < 256; i++) {
      buf[0] = i;
      buf[1] = '\0';
      if (i == '\0') {
         n = 1;
      } else {
         if (mblen(buf, (size_t)1) <= 0) {
            n = 2;
         } else {
            n = 1;
         }
      }
      fprintf(stdout, "%d,", n);

      if ((i + 1) % 32 == 0) {
         fprintf(stdout, "\n");
      }
   }

   return 0;
}

valid case: (on 5.2.1R)
ja_JP.eucJP
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1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mbyte_c vim/files/patch-mbyte_c
--- vim.orig/files/patch-mbyte_c	Thu Jan  1 09:00:00 1970
+++ vim/files/patch-mbyte_c	Tue Nov 30 04:16:47 2004
@@ -0,0 +1,10 @@
+--- mbyte.c.orig	Sun Nov 28 20:40:35 2004
++++ mbyte.c	Sun Nov 28 20:42:49 2004
+@@ -650,6 +650,7 @@
+ 		     * where mblen() returns 0 for invalid character.
+ 		     * Therefore, following condition includes 0.
+ 		     */
++		    mblen(NULL, 0);
+ 		    if (mblen(buf, (size_t)1) <= 0)
+ 			n = 2;
+ 		    else

>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20041129211819.GA34557%gotow>