Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid use of uninitalized values in GBRForestTools #35705

Merged
merged 1 commit into from Oct 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 16 additions & 7 deletions CommonTools/MVAUtils/src/GBRForestTools.cc
Expand Up @@ -80,9 +80,9 @@ namespace {
} else {
int thisidx = tree.CutIndices().size();

int selector;
float cutval;
bool ctype;
int selector = 0;
float cutval = 0.;
bool ctype = false;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: I initialized the variables here rather than doing error checking as there is no error handling what so ever in this function and I didn't want to make a larger change.


node->QueryIntAttribute("IVar", &selector);
node->QueryFloatAttribute("Cut", &cutval);
Expand Down Expand Up @@ -158,8 +158,12 @@ namespace {
e = e->NextSiblingElement("Info")) {
const char* name;
const char* value;
e->QueryStringAttribute("name", &name);
e->QueryStringAttribute("value", &value);
if (tinyxml2::XML_SUCCESS != e->QueryStringAttribute("name", &name)) {
throw cms::Exception("XMLERROR") << "no 'name' attribute found in 'Info' element in " << weightsFileFullPath;
}
if (tinyxml2::XML_SUCCESS != e->QueryStringAttribute("value", &value)) {
throw cms::Exception("XMLERROR") << "no 'value' attribute found in 'Info' element in " << weightsFileFullPath;
}
info[name] = value;
}

Expand All @@ -172,7 +176,9 @@ namespace {
for (tinyxml2::XMLElement* e = optionsElem->FirstChildElement("Option"); e != nullptr;
e = e->NextSiblingElement("Option")) {
const char* name;
e->QueryStringAttribute("name", &name);
if (tinyxml2::XML_SUCCESS != e->QueryStringAttribute("name", &name)) {
throw cms::Exception("XMLERROR") << "no 'name' attribute found in 'Option' element in " << weightsFileFullPath;
}
options[name] = e->GetText();
}

Expand All @@ -194,7 +200,10 @@ namespace {
e = e->NextSiblingElement("BinaryTree")) {
hasTrees = true;
double w;
e->QueryDoubleAttribute("boostWeight", &w);
if (tinyxml2::XML_SUCCESS != e->QueryDoubleAttribute("boostWeight", &w)) {
throw cms::Exception("XMLERROR") << "problem with 'boostWeight' attribute found in 'BinaryTree' element in "
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could fail because the attribute is missing or the value could not be converted to a double. I didn't feel it was worth the effort to distinguish the two.

<< weightsFileFullPath;
}
boostWeights.push_back(w);
}
if (!hasTrees) {
Expand Down