summaryrefslogtreecommitdiff
path: root/extensions
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2012-04-21 22:24:03 +0100
committerCaolán McNamara <caolanm@redhat.com>2012-04-21 22:24:03 +0100
commite37ae322b07a02714b22cb663e1d7ab4f2072730 (patch)
treead9bd80b0435d07cdb8e86e28be8aeb61b17bdb2 /extensions
parent6ef852f160b88b2052c150374fb9aeab43a29804 (diff)
fill in some sane defaults on read/write failure
Diffstat (limited to 'extensions')
-rw-r--r--extensions/source/nsplugin/source/npshell.cxx6
-rw-r--r--extensions/source/scanner/sane.cxx29
2 files changed, 16 insertions, 19 deletions
diff --git a/extensions/source/nsplugin/source/npshell.cxx b/extensions/source/nsplugin/source/npshell.cxx
index f6b4ea4b1bfa..33c282f3991d 100644
--- a/extensions/source/nsplugin/source/npshell.cxx
+++ b/extensions/source/nsplugin/source/npshell.cxx
@@ -761,7 +761,7 @@ NPP_StreamAsFile(NPP instance, NPStream *stream, const char* fname)
return;
}
char buffer[NPP_BUFFER_SIZE] = {0};
- int ret;
+ ssize_t ret;
while(0 <= (ret = read(fdSrc, buffer, NPP_BUFFER_SIZE)))
{
if (0 == ret)
@@ -773,8 +773,10 @@ NPP_StreamAsFile(NPP instance, NPStream *stream, const char* fname)
break;
}
ssize_t written_bytes = write(fdDst, buffer, ret);
- if (written_bytes == -1)
+ if (written_bytes != ret)
{
+ debug_fprintf(NSP_LOG_APPEND, "NPP_StreamAsFile:short write to %s. error: %s \n",
+ localPathNew, strerror(errno));
return;
}
}
diff --git a/extensions/source/scanner/sane.cxx b/extensions/source/scanner/sane.cxx
index ca2cec186758..b89f9bd3b793 100644
--- a/extensions/source/scanner/sane.cxx
+++ b/extensions/source/scanner/sane.cxx
@@ -526,21 +526,20 @@ static inline sal_uInt8 _ReadValue( FILE* fp, int depth )
// as we do
size_t items_read = fread( &nWord, 1, 2, fp );
- // fread() does not distinguish between end-of-file and error, and callers
- // must use feof(3) and ferror(3) to determine which occurred.
- if (items_read == 0)
+ if (items_read != 2)
{
- // nothing todo?
- // WaE is happy!
+ SAL_WARN( "extensions.scanner", "short read, abandoning" );
+ return 0;
}
+
return (sal_uInt8)( nWord / 256 );
}
sal_uInt8 nByte;
size_t items_read = fread( &nByte, 1, 1, fp );
- if (items_read == 0)
+ if (items_read != 1)
{
- // nothing todo?
- // WaE is happy!
+ SAL_WARN( "extensions.scanner", "short read, abandoning" );
+ return 0;
}
return nByte;
}
@@ -819,22 +818,18 @@ sal_Bool Sane::Start( BitmapTransporter& rBitmap )
aConverter.Seek( 1084 );
}
- for( nLine = nHeight-1;
- nLine >= 0; nLine-- )
+ for (nLine = nHeight-1; nLine >= 0; --nLine)
{
fseek( pFrame, nLine * aParams.bytes_per_line, SEEK_SET );
if( eType == FrameStyle_BW ||
( eType == FrameStyle_Gray && aParams.depth == 8 )
)
{
- size_t items_read = fread( pBuffer, 1, aParams.bytes_per_line, pFrame );
-
- // fread() does not distinguish between end-of-file and error, and callers
- // must use feof(3) and ferror(3) to determine which occurred.
- if (items_read == 0)
+ SANE_Int items_read = fread( pBuffer, 1, aParams.bytes_per_line, pFrame );
+ if (items_read != aParams.bytes_per_line)
{
- // nothing todo?
- // WaE is happy!
+ SAL_WARN( "extensions.scanner", "short read, padding with zeros" );
+ memset(pBuffer + items_read, 0, aParams.bytes_per_line - items_read);
}
aConverter.Write( pBuffer, aParams.bytes_per_line );
}