summaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--src/corelib/tools/qtextboundaryfinder.cpp21
-rw-r--r--tests/auto/corelib/tools/qtextboundaryfinder/tst_qtextboundaryfinder.cpp25
2 files changed, 40 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;
}
diff --git a/tests/auto/corelib/tools/qtextboundaryfinder/tst_qtextboundaryfinder.cpp b/tests/auto/corelib/tools/qtextboundaryfinder/tst_qtextboundaryfinder.cpp
index 56409447ff..22d3465823 100644
--- a/tests/auto/corelib/tools/qtextboundaryfinder/tst_qtextboundaryfinder.cpp
+++ b/tests/auto/corelib/tools/qtextboundaryfinder/tst_qtextboundaryfinder.cpp
@@ -72,6 +72,7 @@ private slots:
void lineBoundaries_manual();
void fastConstructor();
+ void assignmentOperator();
void wordBoundaries_qtbug6498();
void isAtSoftHyphen_data();
void isAtSoftHyphen();
@@ -545,6 +546,30 @@ void tst_QTextBoundaryFinder::fastConstructor()
QCOMPARE(finder.boundaryReasons(), QTextBoundaryFinder::NotAtBoundary);
}
+void tst_QTextBoundaryFinder::assignmentOperator()
+{
+ QString text(QLatin1String("Hello World"));
+
+ QTextBoundaryFinder invalidFinder;
+ QVERIFY(!invalidFinder.isValid());
+ QCOMPARE(invalidFinder.string(), QString());
+
+ QTextBoundaryFinder validFinder(QTextBoundaryFinder::Word, text);
+ QVERIFY(validFinder.isValid());
+ QCOMPARE(validFinder.string(), text);
+
+ QTextBoundaryFinder finder(QTextBoundaryFinder::Line, QLatin1String("dummy"));
+ QVERIFY(finder.isValid());
+
+ finder = invalidFinder;
+ QVERIFY(!finder.isValid());
+ QCOMPARE(finder.string(), QString());
+
+ finder = validFinder;
+ QVERIFY(finder.isValid());
+ QCOMPARE(finder.string(), text);
+}
+
void tst_QTextBoundaryFinder::wordBoundaries_qtbug6498()
{
// text with trailing space