(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 f196ac18dc21e4c342fef6bd4ccb631a97fc719d..bb6aa1a6d8e83587591ca558483f212d371be947 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;
                      }