]> Savannah Git Hosting - gnulib.git/commitdiff
wcswidth: Fix result in case of overflow.
authorBruno Haible <bruno@clisp.org>
Thu, 4 May 2023 21:22:14 +0000 (23:22 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 4 May 2023 21:22:14 +0000 (23:22 +0200)
* lib/wcswidth-impl.h (wcswidth): Continue searching for a non-printing
wide character after the total width has become > INT_MAX.

ChangeLog
lib/wcswidth-impl.h

index d41aa0bb28f21351c2feb546cd416179175fd656..af99e65a659ea6535da2805e62f09b6d0d997f57 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2023-05-04  Bruno Haible  <bruno@clisp.org>
+
+       wcswidth: Fix result in case of overflow.
+       * lib/wcswidth-impl.h (wcswidth): Continue searching for a non-printing
+       wide character after the total width has become > INT_MAX.
+
 2023-05-04  Bruno Haible  <bruno@clisp.org>
 
        wcswidth: Relax license.
index 644a093a7e3916245c049d1e6f295b09ab214091..a879bfdd936f23f4bc73329b9250b9a0a50b739e 100644 (file)
@@ -35,9 +35,22 @@ wcswidth (const wchar_t *s, size_t n)
     }
   return count;
 
+  /* The total width has become > INT_MAX.
+     Continue searching for a non-printing wide character.  */
+  for (; n > 0; s++, n--)
+    {
+      wchar_t c = *s;
+      if (c == (wchar_t)'\0')
+        break;
+      {
+        int width = wcwidth (c);
+        if (width < 0)
+          goto found_nonprinting;
+      }
+     overflow: ;
+    }
+  return INT_MAX;
+
  found_nonprinting:
   return -1;
-
- overflow:
-  return INT_MAX;
 }