Skip to content

Commit

Permalink
Avoid crash when managing an empty error message (related to issue #96)
Browse files Browse the repository at this point in the history
  • Loading branch information
morbac committed Oct 20, 2021
1 parent a6d21ae commit 7981818
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions MSXMLWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,33 @@ void MSXMLWrapper::addErrorToVector(IXMLDOMParseError2* pXMLErr, const wchar_t*
ErrorEntryType err;

if (pXMLErr != NULL) {
CHK_HR(pXMLErr->get_line(&line));
CHK_HR(pXMLErr->get_linepos(&linepos));
CHK_HR(pXMLErr->get_filepos(&filepos));
CHK_HR(pXMLErr->get_reason(&bstrReason));
if (bstrReason != NULL) {
CHK_HR(pXMLErr->get_line(&line));
CHK_HR(pXMLErr->get_linepos(&linepos));
CHK_HR(pXMLErr->get_filepos(&filepos));

if (line == 0 || linepos == 0) {
line = 1;
linepos = 1;
}

if (line == 0 || linepos == 0) {
line = 1;
linepos = 1;
}
if (line >= 0 && linepos >= 0 && filepos >= 0) {
err.positioned = TRUE;
err.line = (size_t) line;
err.linepos = (size_t)linepos;
err.filepos = (size_t)filepos + 1;
}
else {
err.positioned = FALSE;
err.line = 0;
err.linepos = 0;
err.filepos = 0;
}

if (line >= 0 && linepos >= 0 && filepos >= 0) {
err.positioned = TRUE;
err.line = (size_t) line;
err.linepos = (size_t)linepos;
err.filepos = (size_t)filepos + 1;
}
else {
err.positioned = FALSE;
err.line = 0;
err.linepos = 0;
err.filepos = 0;
err.reason = std::wstring((wchar_t*)bstr_t(bstrReason));
this->errors.push_back(err);
}
err.reason = std::wstring((wchar_t*)bstr_t(bstrReason));

this->errors.push_back(err);
}

CleanUp:
Expand Down

0 comments on commit 7981818

Please sign in to comment.