]> sigrok.org Git - libsigrok.git/commitdiff
C++: Add sanity checks in StructureWrapper.
authorMartin Ling <redacted>
Sat, 30 Aug 2014 11:16:51 +0000 (12:16 +0100)
committerUwe Hermann <redacted>
Sun, 31 Aug 2014 17:03:31 +0000 (19:03 +0200)
bindings/cxx/include/libsigrok/libsigrok.hpp

index e16a9536279d4a9b1ced248214a2383a701b675b..8c8b55495fa336999c825bd0490186fef807f658 100644 (file)
@@ -148,6 +148,8 @@ public:
        shared_ptr<StructureWrapper<Parent, Struct> >
        get_shared_pointer(Parent *parent)
        {
+               if (!parent)
+                       throw Error(SR_ERR_BUG);
                this->parent = static_pointer_cast<Parent>(parent->shared_from_this());
                return shared_ptr<StructureWrapper<Parent, Struct> >(
                        this, reset_parent);
@@ -155,6 +157,8 @@ public:
        shared_ptr<StructureWrapper<Parent, Struct> >
        get_shared_pointer(shared_ptr<Parent> parent)
        {
+               if (!parent)
+                       throw Error(SR_ERR_BUG);
                this->parent = parent;
                return shared_ptr<StructureWrapper<Parent, Struct> >(
                        this, reset_parent);
@@ -162,6 +166,8 @@ public:
 protected:
        static void reset_parent(StructureWrapper<Parent, Struct> *object)
        {
+               if (!object->parent)
+                       throw Error(SR_ERR_BUG);
                object->parent.reset();
        }