From 31db579265fa9e0acea036faa486be26f508e67a Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 20 Jul 2014 22:08:46 -0500 Subject: Don't go into an endless loop if we hit a bad utf8 sequence without -q. --- toys/posix/ls.c | 10 +++++----- 1 file 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; -- cgit v1.2.3