From 58f9f0495ae8de5bc221e4afaa543132bc149bc4 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 6 Mar 2008 10:30:30 +0100 Subject: [PATCH] for_each_file() fix We will deref ->files one beyond the allocated length due to the way that C for(;;) loops work. So rework it a bit to make it more safe and not look beyond the array. We didn't touch the memory before, but it was still somewhat ugly. Signed-off-by: Jens Axboe --- fio.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fio.h b/fio.h index e7e32cc7..0cf5334b 100644 --- a/fio.h +++ b/fio.h @@ -961,7 +961,9 @@ extern void close_ioengine(struct thread_data *); #define for_each_td(td, i) \ for ((i) = 0, (td) = &threads[0]; (i) < (int) thread_number; (i)++, (td)++) #define for_each_file(td, f, i) \ - for ((i) = 0, (f) = (td)->files[0]; (i) < (td)->o.nr_files; (i)++, (f) = (td)->files[i]) + for ((i) = 0, (f) = (td)->files[0]; \ + (i) < (td)->o.nr_files && ((f) = (td)->files[i]) != NULL; \ + (i)++) #define fio_assert(td, cond) do { \ if (!(cond)) { \ -- 2.25.1