From af31eba9daf7decdf0ac4e76e1b7719a23ae894f Mon Sep 17 00:00:00 2001 From: Chris Bielow Date: Thu, 26 Oct 2023 10:32:25 +0200 Subject: [PATCH] avoid calling ".toString().toDouble());" on potentially empty DataValue (which would crash) --- .../FORMAT/HANDLERS/MzIdentMLDOMHandler.cpp | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/openms/source/FORMAT/HANDLERS/MzIdentMLDOMHandler.cpp b/src/openms/source/FORMAT/HANDLERS/MzIdentMLDOMHandler.cpp index 253d4e8de86..f6602c39faa 100644 --- a/src/openms/source/FORMAT/HANDLERS/MzIdentMLDOMHandler.cpp +++ b/src/openms/source/FORMAT/HANDLERS/MzIdentMLDOMHandler.cpp @@ -565,33 +565,33 @@ namespace OpenMS::Internal DataValue dv = DataValue::EMPTY; if (has_value) { - if (type == "xsd:float" || type == "xsd:double") - { - try + if (type == "xsd:float" || type == "xsd:double") { - dv = value.toDouble(); - } - catch (...) - { - OPENMS_LOG_ERROR << "Found float parameter not convertible to float type." << endl; + try + { + dv = value.toDouble(); + } + catch (...) + { + OPENMS_LOG_ERROR << "Found float parameter not convertible to float type." << endl; + } } - } - else if (type == "xsd:int" || type == "xsd:unsignedInt") - { - try + else if (type == "xsd:int" || type == "xsd:unsignedInt") { - dv = value.toInt(); + try + { + dv = value.toInt(); + } + catch (...) + { + OPENMS_LOG_ERROR << "Found integer parameter not convertible to integer type." << endl; + } } - catch (...) + else { - OPENMS_LOG_ERROR << "Found integer parameter not convertible to integer type." << endl; + dv = value; } } - else - { - dv = value; - } - } // Add unit *after* creating the term @@ -1230,12 +1230,12 @@ namespace OpenMS::Internal DOMElement* databasename_param = element_dbn->getFirstElementChild(); while (databasename_param) { - if (XMLString::equals(databasename_param->getTagName(),CONST_XMLCH("cvParam"))) + if (XMLString::equals(databasename_param->getTagName(), CONST_XMLCH("cvParam"))) { CVTerm param = parseCvParam_(databasename_param); dbname = param.getValue(); } - else if (XMLString::equals(databasename_param->getTagName(),CONST_XMLCH("userParam"))) + else if (XMLString::equals(databasename_param->getTagName(), CONST_XMLCH("userParam"))) { pair param = parseUserParam_(databasename_param); // issue #7099: mzID might have missing "value" for this element @@ -2030,7 +2030,7 @@ namespace OpenMS::Internal // TODO @all: where to store passThreshold value? set after score type eval in pass_threshold long double score = 0; - pair > params = parseParamGroup_(spectrumIdentificationItemElement->getChildNodes()); + const auto& [param_cv, param_user] = parseParamGroup_(spectrumIdentificationItemElement->getChildNodes()); set q_score_terms; set e_score_terms,e_score_tmp; set specific_score_terms; @@ -2040,7 +2040,7 @@ namespace OpenMS::Internal e_score_terms.insert(e_score_tmp.begin(),e_score_tmp.end()); //E-value for peptides cv_.getAllChildTerms(specific_score_terms, "MS:1001143"); //search engine specific score for PSMs bool scoretype = false; - for (map >::const_iterator scoreit = params.first.getCVTerms().begin(); scoreit != params.first.getCVTerms().end(); ++scoreit) + for (map>::const_iterator scoreit = param_cv.getCVTerms().begin(); scoreit != param_cv.getCVTerms().end(); ++scoreit) { if (q_score_terms.find(scoreit->first) != q_score_terms.end() || scoreit->first == "MS:1002354") { @@ -2081,25 +2081,25 @@ namespace OpenMS::Internal { //build the PeptideHit from a SpectrumIdentificationItem PeptideHit hit(score, rank, chargeState, pep_map_[peptide_ref]); - for (std::map >::const_iterator cvs = params.first.getCVTerms().begin(); cvs != params.first.getCVTerms().end(); ++cvs) + for (const auto& cvs : param_cv.getCVTerms()) { - for (vector::const_iterator cv = cvs->second.begin(); cv != cvs->second.end(); ++cv) + for (const auto& cv : cvs.second) // if the same accession occurred multiple times... { - if (cvs->first == "MS:1002540") + if (cvs.first == "MS:1002540") { - hit.setMetaValue(cvs->first, cv->getValue().toString()); + hit.setMetaValue(cvs.first, cv.getValue().toString()); } - else if (cvs->first == "MS:1001143") // this is the CV term "PSM-level search engine specific statistic" and it doesn't have a value + else if (cvs.first == "MS:1001143") // this is the CV term "PSM-level search engine specific statistic" and it doesn't have a value { continue; } else - { - hit.setMetaValue(cvs->first, cv->getValue().toString().toDouble()); + { // value may be empty, e.g. + hit.setMetaValue(cvs.first, cv.getValue()); // can deal with empty values } } } - for (map::const_iterator up = params.second.begin(); up != params.second.end(); ++up) + for (map::const_iterator up = param_user.begin(); up != param_user.end(); ++up) { hit.setMetaValue(up->first, up->second); }