# HG changeset patch # User Brian Neal # Date 1340763762 18000 # Node ID 3370383116dba65bb1b1e095b63561aea2a32688 # Parent 80debdaa4f652e8f2e315def95898e939d2442f4 Bug fix for the string functions. diff -r 80debdaa4f65 -r 3370383116db enigma/plugboard.cpp --- a/enigma/plugboard.cpp Sun Jun 24 19:22:06 2012 -0500 +++ b/enigma/plugboard.cpp Tue Jun 26 21:22:42 2012 -0500 @@ -134,13 +134,17 @@ std::string s; - for (const auto p : pairs) + for (const auto& p : pairs) { s += static_cast(p.first + 'A'); s += static_cast(p.second + 'A'); s += ' '; } - s.erase(s.size() - 1); // erase trailing space + + if (!s.empty()) + { + s.erase(s.size() - 1); // erase trailing space + } return s; } @@ -151,13 +155,16 @@ const auto pairs = get_pairs(); std::ostringstream os; - for (const auto p : pairs) + for (const auto& p : pairs) { os << (p.first + 1) << '/' << (p.second + 1) << ' '; } std::string s(os.str()); - s.erase(s.size() - 1); // erase trailing space + if (!s.empty()) + { + s.erase(s.size() - 1); // erase trailing space + } return s; }