From: Micah Cowan Date: Sun, 3 Feb 2008 09:28:05 +0000 (-0800) Subject: Handle error codes from mbtowc, wcwidth. X-Git-Tag: v1.13~461 X-Git-Url: http://sjero.net/git/?p=wget;a=commitdiff_plain;h=f74d743345c1293482d683ab0e57af4525c2e0d6 Handle error codes from mbtowc, wcwidth. --- diff --git a/src/progress.c b/src/progress.c index d77f99b6..2db82fda 100644 --- a/src/progress.c +++ b/src/progress.c @@ -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; }