From 21ec6f0b86bafbaf7c1afa5cf90d739937f949ac Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 9 Jun 2018 20:00:28 +0200 Subject: [PATCH] Some fixes for PropertyEnumeration: + when reading an enumeration ignore negative indexes and print a warning + raise an exception when trying to get the current value of an invalid enumeration --- src/App/PropertyStandard.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/App/PropertyStandard.cpp b/src/App/PropertyStandard.cpp index 086b4d9509..554a537c7b 100644 --- a/src/App/PropertyStandard.cpp +++ b/src/App/PropertyStandard.cpp @@ -32,6 +32,7 @@ /// Here the FreeCAD includes sorted by Base,App,Gui...... #include +#include #include #include #include @@ -356,6 +357,8 @@ bool PropertyEnumeration::isPartOf(const char *value) const const char * PropertyEnumeration::getValueAsString(void) const { + if (!_enum.isValid()) + throw Base::RuntimeError("Cannot get value from invalid enumeration"); return _enum.getCStr(); } @@ -415,6 +418,11 @@ void PropertyEnumeration::Restore(Base::XMLReader &reader) _enum.setEnums(values); } + if (val < 0) { + Base::Console().Warning("Enumeration index %d is out of range, ignore it\n", val); + val = getValue(); + } + setValue(val); }