QDataWidgetMapper: Fix UB (member call)

As found by UBSan:

  qdatawidgetmapper.cpp:212:59: runtime error: member call on address 0x2b6cc8095be0 which does not point to an object of type 'QFocusHelper'
  0x2b6cc8095be0: note: object is of type 'QLineEdit'

Just make QDataWidgetMapperPrivate a friend of QWidget.

Change-Id: I33d8d430c3a03b7173358d0f96dc7f850d11697c
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
bb10
Marc Mutz 2016-08-01 10:05:28 +03:00
parent d38f86e50b
commit a81be85b63
2 changed files with 3 additions and 16 deletions

View File

@ -199,20 +199,6 @@ void QDataWidgetMapperPrivate::_q_commitData(QWidget *w)
commit(widgetMap.at(idx));
}
class QFocusHelper: public QWidget
{
public:
bool focusNextPrevChild(bool next) Q_DECL_OVERRIDE
{
return QWidget::focusNextPrevChild(next);
}
static inline void focusNextPrevChild(QWidget *w, bool next)
{
static_cast<QFocusHelper *>(w)->focusNextPrevChild(next);
}
};
void QDataWidgetMapperPrivate::_q_closeEditor(QWidget *w, QAbstractItemDelegate::EndEditHint hint)
{
int idx = findWidget(w);
@ -224,10 +210,10 @@ void QDataWidgetMapperPrivate::_q_closeEditor(QWidget *w, QAbstractItemDelegate:
populate(widgetMap[idx]);
break; }
case QAbstractItemDelegate::EditNextItem:
QFocusHelper::focusNextPrevChild(w, true);
w->focusNextChild();
break;
case QAbstractItemDelegate::EditPreviousItem:
QFocusHelper::focusNextPrevChild(w, false);
w->focusPreviousChild();
break;
case QAbstractItemDelegate::SubmitModelCache:
case QAbstractItemDelegate::NoHint:

View File

@ -668,6 +668,7 @@ protected:
void destroy(bool destroyWindow = true,
bool destroySubWindows = true);
friend class QDataWidgetMapperPrivate; // for access to focusNextPrevChild
virtual bool focusNextPrevChild(bool next);
inline bool focusNextChild() { return focusNextPrevChild(true); }
inline bool focusPreviousChild() { return focusNextPrevChild(false); }