[rtems commit] libcsupport: Accept NULL for zero-length entries
Sebastian Huber
sebh at rtems.org
Fri Dec 20 09:26:48 UTC 2013
Module: rtems
Branch: master
Commit: c1d8ee4cdc094b3595d2f4d0cdfc17a53f85716c
Changeset: http://git.rtems.org/rtems/commit/?id=c1d8ee4cdc094b3595d2f4d0cdfc17a53f85716c
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Tue Dec 17 10:59:13 2013 +0100
libcsupport: Accept NULL for zero-length entries
---
cpukit/libcsupport/include/rtems/libio_.h | 2 +-
cpukit/libfs/src/defaults/default_readv.c | 24 ++++++++++++++----------
cpukit/libfs/src/defaults/default_writev.c | 24 ++++++++++++++----------
testsuites/psxtests/psxrdwrv/test.c | 4 ++--
4 files changed, 31 insertions(+), 23 deletions(-)
diff --git a/cpukit/libcsupport/include/rtems/libio_.h b/cpukit/libcsupport/include/rtems/libio_.h
index 995d621..78a57c8 100644
--- a/cpukit/libcsupport/include/rtems/libio_.h
+++ b/cpukit/libcsupport/include/rtems/libio_.h
@@ -887,7 +887,7 @@ static inline ssize_t rtems_libio_iovec_eval(
total += ( ssize_t ) len;
- if ( iov[ v ].iov_base == NULL ) {
+ if ( iov[ v ].iov_base == NULL && len != 0 ) {
rtems_set_errno_and_return_minus_one( EINVAL );
}
}
diff --git a/cpukit/libfs/src/defaults/default_readv.c b/cpukit/libfs/src/defaults/default_readv.c
index 063ed5e..0156a41 100644
--- a/cpukit/libfs/src/defaults/default_readv.c
+++ b/cpukit/libfs/src/defaults/default_readv.c
@@ -41,19 +41,23 @@ ssize_t rtems_filesystem_default_readv(
total = 0;
for ( v = 0 ; v < iovcnt ; ++v ) {
- ssize_t bytes = ( *iop->pathinfo.handlers->read_h )(
- iop,
- iov[ v ].iov_base,
- iov[ v ].iov_len
- );
+ size_t len = iov[ v ].iov_len;
- if ( bytes < 0 )
- return -1;
+ if ( len > 0 ) {
+ ssize_t bytes = ( *iop->pathinfo.handlers->read_h )(
+ iop,
+ iov[ v ].iov_base,
+ len
+ );
- total += bytes;
+ if ( bytes < 0 )
+ return -1;
- if ( bytes != iov[ v ].iov_len )
- break;
+ total += bytes;
+
+ if ( bytes != ( ssize_t ) len )
+ break;
+ }
}
return total;
diff --git a/cpukit/libfs/src/defaults/default_writev.c b/cpukit/libfs/src/defaults/default_writev.c
index e62e084..3a4ed82 100644
--- a/cpukit/libfs/src/defaults/default_writev.c
+++ b/cpukit/libfs/src/defaults/default_writev.c
@@ -41,19 +41,23 @@ ssize_t rtems_filesystem_default_writev(
total = 0;
for ( v = 0 ; v < iovcnt ; ++v ) {
- ssize_t bytes = ( *iop->pathinfo.handlers->write_h )(
- iop,
- iov[ v ].iov_base,
- iov[ v ].iov_len
- );
+ size_t len = iov[ v ].iov_len;
- if ( bytes < 0 )
- return -1;
+ if ( len > 0 ) {
+ ssize_t bytes = ( *iop->pathinfo.handlers->write_h )(
+ iop,
+ iov[ v ].iov_base,
+ len
+ );
- total += bytes;
+ if ( bytes < 0 )
+ return -1;
- if ( bytes != iov[ v ].iov_len )
- break;
+ total += bytes;
+
+ if ( bytes != ( ssize_t ) len )
+ break;
+ }
}
return total;
diff --git a/testsuites/psxtests/psxrdwrv/test.c b/testsuites/psxtests/psxrdwrv/test.c
index 0e06674..181d9d4 100644
--- a/testsuites/psxtests/psxrdwrv/test.c
+++ b/testsuites/psxtests/psxrdwrv/test.c
@@ -361,7 +361,7 @@ int doErrorTest(void)
/* writev -- all zero length buffers */
vec[0].iov_base = vec;
vec[0].iov_len = 0;
- vec[1].iov_base = vec;
+ vec[1].iov_base = NULL;
vec[1].iov_len = 0;
puts("writev iov_len works with no effect -- OK");
rc = writev(fd, vec, 2);
@@ -374,7 +374,7 @@ int doErrorTest(void)
/* readv -- all zero length buffers */
vec[0].iov_base = vec;
vec[0].iov_len = 0;
- vec[1].iov_base = vec;
+ vec[1].iov_base = NULL;
vec[1].iov_len = 0;
puts("readv iov_len works with no effect -- OK");
rc = readv(fd, vec, 2);
More information about the vc
mailing list