From 9436a95da1ec9036607c4c612c17dc5021c6cf81 Mon Sep 17 00:00:00 2001 From: "r.kuznetsov" Date: Wed, 30 May 2018 10:32:26 +0300 Subject: [PATCH] [pykmlib] Added none protection --- kml/pykmlib/bindings.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/kml/pykmlib/bindings.cpp b/kml/pykmlib/bindings.cpp index 43746966fde..4283f002573 100644 --- a/kml/pykmlib/bindings.cpp +++ b/kml/pykmlib/bindings.cpp @@ -93,6 +93,9 @@ struct LocalizableStringAdapter static void SetDict(LocalizableString & str, boost::python::dict & dict) { str.clear(); + if (dict.is_none()) + return; + auto const langs = python_list_to_std_vector(dict.keys()); for (auto const & lang : langs) { @@ -156,6 +159,9 @@ struct PropertiesAdapter static void SetDict(Properties & props, boost::python::dict & dict) { props.clear(); + if (dict.is_none()) + return; + auto const keys = python_list_to_std_vector(dict.keys()); for (auto const & k : keys) props[k] = extract(dict[k]); @@ -188,6 +194,11 @@ struct VectorAdapter static void Set(std::vector & v, boost::python::object const & iterable) { + if (iterable.is_none()) + { + v.clear(); + return; + } v = python_list_to_std_vector(iterable); } @@ -243,8 +254,11 @@ boost::python::list VectorAdapter::Get(std::vector const template<> void VectorAdapter::Set(std::vector & v, boost::python::object const & iterable) { - auto const latLon = python_list_to_std_vector(iterable); v.clear(); + if (iterable.is_none()) + return; + + auto const latLon = python_list_to_std_vector(iterable); v.reserve(latLon.size()); for (size_t i = 0; i < latLon.size(); ++i) v.emplace_back(MercatorBounds::LonToX(latLon[i].lon), MercatorBounds::LatToY(latLon[i].lat)); @@ -519,8 +533,11 @@ boost::python::list GetLanguages(std::vector const & langs) void SetLanguages(std::vector & langs, boost::python::object const & iterable) { - auto const langStr = python_list_to_std_vector(iterable); langs.clear(); + if (iterable.is_none()) + return; + + auto const langStr = python_list_to_std_vector(iterable); langs.reserve(langStr.size()); for (auto const & lang : langStr) {