OSDN Git Service

Don't go into an endless loop if we hit a bad utf8 sequence without -q.
authorRob Landley <rob@landley.net>
Mon, 21 Jul 2014 03:08:46 +0000 (22:08 -0500)
committerRob Landley <rob@landley.net>
Mon, 21 Jul 2014 03:08:46 +0000 (22:08 -0500)
toys/posix/ls.c

index b955c41..3a7de63 100644 (file)
@@ -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;