diff options
author | Carl Schumann <schumann@fnal.gov> | 2012-05-11 18:40:21 (GMT) |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-25 00:04:08 (GMT) |
commit | 8f22e4bed8973758ef175f4d5d7f725009db9eb6 (patch) | |
tree | fb78c242a113b47059868f33582c30a6a73d87f0 /src/gui/dialogs | |
parent | af7e859a3fc203613200e6d61d43e214480e2bd3 (diff) | |
download | Qt-8f22e4bed8973758ef175f4d5d7f725009db9eb6.zip Qt-8f22e4bed8973758ef175f4d5d7f725009db9eb6.tar.gz Qt-8f22e4bed8973758ef175f4d5d7f725009db9eb6.tar.bz2 |
Fix bug when destruction fields in QWizard
Cherry-picked a70b8d407e1ca46e5dc208580534feee7ddfe51a from
Qt5's qtbase master branch.
Maintain the consistency of QWizardPrivate's two members:
QVector<QWizardField> fields;
QMap<QString, int> fieldIndexMap;
during and after calls to QWizardPrivate's
void _q_handleFieldObjectDestroyed(QObject *)
member function. The failure to maintain this consistency
caused an out of bounds access and core dump in
QWizard's field(const QString &name) member function.
QWizard's field(const QString &name) member function expects
the values in the QMap fieldIndexMap to be indexes into the
QVector fields. Prior to this change
_q_handleFieldObjectDestroyed only removed the appropriate
entry from the map and erased it from the vector. It did
not decrement by one all the indexes greater than the index
that was removed from the map and erased from the vector
in the rest of the map.
For example ...
So if initially have the following mapping ...
"field0" -> 0,
"field1" -> 1, and
"field2" -> 2
with fields of size 3. After destruction of "field1" have ...
"field0" -> 0, and
"field2" -> 2
with fields of size 2.
Now attempts to look up "field2" using QWizard::field will
have an out of bounds error and possibly core dump or trigger
an internal Qt assert because an attempt to access
this->fields[2] will be made. It should be accessing
this->fields[1], but does not because the map is no longer
consistent with the vector.
This change adds a decrement by one for all the indexes
greater than the index that was removed from the map and
erased from the vector.
Task-number: QTBUG-25691
Change-Id: Ia2a41027628a65faec4ecdd5da235ddd19746a57
Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Reviewed-by: Girish Ramakrishnan <girish.1.ramakrishnan@nokia.com>
Diffstat (limited to 'src/gui/dialogs')
-rw-r--r-- | src/gui/dialogs/qwizard.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/gui/dialogs/qwizard.cpp b/src/gui/dialogs/qwizard.cpp index 4ed20a4..dc91603 100644 --- a/src/gui/dialogs/qwizard.cpp +++ b/src/gui/dialogs/qwizard.cpp @@ -1703,16 +1703,29 @@ void QWizardPrivate::_q_updateButtonStates() void QWizardPrivate::_q_handleFieldObjectDestroyed(QObject *object) { + int destroyed_index = -1; QVector<QWizardField>::iterator it = fields.begin(); while (it != fields.end()) { const QWizardField &field = *it; if (field.object == object) { + destroyed_index = fieldIndexMap.value(field.name, -1); fieldIndexMap.remove(field.name); it = fields.erase(it); } else { ++it; } } + if (destroyed_index != -1) { + QMap<QString, int>::iterator it2 = fieldIndexMap.begin(); + while (it2 != fieldIndexMap.end()) { + int index = it2.value(); + if (index > destroyed_index) { + QString field_name = it2.key(); + fieldIndexMap.insert(field_name, index-1); + } + ++it2; + } + } } void QWizardPrivate::setStyle(QStyle *style) |