diff options
| author | Konstantin Ritt <[email protected]> | 2012-10-03 15:29:16 +0300 |
|---|---|---|
| committer | The Qt Project <[email protected]> | 2012-10-03 16:34:32 +0200 |
| commit | 3d620088b461b9570fc67508ab6f1b71db81e94b (patch) | |
| tree | b551c82eabb12153482fe2a09d7996efaf63010b /src | |
| parent | 9695df4d44b228e7e778ff17d5cccac30967b1fd (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 <[email protected]>
Diffstat (limited to 'src')
| -rw-r--r-- | src/corelib/tools/qtextboundaryfinder.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/corelib/tools/qtextboundaryfinder.cpp b/src/corelib/tools/qtextboundaryfinder.cpp index 6656569e65b..7f120323feb 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; } |
