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>bb10
parent
9695df4d44
commit
3d620088b4
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue