From: Jens Axboe Date: Thu, 6 Mar 2008 09:30:30 +0000 (+0100) Subject: for_each_file() fix X-Git-Tag: fio-1.20-rc2~6 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=58f9f0495ae8de5bc221e4afaa543132bc149bc4 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 --- 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)) { \