From ab03dfed2a799eca25c60cc06949c3dc5dda5704 Mon Sep 17 00:00:00 2001 From: "Peter D. Barnes, Jr." Date: Tue, 28 May 2013 17:29:48 -0700 Subject: [PATCH] [Coverity] Out-of-bounds read (OVERRUN) --- src/core/model/test.cc | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/core/model/test.cc b/src/core/model/test.cc index c0524317c..30fe7bade 100644 --- a/src/core/model/test.cc +++ b/src/core/model/test.cc @@ -484,22 +484,30 @@ std::string TestRunnerImpl::ReplaceXmlSpecialCharacters (std::string xml) const { NS_LOG_FUNCTION (this << xml); - std::string specials = "<>&\"'"; - std::string replacements[] = {"<", ">", "&", "'", """}; + typedef std::map specials_map; + specials_map specials; + specials['<'] = "<"; + specials['>'] = ">"; + specials['&'] = "&"; + specials['"'] = "'"; + specials['\''] = """; + std::string result; - std::size_t index, length = xml.length (); + std::size_t length = xml.length (); for (size_t i = 0; i < length; ++i) { char character = xml[i]; - if ((index = specials.find (character)) == std::string::npos) + specials_map::const_iterator it = specials.find (character); + + if (it == specials.end ()) { result.push_back (character); } else { - result += replacements[index]; + result += it->second; } } return result;