From 353943edc5a7bbedc816f08031fb5bf16efeb23e Mon Sep 17 00:00:00 2001 From: Determinant Date: Tue, 26 Jun 2018 20:48:43 -0400 Subject: check ctl pointer before dereference --- include/salticidae/ref.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'include/salticidae/ref.h') 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 RcObjBase(const RcObjBase &other): obj(other.obj), ctl(other.ctl) { - ctl->add_ref(); + if (ctl) ctl->add_ref(); } RcObjBase(RcObjBase &&other): @@ -171,15 +171,15 @@ template RcObjBase static_pointer_cast(const RcObjBase &other) { RcObjBase rc{}; rc.obj = static_cast(other.obj); - rc.ctl = other.ctl; - rc.ctl->add_ref(); + if ((rc.ctl = other.ctl)) + rc.ctl->add_ref(); return std::move(rc); } template inline WeakObjBase::WeakObjBase(const RcObjBase &other): ctl(other.ctl) { - ctl->add_weak(); + if (ctl) ctl->add_weak(); } template using RcObj = RcObjBase; -- cgit v1.2.3