Fix off-by-one in jobs_eta allocation
Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/eta.c b/eta.c
index b7f1fd6..6118d1a 100644
--- a/eta.c
+++ b/eta.c
@@ -418,10 +418,14 @@
void print_thread_status(void)
{
struct jobs_eta *je;
+ size_t size;
- je = malloc(sizeof(*je) + thread_number * sizeof(char));
+ if (!thread_number)
+ return;
- memset(je, 0, sizeof(*je) + thread_number * sizeof(char));
+ size = sizeof(*je) + thread_number * sizeof(char) + 1;
+ je = malloc(size);
+ memset(je, 0, size);
if (calc_thread_status(je, 0))
display_thread_status(je);
diff --git a/server.c b/server.c
index ac6c2fb..2c20e37 100644
--- a/server.c
+++ b/server.c
@@ -409,7 +409,10 @@
size_t size;
int i;
- size = sizeof(*je) + thread_number * sizeof(char);
+ if (!thread_number)
+ return 0;
+
+ size = sizeof(*je) + thread_number * sizeof(char) + 1;
je = malloc(size);
memset(je, 0, size);