changeset 1397:3fb99aaae28b draft

Don't go into an endless loop if we hit a bad utf8 sequence without -q.
author Rob Landley <rob@landley.net>
date Sun, 20 Jul 2014 22:08:46 -0500
parents e0c9c5424864
children 7402cae7889f
files toys/posix/ls.c
diffstat 1 files changed, 5 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/toys/posix/ls.c	Sun Jul 20 21:34:49 2014 -0500
+++ b/toys/posix/ls.c	Sun Jul 20 22:08:46 2014 -0500
@@ -75,12 +75,12 @@
     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;