tools/winedump/pe.c: Check return value of fwrite. Report error and exit in case of any error. (bug # 16413)

titon barua titanix88 at gmail.com
Sun Jan 4 14:12:00 CST 2009


---
 tools/winedump/pe.c |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/tools/winedump/pe.c b/tools/winedump/pe.c
index 31a744e..e6a6dff 100644
--- a/tools/winedump/pe.c
+++ b/tools/winedump/pe.c
@@ -947,6 +947,12 @@ static const char *get_resource_type( unsigned int id )
     return NULL;
 }
 
+static void report_error_and_exit (const char * s)
+{
+   perror ( s );
+   exit ( 1 );
+}
+
 /* dump an ASCII string with proper escaping */
 static int dump_strA( const unsigned char *str, size_t len )
 {
@@ -959,7 +965,8 @@ static int dump_strA( const unsigned char *str, size_t len )
     {
         if (pos > buffer + sizeof(buffer) - 8)
         {
-            fwrite( buffer, pos - buffer, 1, stdout );
+            if (fwrite( buffer, pos - buffer, 1, stdout ) != 1)
+               report_error_and_exit ( "Error dumping ASCII string" );
             count += pos - buffer;
             pos = buffer;
         }
@@ -982,7 +989,8 @@ static int dump_strA( const unsigned char *str, size_t len )
         if (*str == '\\') *pos++ = '\\';
         *pos++ = *str;
     }
-    fwrite( buffer, pos - buffer, 1, stdout );
+    if (fwrite( buffer, pos - buffer, 1, stdout ) != 1)
+      report_error_and_exit ( "Error dumping ASCII string" );
     count += pos - buffer;
     return count;
 }
@@ -999,7 +1007,8 @@ static int dump_strW( const WCHAR *str, size_t len )
     {
         if (pos > buffer + sizeof(buffer) - 8)
         {
-            fwrite( buffer, pos - buffer, 1, stdout );
+            if (fwrite( buffer, pos - buffer, 1, stdout ) != 1)
+               report_error_and_exit ( "Error dumping Unicode string" );
             count += pos - buffer;
             pos = buffer;
         }
@@ -1025,7 +1034,8 @@ static int dump_strW( const WCHAR *str, size_t len )
         if (*str == '\\') *pos++ = '\\';
         *pos++ = *str;
     }
-    fwrite( buffer, pos - buffer, 1, stdout );
+    if (fwrite( buffer, pos - buffer, 1, stdout ) != 1)
+        report_error_and_exit ( "Error dumping Unicode string" );
     count += pos - buffer;
     return count;
 }
-- 
1.5.6.3
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.winehq.org/pipermail/wine-patches/attachments/20090105/2a827dfb/attachment.htm 


More information about the wine-patches mailing list