>From 2c1e85803ab10075e22d9978b97085ee052241d7 Mon Sep 17 00:00:00 2001
From: Nikolay Sivov <nsivov@codeweavers.com>
Date: Wed, 21 Sep 2011 13:48:17 +0400
Subject: [PATCH 1/1] It's not a failure to get S_FALSE from IStream::Read()

---
 dlls/msxml3/saxreader.c |   43 ++++++++++++++++++++++++++-----------------
 1 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/dlls/msxml3/saxreader.c b/dlls/msxml3/saxreader.c
index 5bf6eda..f5ec672 100644
--- a/dlls/msxml3/saxreader.c
+++ b/dlls/msxml3/saxreader.c
@@ -1873,14 +1873,14 @@ static HRESULT internal_parseStream(saxreader *This, IStream *stream, BOOL vbInt
     HRESULT hr;
     ULONG dataRead;
     char data[1024];
+    int ret;
 
+    dataRead = 0;
     hr = IStream_Read(stream, data, sizeof(data), &dataRead);
-    if(hr != S_OK)
-        return hr;
+    if(FAILED(hr)) return hr;
 
     hr = SAXLocator_create(This, &locator, vbInterface);
-    if(FAILED(hr))
-        return hr;
+    if(FAILED(hr)) return hr;
 
     locator->pParserCtxt = xmlCreatePushParserCtxt(
             &locator->saxreader->sax, locator,
@@ -1892,25 +1892,34 @@ static HRESULT internal_parseStream(saxreader *This, IStream *stream, BOOL vbInt
     }
 
     This->isParsing = TRUE;
-    while(1)
-    {
-        hr = IStream_Read(stream, data, sizeof(data), &dataRead);
-        if(hr != S_OK)
-            break;
 
-        if(xmlParseChunk(locator->pParserCtxt, data, dataRead, 0) != XML_ERR_OK) hr = E_FAIL;
-        else hr = locator->ret;
+    if(dataRead != sizeof(data))
+    {
+        ret = xmlParseChunk(locator->pParserCtxt, data, 0, 1);
+        hr = ret != XML_ERR_OK ? E_FAIL : locator->ret;
+    }
+    else
+    {
+        while(1)
+        {
+            dataRead = 0;
+            hr = IStream_Read(stream, data, sizeof(data), &dataRead);
+            if (FAILED(hr)) break;
 
-        if(hr != S_OK) break;
+            ret = xmlParseChunk(locator->pParserCtxt, data, dataRead, 0);
+            hr = ret != XML_ERR_OK ? E_FAIL : locator->ret;
 
-        if(dataRead != sizeof(data))
-        {
-            if(xmlParseChunk(locator->pParserCtxt, data, 0, 1) != XML_ERR_OK) hr = E_FAIL;
-            else hr = locator->ret;
+            if (hr != S_OK) break;
 
-            break;
+            if (dataRead != sizeof(data))
+            {
+                ret = xmlParseChunk(locator->pParserCtxt, data, 0, 1);
+                hr = ret != XML_ERR_OK ? E_FAIL : locator->ret;
+                break;
+            }
         }
     }
+
     This->isParsing = FALSE;
 
     xmlFreeParserCtxt(locator->pParserCtxt);
-- 
1.5.6.5

