diff options
author | Julien Chaffraix <julien.chaffraix@gmail.com> | 2011-04-30 16:37:49 -0700 |
---|---|---|
committer | Michael Meeks <michael.meeks@novell.com> | 2011-05-03 10:21:46 +0100 |
commit | 48227a2047e0ea1b501becf02ebfe30287bab1a9 (patch) | |
tree | c7c2bb43f049ec500a909d2ff3019f849707e476 | |
parent | b9dea6ac66aa8fbf954a917b01ed99d53ec15195 (diff) |
Properly advance the data / buffer pointer.
Spotted by Michael Meeks.
-rw-r--r-- | sal/osl/unx/readwrite_helper.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/sal/osl/unx/readwrite_helper.c b/sal/osl/unx/readwrite_helper.c index 51e1ec6b6458..e2598953e8b5 100644 --- a/sal/osl/unx/readwrite_helper.c +++ b/sal/osl/unx/readwrite_helper.c @@ -35,10 +35,12 @@ sal_Bool safeWrite(int fd, void* data, sal_uInt32 dataSize) { sal_Int32 nToWrite = dataSize; + unsigned char* dataToWrite = data; + // Check for overflow as we convert a signed to an unsigned. OSL_ASSERT(dataSize == (sal_uInt32)nToWrite); while ( nToWrite ) { - sal_Int32 nWritten = write(fd, data, nToWrite); + sal_Int32 nWritten = write(fd, dataToWrite, nToWrite); if ( nWritten < 0 ) { if ( errno == EINTR ) continue; @@ -49,6 +51,7 @@ sal_Bool safeWrite(int fd, void* data, sal_uInt32 dataSize) OSL_ASSERT(nWritten > 0); nToWrite -= nWritten; + dataToWrite += nWritten; } return sal_True; @@ -57,10 +60,12 @@ sal_Bool safeWrite(int fd, void* data, sal_uInt32 dataSize) sal_Bool safeRead( int fd, void* buffer, sal_uInt32 count ) { sal_Int32 nToRead = count; + unsigned char* bufferForReading = buffer; + // Check for overflow as we convert a signed to an unsigned. OSL_ASSERT(count == (sal_uInt32)nToRead); while ( nToRead ) { - sal_Int32 nRead = read(fd, buffer, nToRead); + sal_Int32 nRead = read(fd, bufferForReading, nToRead); if ( nRead < 0 ) { // We were interrupted before reading, retry. if (errno == EINTR) @@ -75,6 +80,7 @@ sal_Bool safeRead( int fd, void* buffer, sal_uInt32 count ) return sal_False; nToRead -= nRead; + bufferForReading += nRead; } return sal_True; |