--- wget-1.11/src/progress.c 2008-01-26 12:26:58.000000000 +0300 +++ wget-1.11/src/progress.c.multibyte 2008-03-24 20:37:16.000000000 +0300 @@ -64,6 +64,7 @@ static void *bar_create (wgint, wgint); static void bar_update (void *, wgint, double); static void bar_finish (void *, double); static void bar_set_params (const char *); +static size_t buffer_calculate_size(wgint); static struct progress_implementation implementations[] = { { "dot", 0, dot_create, dot_update, dot_finish, dot_set_params }, @@ -505,6 +506,10 @@ struct bar_progress { measured since the beginning of download. */ + int buffer_size; /* buffer size we're using for the progress + gauge was created. it same as screen width + for single byte locales, but more for + multibyte locales.*/ int width; /* screen width we're using at the time the progress gauge was created. this is different from @@ -577,8 +582,10 @@ bar_create (wgint initial, wgint total) /* - 1 because we don't want to use the last screen column. */ bp->width = screen_width - 1; - /* + 1 for the terminating zero. */ - bp->buffer = xmalloc (bp->width + 1); + + /*allocate buffer */ + bp->buffer_size = buffer_calculate_size (bp->width); + bp->buffer = xmalloc (bp->buffer_size); logputs (LOG_VERBOSE, "\n"); @@ -621,7 +628,8 @@ bar_update (void *progress, wgint howmuc if (screen_width != old_width) { bp->width = screen_width - 1; - bp->buffer = xrealloc (bp->buffer, bp->width + 1); + bp->buffer_size = buffer_calculate_size (bp->width); + bp->buffer = xrealloc (bp->buffer, bp->buffer_size); force_screen_update = true; } received_sigwinch = 0; @@ -969,7 +977,7 @@ create_image (struct bar_progress *bp, d move_to_end (p); } - assert (p - bp->buffer <= bp->width); + assert (p - bp->buffer <= bp->buffer_size); while (p < bp->buffer + bp->width) *p++ = ' '; @@ -1023,6 +1031,17 @@ bar_set_params (const char *params) } } +/* calculate sizeof buffer for bar */ +static size_t buffer_calculate_size (wgint output_width) +{ + size_t eta_len = strlen(_(" eta %s")); + /* + 1 for the terminating zero. + " eta 36m 51s" - ETA - 13 chars, but this is with time," + get 8 for single byte locales and more if locale is multibyte + */ + return (output_width + MAX(8, eta_len) - 8 + 1); +} + #ifdef SIGWINCH void progress_handle_sigwinch (int sig)