From: Christian Bauer Date: Fri, 20 Aug 2004 20:13:09 +0000 (+0000) Subject: cache other.p in assignment; this should fix the "assignment of X-Git-Tag: release_1-3-0~31 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=dffb4439ad438c76002d6b7798e5e3b651a2ac19 cache other.p in assignment; this should fix the "assignment of sub-expression" problem with operator[] --- diff --git a/ginac/ptr.h b/ginac/ptr.h index 7f305fe1..4c4ea71d 100644 --- a/ginac/ptr.h +++ b/ginac/ptr.h @@ -80,11 +80,14 @@ public: ptr &operator=(const ptr & other) { - // NB: must first add reference to "other", since other might be *this. - other.p->add_reference(); + // NB1: Must first add reference to "other", since other might be *this. + // NB2: Cache other.p, because if "other" is a subexpression of p, + // deleting p will also invalidate "other". + T *otherp = other.p; + otherp->add_reference(); if (p->remove_reference() == 0) delete p; - p = other.p; + p = otherp; return *this; }