diff lib/wcswidth-impl.h @ 14418:07a5551df5ac

wcswidth, mbswidth: Avoid integer overflow. * lib/wcswidth.c: Include <limits.h>. * lib/wcswidth-impl.h (wcswidth): Avoid 'int' overflow. * lib/mbswidth.c: Include <limits.h>. (mbsnwidth): Avoid 'int' overflow. Reported by Jim Meyering.
author Bruno Haible <bruno@clisp.org>
date Sat, 12 Mar 2011 13:54:43 +0100
parents 7357862f4745
children 8250f2777afc
line wrap: on
line diff
--- a/lib/wcswidth-impl.h
+++ b/lib/wcswidth-impl.h
@@ -28,6 +28,8 @@
         int width = wcwidth (c);
         if (width < 0)
           goto found_nonprinting;
+        if (width > INT_MAX - count)
+          goto overflow;
         count += width;
       }
     }
@@ -35,4 +37,7 @@
 
  found_nonprinting:
   return -1;
+
+ overflow:
+  return INT_MAX;
 }