diff options
author | Determinant <[email protected]> | 2018-06-26 20:48:43 -0400 |
---|---|---|
committer | Determinant <[email protected]> | 2018-06-26 20:48:43 -0400 |
commit | 353943edc5a7bbedc816f08031fb5bf16efeb23e (patch) | |
tree | d60dd97721431a9f35b3e2fd9f6a794de98fce15 /include | |
parent | bfb0b426df85efc5485872702b19af7921ff455e (diff) |
check ctl pointer before dereference
Diffstat (limited to 'include')
-rw-r--r-- | include/salticidae/ref.h | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/include/salticidae/ref.h b/include/salticidae/ref.h index 5f54da2..83fd00b 100644 --- a/include/salticidae/ref.h +++ b/include/salticidae/ref.h @@ -87,13 +87,13 @@ class WeakObjBase { WeakObjBase(): ctl(nullptr) {} WeakObjBase &operator=(const WeakObjBase &other) { release(); - ctl = other.ctl; - ctl->add_weak(); + if ((ctl = other.ctl)) + ctl->add_weak(); return *this; } WeakObjBase(const WeakObjBase &other): ctl(other.ctl) { - ctl->add_weak(); + if (ctl) ctl->add_weak(); } WeakObjBase(WeakObjBase &&other): ctl(other.ctl) { @@ -127,20 +127,20 @@ class RcObjBase { RcObjBase &operator=(const RcObjBase &other) { release(); obj = other.obj; - ctl = other.ctl; - ctl->add_ref(); + if ((ctl = other.ctl)) + ctl->add_ref(); return *this; } RcObjBase(const RcObjBase &other): obj(other.obj), ctl(other.ctl) { - ctl->add_ref(); + if (ctl) ctl->add_ref(); } template<typename T_> RcObjBase(const RcObjBase<T_, R> &other): obj(other.obj), ctl(other.ctl) { - ctl->add_ref(); + if (ctl) ctl->add_ref(); } RcObjBase(RcObjBase &&other): @@ -171,15 +171,15 @@ template<typename T, typename T_, typename R> RcObjBase<T, R> static_pointer_cast(const RcObjBase<T_, R> &other) { RcObjBase<T, R> rc{}; rc.obj = static_cast<T *>(other.obj); - rc.ctl = other.ctl; - rc.ctl->add_ref(); + if ((rc.ctl = other.ctl)) + rc.ctl->add_ref(); return std::move(rc); } template<typename T, typename R> inline WeakObjBase<T, R>::WeakObjBase(const RcObjBase<T, R> &other): ctl(other.ctl) { - ctl->add_weak(); + if (ctl) ctl->add_weak(); } template<typename T> using RcObj = RcObjBase<T, _RCCtl>; |