From f47241501fe009c715936aefa57e22f90995df0b Mon Sep 17 00:00:00 2001 From: Oliver Freyermuth Date: Wed, 13 Apr 2016 18:18:53 +0200 Subject: [PATCH] TText: Fix missing initialization in copy constructor and TText::Copy. TText::Copy was broken in several ways: - wchar-title was not copied to the given object, but from it. - nullptr checks were missing. The combination of both issues lead to all cases of TText::Copy to fail (no matter if the wchar-name was set or not). --- graf2d/graf/src/TText.cxx | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/graf2d/graf/src/TText.cxx b/graf2d/graf/src/TText.cxx index 67557bc9aaced..9115a891b0c01 100644 --- a/graf2d/graf/src/TText.cxx +++ b/graf2d/graf/src/TText.cxx @@ -94,7 +94,7 @@ TText::~TText() //////////////////////////////////////////////////////////////////////////////// /// Copy constructor. -TText::TText(const TText &text) : TNamed(text), TAttText(text), TAttBBox2D(text) +TText::TText(const TText &text) : TNamed(text), TAttText(text), TAttBBox2D(text), fWcsTitle(NULL) { fX = 0.; fY = 0.; @@ -110,13 +110,17 @@ void TText::Copy(TObject &obj) const ((TText&)obj).fY = fY; TNamed::Copy(obj); TAttText::Copy(((TText&)obj)); - if (fWcsTitle != NULL) { - *reinterpret_cast(fWcsTitle) = - *reinterpret_cast(((TText&)obj).fWcsTitle); + if (((TText&)obj).fWcsTitle != NULL) { + if (fWcsTitle != NULL) { + *reinterpret_cast(&((TText&)obj).fWcsTitle) = *reinterpret_cast(&fWcsTitle); + } else { + delete reinterpret_cast(&((TText&)obj).fWcsTitle); + ((TText&)obj).fWcsTitle = NULL; + } } else { - dynamic_cast(obj).fWcsTitle = - new std::wstring(*reinterpret_cast( - dynamic_cast(obj).fWcsTitle)); + if (fWcsTitle != NULL) { + ((TText&)(obj)).fWcsTitle = new std::wstring(*reinterpret_cast(fWcsTitle)); + } } }