io_ddir: return appropriate string for DDIR_INVAL
authorVincent Fu <vincent.fu@samsung.com>
Fri, 3 Dec 2021 21:10:10 +0000 (21:10 +0000)
committerJens Axboe <axboe@kernel.dk>
Fri, 3 Dec 2021 21:46:33 +0000 (14:46 -0700)
When looking up the appropriate name for a data direction, make sure the
array index is non-negative. This ensures that we return an appropriate
string for DDIR_INVAL.

Signed-off-by: Vincent Fu <vincent.fu@samsung.com>
Link: https://lore.kernel.org/r/20211203211050.51241-2-vincent.fu@samsung.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_ddir.h

index a42da97a335cd046b82c44c396695be471341b8e..296a9d04ac53cc1c44585ee736f8ea424375615d 100644 (file)
--- a/io_ddir.h
+++ b/io_ddir.h
@@ -24,7 +24,7 @@ static inline const char *io_ddir_name(enum fio_ddir ddir)
                                        "datasync", "sync_file_range",
                                        "wait", };
 
-       if (ddir < DDIR_LAST)
+       if (ddir >= 0 && ddir < DDIR_LAST)
                return name[ddir];
 
        return "invalid";