]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfsprogs: fix wrong variable types in pwrite/pread code
authorZirong Lang <zlang@redhat.com>
Mon, 20 Nov 2017 19:53:56 +0000 (13:53 -0600)
committerEric Sandeen <sandeen@redhat.com>
Mon, 20 Nov 2017 19:53:56 +0000 (13:53 -0600)
The 'Coverity Scan' found a problem in new write_once() function:

272             size_t bytes;
273             bytes = do_pwrite(file->fd, offset, count, count, pwritev2_flags);
>>>     CID 1420710:  Control flow issues  (NO_EFFECT)
>>>     This less-than-zero comparison of an unsigned value is never true. "bytes < 0UL".
274             if (bytes < 0)
275                     return -1;

That's unreasonable. do_pwrite return 'ssize_t' type value, which can
be less than zero, but we use a 'size_t' to get the return value. So
change the size_t to ssize_t for it can store the return value
correctly.

By the chance, correct all 'ssize_t' type problems in pwrite/pread
related functions.

Signed-off-by: Zorro Lang <zlang@redhat.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
[sandeen: modify commit summary]
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
io/pread.c
io/pwrite.c

index 7591276df996c8de2ef4145659ad264cf24d00ff..60650aa340f6b83b73b7086c2e86ea5d055760de 100644 (file)
@@ -172,12 +172,12 @@ dump_buffer(
 }
 
 #ifdef HAVE_PREADV
-static int
+static ssize_t
 do_preadv(
        int             fd,
        off64_t         offset,
-       ssize_t         count,
-       ssize_t         buffer_size)
+       size_t          count,
+       size_t          buffer_size)
 {
        int             vecs = 0;
        ssize_t         oldlen = 0;
@@ -208,12 +208,12 @@ do_preadv(
 #define do_preadv(fd, offset, count, buffer_size) (0)
 #endif
 
-static int
+static ssize_t
 do_pread(
        int             fd,
        off64_t         offset,
-       ssize_t         count,
-       ssize_t         buffer_size)
+       size_t          count,
+       size_t          buffer_size)
 {
        if (!vectors)
                return pread(fd, buffer, min(count, buffer_size), offset);
index 26f79579e668eebc99fab075e9f25c1eea18e2e6..3df976a89eb25918e5fe335db4423b0f5950be7b 100644 (file)
@@ -61,12 +61,12 @@ pwrite_help(void)
 }
 
 #ifdef HAVE_PWRITEV
-static int
+static ssize_t
 do_pwritev(
        int             fd,
        off64_t         offset,
-       ssize_t         count,
-       ssize_t         buffer_size,
+       size_t          count,
+       size_t          buffer_size,
        int             pwritev2_flags)
 {
        int vecs = 0;
@@ -105,12 +105,12 @@ do_pwritev(
 #define do_pwritev(fd, offset, count, buffer_size) (0)
 #endif
 
-static int
+static ssize_t
 do_pwrite(
        int             fd,
        off64_t         offset,
-       ssize_t         count,
-       ssize_t         buffer_size,
+       size_t          count,
+       size_t          buffer_size,
        int             pwritev2_flags)
 {
        if (!vectors)
@@ -269,7 +269,7 @@ write_once(
        long long       *total,
        int             pwritev2_flags)
 {
-       size_t bytes;
+       ssize_t bytes;
        bytes = do_pwrite(file->fd, offset, count, count, pwritev2_flags);
        if (bytes < 0)
                return -1;