From c3550de72b83bf70aa82f63b7395f1a0b41a4b0d Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Mon, 27 Jan 2014 04:06:35 +0000 Subject: 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 --- src/pugixml.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src') 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); -- cgit v1.2.3