From 261277783fa16e0c974b1981a5eb0a208fca955e Mon Sep 17 00:00:00 2001 From: Neil Date: Fri, 21 Apr 2017 09:30:16 +1000 Subject: More consistent deletion of standard methods. --- src/PositionCache.cxx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/PositionCache.cxx') diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index c5ba231de..c302f8581 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -561,7 +561,17 @@ bool BreakFinder::More() const { } PositionCacheEntry::PositionCacheEntry() : - styleNumber(0), len(0), clock(0), positions(0) { + styleNumber(0), len(0), clock(0), positions(nullptr) { +} + +// Copy constructor not currently used, but needed for being element in std::vector. +PositionCacheEntry::PositionCacheEntry(const PositionCacheEntry &other) : + styleNumber(other.styleNumber), len(other.styleNumber), clock(other.styleNumber), positions(nullptr) { + if (other.positions) { + const size_t lenData = len + (len / sizeof(XYPOSITION)) + 1; + positions = new XYPOSITION[lenData]; + memcpy(positions, other.positions, lenData * sizeof(XYPOSITION)); + } } void PositionCacheEntry::Set(unsigned int styleNumber_, const char *s_, @@ -571,7 +581,7 @@ void PositionCacheEntry::Set(unsigned int styleNumber_, const char *s_, len = len_; clock = clock_; if (s_ && positions_) { - positions = new XYPOSITION[len + (len / 4) + 1]; + positions = new XYPOSITION[len + (len / sizeof(XYPOSITION)) + 1]; for (unsigned int i=0; i