for_each_file() fix
authorJens Axboe <jens.axboe@oracle.com>
Thu, 6 Mar 2008 09:30:30 +0000 (10:30 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Thu, 6 Mar 2008 09:30:30 +0000 (10:30 +0100)
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 <jens.axboe@oracle.com>
fio.h

diff --git a/fio.h b/fio.h
index e7e32cc75a48652286b45c7eb0207eb902a1baf6..0cf5334ba8ef518a60356d9176646cbc5a8662f8 100644 (file)
--- 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)) {                  \