summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2012-10-03 15:29:16 +0300
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-03 16:34:32 +0200
commit3d620088b461b9570fc67508ab6f1b71db81e94b (patch)
treeb551c82eabb12153482fe2a09d7996efaf63010b /src/corelib/tools
parent9695df4d44b228e7e778ff17d5cccac30967b1fd (diff)
Fix QTextBoundaryFinder assignment operator
for the case when the boundary finder is assigned to an invalid one. Change-Id: I5b60984ff3fd99972fcae21895684bd83b012780 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qtextboundaryfinder.cpp21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/corelib/tools/qtextboundaryfinder.cpp b/src/corelib/tools/qtextboundaryfinder.cpp
index 6656569e65..7f120323fe 100644
--- a/src/corelib/tools/qtextboundaryfinder.cpp
+++ b/src/corelib/tools/qtextboundaryfinder.cpp
@@ -202,18 +202,27 @@ QTextBoundaryFinder &QTextBoundaryFinder::operator=(const QTextBoundaryFinder &o
if (&other == this)
return *this;
+ if (other.d) {
+ uint newCapacity = (length + 1) * sizeof(QCharAttributes);
+ QTextBoundaryFinderPrivate *newD = (QTextBoundaryFinderPrivate *) realloc(freePrivate ? d : 0, newCapacity);
+ Q_CHECK_PTR(newD);
+ freePrivate = true;
+ d = newD;
+ }
+
t = other.t;
s = other.s;
chars = other.chars;
length = other.length;
pos = other.pos;
- QTextBoundaryFinderPrivate *newD = (QTextBoundaryFinderPrivate *)
- realloc(freePrivate ? d : 0, (length + 1) * sizeof(QCharAttributes));
- Q_CHECK_PTR(newD);
- freePrivate = true;
- d = newD;
- memcpy(d, other.d, (length + 1) * sizeof(QCharAttributes));
+ if (other.d) {
+ memcpy(d, other.d, (length + 1) * sizeof(QCharAttributes));
+ } else {
+ if (freePrivate)
+ free(d);
+ d = 0;
+ }
return *this;
}