File bash-2.05b-mbutil.patch of Package compat-readline4

|			     BASH PATCH REPORT
|			     =================
|
|Bash-Release: 2.05b
|Patch-ID: bash205b-005
|
|Bug-Reported-by:	Jim Meyering <jim@meyering.net>
|Bug-Reference-ID:	<87bs6v8iib.fsf@pixie.eng.ascend.com>
|Bug-Reference-URL:	http://mail.gnu.org/archive/html/bug-bash/2002-09/msg00047.html
|
|Bug-Description:
|
|When in a locale with multibyte characters, the readline display updater
|will occasionally cause a segmentation fault when attempting to compute
|the length of the first multibyte character on the line.
|
|Patch:
--- lib/readline/mbutil.c
+++ lib/readline/mbutil.c	Thu Mar 25 15:59:43 2004
@@ -205,14 +205,16 @@
   if (tmp == (size_t)(-2))
     {
       /* shorted to compose multibyte char */
-      memset (ps, 0, sizeof(mbstate_t));
+      if (ps)
+	memset (ps, 0, sizeof(mbstate_t));
       return -2;
     }
   else if (tmp == (size_t)(-1))
     {
       /* invalid to compose multibyte char */
       /* initialize the conversion state */
-      memset (ps, 0, sizeof(mbstate_t));
+      if (ps)
+	memset (ps, 0, sizeof(mbstate_t));
       return -1;
     }
   else if (tmp == (size_t)0)
@@ -225,9 +227,12 @@
    return 1. Otherwise return 0. */
 int
 _rl_compare_chars (buf1, pos1, ps1, buf2, pos2, ps2)
-     char *buf1, *buf2;
-     mbstate_t *ps1, *ps2;
-     int pos1, pos2;
+     char *buf1;
+     int pos1;
+     mbstate_t *ps1;
+     char *buf2;
+     int pos2;
+     mbstate_t *ps2;
 {
   int i, w1, w2;
 
@@ -276,8 +281,11 @@
 	  pos++;
 	  /* clear the state of the byte sequence, because
 	     in this case effect of mbstate is undefined  */
-	  memset (ps, 0, sizeof (mbstate_t));
+	  if (ps)
+	    memset (ps, 0, sizeof (mbstate_t));
 	}
+      else if (tmp == 0)
+	pos++;
       else
 	pos += tmp;
     }