Ensure we have enough room for the ETA runstr
authorJens Axboe <axboe@fb.com>
Tue, 24 Jun 2014 01:07:12 +0000 (19:07 -0600)
committerJens Axboe <axboe@fb.com>
Tue, 24 Jun 2014 01:07:12 +0000 (19:07 -0600)
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 <andreas.gruenbacher@gmail.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
eta.c
server.c
stat.h

diff --git a/eta.c b/eta.c
index 0dd04be8d7a6506443a369233718bbea7937a5a3..dfe66f9e8ffbb455efe44de1b800c8e037c87895 100644 (file)
--- 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);
 
index 8865502520cb7f1fe2a8315bf8c9c79c54e346a7..e20f5921b6b4994f30fef52ab3a75235db7a16cd 100644 (file)
--- 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 3f68305adb2841c3aac8f98de942be94b8e23d5b..2c2f1e1a5e2c4e8be3fa375997c7c9d900a1bc4a 100644 (file)
--- 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