summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2014-01-27 04:06:35 +0000
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2014-01-27 04:06:35 +0000
commitc3550de72b83bf70aa82f63b7395f1a0b41a4b0d (patch)
treeb2ef9d9eb64a609a276fe1d0f554e790488ad6ad
parent0938714fa010b23e2d2a43606ae0eb8280c481fe (diff)
Ignore stream errors generated by a failing tellg() for non-seekable streams
git-svn-id: http://pugixml.googlecode.com/svn/trunk@961 99668b35-9821-0410-8761-19e4c4f06640
-rw-r--r--src/pugixml.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/pugixml.cpp b/src/pugixml.cpp
index 149b5d9..78fe50a 100644
--- a/src/pugixml.cpp
+++ b/src/pugixml.cpp
@@ -3627,9 +3627,20 @@ PUGI__NS_BEGIN
{
void* buffer = 0;
size_t size = 0;
+ xml_parse_status status = status_ok;
+
+ // if stream has an error bit set, bail out (otherwise tellg() can fail and we'll clear error bits)
+ if (stream.fail()) return make_parse_result(status_io_error);
// load stream to memory (using seek-based implementation if possible, since it's faster and takes less memory)
- xml_parse_status status = (stream.tellg() < 0) ? load_stream_data_noseek(stream, &buffer, &size) : load_stream_data_seek(stream, &buffer, &size);
+ if (stream.tellg() < 0)
+ {
+ stream.clear(); // clear error flags that could be set by a failing tellg
+ status = load_stream_data_noseek(stream, &buffer, &size);
+ }
+ else
+ status = load_stream_data_seek(stream, &buffer, &size);
+
if (status != status_ok) return make_parse_result(status);
return doc.load_buffer_inplace_own(buffer, size, options, encoding);