Fix QDomNamedNodeMap::item crash with negative index
Task-number: QTBUG-49113 Change-Id: I62dee4c112b73a25628657bc3d2ae675f26b87d8 Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
parent
26238aca8c
commit
b20d6cded7
@ -3142,7 +3142,7 @@ QDomNodePrivate* QDomNamedNodeMapPrivate::removeNamedItem(const QString& name)
|
|||||||
|
|
||||||
QDomNodePrivate* QDomNamedNodeMapPrivate::item(int index) const
|
QDomNodePrivate* QDomNamedNodeMapPrivate::item(int index) const
|
||||||
{
|
{
|
||||||
if (index >= length())
|
if (index >= length() || index < 0)
|
||||||
return 0;
|
return 0;
|
||||||
return *(map.constBegin() + index);
|
return *(map.constBegin() + index);
|
||||||
}
|
}
|
||||||
|
@ -119,6 +119,7 @@ private slots:
|
|||||||
void cloneDTD_QTBUG8398() const;
|
void cloneDTD_QTBUG8398() const;
|
||||||
void DTDNotationDecl();
|
void DTDNotationDecl();
|
||||||
void DTDEntityDecl();
|
void DTDEntityDecl();
|
||||||
|
void QTBUG49113_dontCrashWithNegativeIndex() const;
|
||||||
|
|
||||||
void cleanupTestCase() const;
|
void cleanupTestCase() const;
|
||||||
|
|
||||||
@ -1979,5 +1980,13 @@ void tst_QDom::DTDEntityDecl()
|
|||||||
QCOMPARE(doctype.namedItem(QString("logo")).toEntity().notationName(), QString("gif"));
|
QCOMPARE(doctype.namedItem(QString("logo")).toEntity().notationName(), QString("gif"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QDom::QTBUG49113_dontCrashWithNegativeIndex() const
|
||||||
|
{
|
||||||
|
QDomDocument doc;
|
||||||
|
QDomElement elem = doc.appendChild(doc.createElement("root")).toElement();
|
||||||
|
QDomNode node = elem.attributes().item(-1);
|
||||||
|
QVERIFY(node.isNull());
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QDom)
|
QTEST_MAIN(tst_QDom)
|
||||||
#include "tst_qdom.moc"
|
#include "tst_qdom.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user