xfstests: fix modulo-by-zero error in fsx
authorDave Chinner <dchinner@redhat.com>
Tue, 19 Jul 2011 22:43:41 +0000 (08:43 +1000)
committerDave Chinner <david@fromorbit.com>
Tue, 19 Jul 2011 22:43:41 +0000 (08:43 +1000)
The recent fsx fixes has a logic error in the offset trimming code.
If a read is done when the file size is zero, then the logic error
causes a offset % 0 opertaion to occur. This causes fsx to get a
SIGFPE and die.

This was not discovered during my testing because I was using a
random seed that didn't trip this condition. Changing the seed to
that which test 091 uses (the default of 1) causes such an operation
to occur....

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
ltp/fsx.c

index 771bcdc0a75e2ed32df6099f5caf6fee4cd11809..d53c4980119fc249abe8753f7d489975bb8146f0 100644 (file)
--- a/ltp/fsx.c
+++ b/ltp/fsx.c
@@ -987,14 +987,14 @@ docloseopen(void)
        }
 }
 
-#define TRIM_OFF_LEN(off, len, size, zero_offset)      \
-do {                                   \
-       if (!zero_offset || file_size)  \
-               offset %= size;         \
-       else                            \
-               offset = 0;             \
-       if (offset + len > size)        \
-               len = size - offset;    \
+#define TRIM_OFF_LEN(off, len, size, allow_zero_file_size)     \
+do {                                           \
+       if (allow_zero_file_size || file_size)  \
+               offset %= size;                 \
+       else                                    \
+               offset = 0;                     \
+       if (offset + len > size)                \
+               len = size - offset;            \
 } while (0)
 
 void