]> sjero.net Git - wget/commitdiff
Handle error codes from mbtowc, wcwidth.
authorMicah Cowan <micah@cowan.name>
Sun, 3 Feb 2008 09:28:05 +0000 (01:28 -0800)
committerMicah Cowan <micah@cowan.name>
Sun, 3 Feb 2008 09:28:05 +0000 (01:28 -0800)
src/progress.c

index d77f99b6951d12b7c63360704c86a21e2ac2f413..2db82fda35820e5ee8d4090d0a9fdc66e3ff46b6 100644 (file)
@@ -778,13 +778,21 @@ count_cols (const char *mbs)
   int     bytes;
   int     remaining = strlen(mbs);
   int     cols = 0;
+  int     wccols;
 
   while (*mbs != '\0')
     {
       bytes = mbtowc (&wc, mbs, remaining);
+      assert (bytes != 0);  /* Only happens when *mbs == '\0' */
+      if (bytes == -1)
+        {
+          /* Invalid sequence. We'll just have to fudge it. */
+          return cols + remaining;
+        }
       mbs += bytes;
       remaining -= bytes;
-      cols += wcwidth(wc);
+      wccols = wcwidth(wc);
+      cols += (wccols == -1? 1 : wccols);
     }
   return cols;
 }