(mbsnwidth): Don't loop endlessly when called with an
authorJim Meyering <jim@meyering.net>
Fri, 8 Dec 2000 18:31:38 +0000 (18:31 +0000)
committerJim Meyering <jim@meyering.net>
Fri, 8 Dec 2000 18:31:38 +0000 (18:31 +0000)
invalid mulitbyte sequence and with the MBSW_ACCEPT_INVALID flag set.

lib/mbswidth.c

index f196ac1..bb6aa1a 100644 (file)
@@ -153,7 +153,11 @@ mbsnwidth (const char *string, size_t nbytes, int flags)
                      /* An invalid multibyte sequence was encountered.  */
                      {
                        if (flags & MBSW_ACCEPT_INVALID)
-                         break;
+                         {
+                           p++;
+                           width++;
+                           break;
+                         }
                        else
                          return -1;
                      }
@@ -162,7 +166,11 @@ mbsnwidth (const char *string, size_t nbytes, int flags)
                      /* An incomplete multibyte character at the end.  */
                      {
                        if (flags & MBSW_ACCEPT_INVALID)
-                         break;
+                         {
+                           p = plimit;
+                           width++;
+                           break;
+                         }
                        else
                          return -1;
                      }