Kaydet (Commit) 98db90e2 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Don't create std::string from nullptr

...which violates the ctor's preconditions, so is UB.  Also, the "XML Help
Document Type Definition" appendix of
<http://documentation.openoffice.org/online_help/OOo2HelpAuthoring.pdf> states
that "branch" and "id" attributes are #REQUIRED for the "bookmark" element.

(There's probably further cases in the surrounding code where a std::string is
created from a potentially null argument, which would benefit from similar
fixes.)

Change-Id: I414576d13de784de1290951bcdd5e3ecb51f9cb8
Reviewed-on: https://gerrit.libreoffice.org/55735Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst 39e75712
......@@ -325,10 +325,18 @@ void myparser::traverse( xmlNodePtr parentNode )
else if (!strcmp(reinterpret_cast<const char*>(test->name), "bookmark"))
{
xmlChar *branchxml = xmlGetProp(test, reinterpret_cast<const xmlChar*>("branch"));
xmlChar *idxml = xmlGetProp(test, reinterpret_cast<const xmlChar*>("id"));
if (branchxml == nullptr) {
throw HelpProcessingException(
HelpProcessingErrorClass::XmlParsing, "bookmark lacks branch attribute");
}
std::string branch(reinterpret_cast<char*>(branchxml));
std::string anchor(reinterpret_cast<char*>(idxml));
xmlFree (branchxml);
xmlChar *idxml = xmlGetProp(test, reinterpret_cast<const xmlChar*>("id"));
if (idxml == nullptr) {
throw HelpProcessingException(
HelpProcessingErrorClass::XmlParsing, "bookmark lacks id attribute");
}
std::string anchor(reinterpret_cast<char*>(idxml));
xmlFree (idxml);
if (branch.compare(0, 3, "hid") == 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment