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 | 82af2c10b5b093496bfb6d29f4a7068dd158f943 (patch) | |
tree | de1cae98d51757eccc1e867688ad45f7eeacdddb /sal | |
parent | 3f40d4b1862aab3a7d0bc54f005ff9816c6927d2 (diff) |
Properly advance the data / buffer pointer.
Spotted by Michael Meeks.
Diffstat (limited to 'sal')
-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 51e1ec6b6..e2598953e 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; |