From 111558579a2f1965ff3f6a67ecb8ee4b596a4f88 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Mon, 23 Jun 2014 19:07:12 -0600 Subject: [PATCH] Ensure we have enough room for the ETA runstr MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The calculation of 1:4 is wrong, it's 1:5. And we missed the similar change in server.c. Reported-by: Andreas Grünbacher Signed-off-by: Jens Axboe --- eta.c | 6 +++--- server.c | 2 +- stat.h | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/eta.c b/eta.c index 0dd04be8..dfe66f9e 100644 --- a/eta.c +++ b/eta.c @@ -10,9 +10,9 @@ static char __run_str[REAL_MAX_JOBS + 1]; /* - * Worst level condensing would be 1:4, so allow enough room for that + * Worst level condensing would be 1:5, so allow enough room for that */ -static char run_str[(4 * REAL_MAX_JOBS) + 1]; +static char run_str[__THREAD_RUNSTR_SZ(REAL_MAX_JOBS)]; static void update_condensed_str(char *run_str, char *run_str_condensed) { @@ -592,7 +592,7 @@ void print_thread_status(void) if (!thread_number) return; - size = sizeof(*je) + thread_number * sizeof(char) + 1; + size = sizeof(*je) + THREAD_RUNSTR_SZ; je = malloc(size); memset(je, 0, size); diff --git a/server.c b/server.c index 88655025..e20f5921 100644 --- a/server.c +++ b/server.c @@ -673,7 +673,7 @@ static int handle_send_eta_cmd(struct fio_net_cmd *cmd) if (!thread_number) return 0; - size = sizeof(*je) + thread_number * sizeof(char) + 1; + size = sizeof(*je) + THREAD_RUNSTR_SZ; je = malloc(size); memset(je, 0, size); diff --git a/stat.h b/stat.h index 3f68305a..2c2f1e1a 100644 --- a/stat.h +++ b/stat.h @@ -241,4 +241,7 @@ static inline int usec_to_msec(unsigned long *min, unsigned long *max, return 1; } +#define __THREAD_RUNSTR_SZ(nr) (((nr) * 5) + 1) +#define THREAD_RUNSTR_SZ __THREAD_RUNSTR_SZ(thread_number) + #endif -- 2.25.1