]> sjero.net Git - wget/blobdiff - src/progress.c
Remove screenwidth assertion from create_image.
[wget] / src / progress.c
index d77f99b6951d12b7c63360704c86a21e2ac2f413..bbbad179975fcbd8b79c7b8b1ba31d197b7f61db 100644 (file)
@@ -767,10 +767,7 @@ update_speed_ring (struct bar_progress *bp, wgint howmuch, double dltime)
 #endif
 }
 
-#if ! HAVE_WCWIDTH
-#define wcwidth(wc) (1)
-#endif
-
+#if USE_NLS_PROGRESS_BAR
 int
 count_cols (const char *mbs)
 {
@@ -778,16 +775,27 @@ count_cols (const char *mbs)
   int     bytes;
   int     remaining = strlen(mbs);
   int     cols = 0;
+  int     wccols;
 
   while (*mbs != '\0')
     {
       bytes = mbtowc (&wc, mbs, remaining);
+      assert (bytes != 0);  /* Only happens when *mbs == '\0' */
+      if (bytes == -1)
+        {
+          /* Invalid sequence. We'll just have to fudge it. */
+          return cols + remaining;
+        }
       mbs += bytes;
       remaining -= bytes;
-      cols += wcwidth(wc);
+      wccols = wcwidth(wc);
+      cols += (wccols == -1? 1 : wccols);
     }
   return cols;
 }
+#else
+# define count_cols(mbs) ((int)(strlen(mbs)))
+#endif
 
 /* Translation note: "ETA" is English-centric, but this must
    be short, ideally 3 chars.  Abbreviate if necessary.  */
@@ -803,7 +811,11 @@ get_eta (void)
       int nbytes;
       int ncols;
 
+#if USE_NLS_PROGRESS_BAR
       eta_trans = _(eta_str);
+#else
+      eta_trans = eta_str;
+#endif
 
       /* Determine the number of bytes used in the translated string,
        * versus the number of columns used. This is to figure out how
@@ -1035,8 +1047,6 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done)
       move_to_end (p);
     }
 
-  assert (p - bp->buffer - bytes_cols_diff - size_grouped_diff <= bp->width);
-
   while (p - bp->buffer - bytes_cols_diff - size_grouped_diff < bp->width)
     *p++ = ' ';
   *p = '\0';