1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

Handle error codes from mbtowc, wcwidth.

This commit is contained in:
Micah Cowan 2008-02-03 01:28:05 -08:00
parent 35b72cc941
commit f74d743345

View File

@ -778,13 +778,21 @@ count_cols (const char *mbs)
int bytes; int bytes;
int remaining = strlen(mbs); int remaining = strlen(mbs);
int cols = 0; int cols = 0;
int wccols;
while (*mbs != '\0') while (*mbs != '\0')
{ {
bytes = mbtowc (&wc, mbs, remaining); 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; mbs += bytes;
remaining -= bytes; remaining -= bytes;
cols += wcwidth(wc); wccols = wcwidth(wc);
cols += (wccols == -1? 1 : wccols);
} }
return cols; return cols;
} }