From 384478a745e55aca9aa8b8ded8c08ea900cf0849 Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Wed, 19 Apr 2017 22:21:03 +1000 Subject: [PATCH] Use XMLNode::get_property in Session::restore_history Avoid using std::stringstream due to potential future issues with C++ locale. Also avoids potential NULL pointer dereferences. --- libs/ardour/session_state.cc | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 4ad1f91f4a..c59ae00a57 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -3823,13 +3823,21 @@ Session::restore_history (string snapshot_name) XMLNode *t = *it; UndoTransaction* ut = new UndoTransaction (); - struct timeval tv; - ut->set_name(t->property("name")->value()); - stringstream ss(t->property("tv-sec")->value()); - ss >> tv.tv_sec; - ss.str(t->property("tv-usec")->value()); - ss >> tv.tv_usec; + std::string name; + int64_t tv_sec; + int64_t tv_usec; + + if (!t->get_property ("name", name) || !t->get_property ("tv-sec", tv_sec) || + !t->get_property ("tv-usec", tv_usec)) { + continue; + } + + ut->set_name (name); + + struct timeval tv; + tv.tv_sec = tv_sec; + tv.tv_usec = tv_usec; ut->set_timestamp(tv); for (XMLNodeConstIterator child_it = t->children().begin(); -- 2.30.2