Fix get interpreter
The previous algorithm advanced the iterator after printing a leaflist
instance, which meant that if the last item was leaflist instance, the
iterator would be advanced to .end() and in the next while-loop
condition check, the iterator would no longer be dereferencable.
The new algorithm peeks at the next element, checks whether it's the
end, if not, checks whether it's still the same leaflist and only then
advances the iterator.
Issue: https://tree.taiga.io/project/jktjkt-netconf-cli/issue/175
Change-Id: I0770d87585da800c160684221a85dbeb687a8955
diff --git a/src/interpreter.cpp b/src/interpreter.cpp
index 80e7a7a..cfd0a5d 100644
--- a/src/interpreter.cpp
+++ b/src/interpreter.cpp
@@ -47,10 +47,10 @@
if (value.type() == typeid(special_) && boost::get<special_>(value).m_value == SpecialValue::LeafList) {
auto leafListPrefix = path;
std::cout << path << " = " << leafDataToString(value) << std::endl;
- ++it;
- while (boost::starts_with(it->first, leafListPrefix)) {
- std::cout << stripLeafListValueFromPath(it->first) << " = " << leafDataToString(it->second) << std::endl;
+
+ while (it + 1 != items.end() && boost::starts_with((it + 1) ->first, leafListPrefix)) {
++it;
+ std::cout << stripLeafListValueFromPath(it->first) << " = " << leafDataToString(it->second) << std::endl;
}
} else {
std::cout << path << " = " << leafDataToString(value) << std::endl;