diff options
author | Rob Landley <rob@landley.net> | 2014-07-20 22:08:46 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2014-07-20 22:08:46 -0500 |
commit | 31db579265fa9e0acea036faa486be26f508e67a (patch) | |
tree | 5d407d0add904ce50cb10405399dbef3723ea7e8 | |
parent | 4a86c8193bf05646cdca9faa5253c607d6df5d35 (diff) | |
download | toybox-31db579265fa9e0acea036faa486be26f508e67a.tar.gz |
Don't go into an endless loop if we hit a bad utf8 sequence without -q.
-rw-r--r-- | toys/posix/ls.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/toys/posix/ls.c b/toys/posix/ls.c index b955c41d..3a7de63d 100644 --- a/toys/posix/ls.c +++ b/toys/posix/ls.c @@ -75,12 +75,12 @@ int strwidth(char *s) len = mbrtowc(&c, s, MB_CUR_MAX, 0); if (len < 1 || (width = wcwidth(c)) < 0) { total++; - if (toys.optflags & FLAG_q) *(s++) = '?'; - - continue; + if (toys.optflags & FLAG_q) *s = '?'; + s++; + } else { + s += len; + total += width; } - s += len; - total += width; } return total; |