aboutsummaryrefslogtreecommitdiff
path: root/toys/posix
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2014-07-20 22:08:46 -0500
committerRob Landley <rob@landley.net>2014-07-20 22:08:46 -0500
commit31db579265fa9e0acea036faa486be26f508e67a (patch)
tree5d407d0add904ce50cb10405399dbef3723ea7e8 /toys/posix
parent4a86c8193bf05646cdca9faa5253c607d6df5d35 (diff)
downloadtoybox-31db579265fa9e0acea036faa486be26f508e67a.tar.gz
Don't go into an endless loop if we hit a bad utf8 sequence without -q.
Diffstat (limited to 'toys/posix')
-rw-r--r--toys/posix/ls.c10
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;