[Libreoffice-commits] .: 2 commits - extensions/source

Caolán McNamara caolan at kemper.freedesktop.org
Sat Apr 21 14:24:48 PDT 2012


 extensions/source/nsplugin/source/npshell.cxx |   10 ++++++++--
 extensions/source/scanner/sane.cxx            |   26 +++++++++++++++++++++-----
 2 files changed, 29 insertions(+), 7 deletions(-)

New commits:
commit e37ae322b07a02714b22cb663e1d7ab4f2072730
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Sat Apr 21 22:24:03 2012 +0100

    fill in some sane defaults on read/write failure

diff --git a/extensions/source/nsplugin/source/npshell.cxx b/extensions/source/nsplugin/source/npshell.cxx
index f6b4ea4..33c282f 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 ca2cec1..b89f9bd 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 );
                 }
commit 6ef852f160b88b2052c150374fb9aeab43a29804
Author: David Ostrovsky <David.Ostrovsky at gmx.de>
Date:   Sat Apr 21 14:29:14 2012 +0200

    WaE: extensions warnings fixed

diff --git a/extensions/source/nsplugin/source/npshell.cxx b/extensions/source/nsplugin/source/npshell.cxx
index 81ce8fb..f6b4ea4 100644
--- a/extensions/source/nsplugin/source/npshell.cxx
+++ b/extensions/source/nsplugin/source/npshell.cxx
@@ -772,7 +772,11 @@ NPP_StreamAsFile(NPP instance, NPStream *stream, const char* fname)
 
                     break;
             }
-            write(fdDst, buffer, ret);
+            ssize_t written_bytes = write(fdDst, buffer, ret);
+            if (written_bytes == -1)
+            {
+                return;
+            }
         }
         close(fdSrc);
         close(fdDst);
diff --git a/extensions/source/scanner/sane.cxx b/extensions/source/scanner/sane.cxx
index aaefbf4..ca2cec1 100644
--- a/extensions/source/scanner/sane.cxx
+++ b/extensions/source/scanner/sane.cxx
@@ -524,11 +524,24 @@ static inline sal_uInt8 _ReadValue( FILE* fp, int depth )
         // e.g. UMAX Astra 1200S delivers 16 bit but in BIGENDIAN
         // against SANE documentation (xscanimage gets the same result
         // as we do
-        fread( &nWord, 1, 2, fp );
+        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)
+        {
+             // nothing todo?
+             // WaE is happy!
+        }
         return (sal_uInt8)( nWord / 256 );
     }
     sal_uInt8 nByte;
-    fread( &nByte, 1, 1, fp );
+    size_t items_read = fread( &nByte, 1, 1, fp );
+    if (items_read == 0)
+    {
+         // nothing todo?
+         // WaE is happy!
+    }
     return nByte;
 }
 
@@ -814,7 +827,15 @@ sal_Bool Sane::Start( BitmapTransporter& rBitmap )
                     ( eType == FrameStyle_Gray && aParams.depth == 8 )
                     )
                 {
-                    fread( pBuffer, 1, aParams.bytes_per_line, pFrame );
+                    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)
+                    {
+                        // nothing todo?
+                        // WaE is happy!
+                    }
                     aConverter.Write( pBuffer, aParams.bytes_per_line );
                 }
                 else if( eType == FrameStyle_Gray )


More information about the Libreoffice-commits mailing list