aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBertrand Augereau2015-11-09 22:51:15 +0100
committerBertrand Augereau2015-11-09 22:51:15 +0100
commit4920b3ab3ef104cc2278ad7e52fe120bde6c7336 (patch)
tree5ebf1416166bac6705364038912f377360595499
parent8c046f4826be1d2d85d04b1e3f83dcc62ac55e5c (diff)
downloadscummvm-rg350-4920b3ab3ef104cc2278ad7e52fe120bde6c7336.tar.gz
scummvm-rg350-4920b3ab3ef104cc2278ad7e52fe120bde6c7336.tar.bz2
scummvm-rg350-4920b3ab3ef104cc2278ad7e52fe120bde6c7336.zip
COMMON: Some ill-formed xml files triggered a seek(CUR, -2) in the parser
-rw-r--r--common/xmlparser.cpp48
1 files changed, 25 insertions, 23 deletions
diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp
index 67a3d36cec..da4f577e3c 100644
--- a/common/xmlparser.cpp
+++ b/common/xmlparser.cpp
@@ -97,36 +97,38 @@ bool XMLParser::parserError(const String &errStr) {
assert(_stream->pos() == startPosition);
currentPosition = startPosition;
- int keyOpening = 0;
- int keyClosing = 0;
-
- while (currentPosition-- && keyOpening == 0) {
- _stream->seek(-2, SEEK_CUR);
- c = _stream->readByte();
+ Common::String errorMessage = Common::String::format("\n File <%s>, line %d:\n", _fileName.c_str(), lineCount);
- if (c == '<')
- keyOpening = currentPosition - 1;
- else if (c == '>')
- keyClosing = currentPosition;
- }
+ if (startPosition > 1) {
+ int keyOpening = 0;
+ int keyClosing = 0;
- _stream->seek(startPosition, SEEK_SET);
- currentPosition = startPosition;
- while (keyClosing == 0 && c && currentPosition++) {
- c = _stream->readByte();
+ while (currentPosition-- && keyOpening == 0) {
+ _stream->seek(-2, SEEK_CUR);
+ c = _stream->readByte();
- if (c == '>')
- keyClosing = currentPosition;
- }
+ if (c == '<')
+ keyOpening = currentPosition - 1;
+ else if (c == '>')
+ keyClosing = currentPosition;
+ }
- Common::String errorMessage = Common::String::format("\n File <%s>, line %d:\n", _fileName.c_str(), lineCount);
+ _stream->seek(startPosition, SEEK_SET);
+ currentPosition = startPosition;
+ while (keyClosing == 0 && c && currentPosition++) {
+ c = _stream->readByte();
- currentPosition = (keyClosing - keyOpening);
- _stream->seek(keyOpening, SEEK_SET);
+ if (c == '>')
+ keyClosing = currentPosition;
+ }
- while (currentPosition--)
- errorMessage += (char)_stream->readByte();
+ currentPosition = (keyClosing - keyOpening);
+ _stream->seek(keyOpening, SEEK_SET);
+ while (currentPosition--)
+ errorMessage += (char)_stream->readByte();
+ }
+
errorMessage += "\n\nParser error: ";
errorMessage += errStr;
errorMessage += "\n\n";