48 lines
1.5 KiB
Diff
48 lines
1.5 KiB
Diff
|
|
From 6bd74e33d6d0ccc43031405819a6766382823828 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Tim Rühsen <tim.ruehsen@gmx.de>
|
||
|
|
Date: Wed, 18 Dec 2019 13:06:46 +0100
|
||
|
|
Subject: [PATCH] Fix segfault in progress bar in certain locales
|
||
|
|
|
||
|
|
* src/progress.c (create_image): Protect memset from negative count
|
||
|
|
|
||
|
|
Reported-by: JunDong Xie
|
||
|
|
---
|
||
|
|
src/progress.c | 14 ++++++++++----
|
||
|
|
1 file changed, 10 insertions(+), 4 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/src/progress.c b/src/progress.c
|
||
|
|
index 80775b0c..63bebab8 100644
|
||
|
|
--- a/src/progress.c
|
||
|
|
+++ b/src/progress.c
|
||
|
|
@@ -1099,8 +1099,11 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done)
|
||
|
|
/* " 234.56M" */
|
||
|
|
down_size = human_readable (size, 1000, 2);
|
||
|
|
cols_diff = PROGRESS_FILESIZE_LEN - count_cols (down_size);
|
||
|
|
- memset (p, ' ', cols_diff);
|
||
|
|
- p += cols_diff;
|
||
|
|
+ if (cols_diff > 0)
|
||
|
|
+ {
|
||
|
|
+ memset (p, ' ', cols_diff);
|
||
|
|
+ p += cols_diff;
|
||
|
|
+ }
|
||
|
|
p += sprintf (p, "%s", down_size);
|
||
|
|
|
||
|
|
/* " 12.52Kb/s or 12.52KB/s" */
|
||
|
|
@@ -1182,8 +1185,11 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done)
|
||
|
|
else
|
||
|
|
ncols += sprintf (p + nbytes, "%ss", print_decimal (dl_total_time));
|
||
|
|
p += ncols + bytes_cols_diff;
|
||
|
|
- memset (p, ' ', PROGRESS_ETA_LEN - ncols);
|
||
|
|
- p += PROGRESS_ETA_LEN - ncols;
|
||
|
|
+ if (ncols < PROGRESS_ETA_LEN)
|
||
|
|
+ {
|
||
|
|
+ memset (p, ' ', PROGRESS_ETA_LEN - ncols);
|
||
|
|
+ p += PROGRESS_ETA_LEN - ncols;
|
||
|
|
+ }
|
||
|
|
}
|
||
|
|
|
||
|
|
padding = bp->width - count_cols (bp->buffer);
|
||
|
|
--
|
||
|
|
2.19.1.windows.1
|
||
|
|
|