diff options
author | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2022-03-14 14:09:47 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-03-15 18:40:05 +0000 |
commit | 893d61c4aa88aab4cbacf57a8a1763514b4ac9c4 (patch) | |
tree | 1cdbd798af59c3451c0acf25651a1953ecbe16df | |
parent | f8c29581456343ad09f23785b8218113743f1686 (diff) |
Android: guard against potential null pointer access
androidPlatformIntegration might be called before
setAndroidPlatformIntegration() is called, and also all other
uses of androidPlatformIntegration is already guarded in our
code.
Task-number: QTBUG-100470
Change-Id: Ifd7d36ba7f2f3b55652466825d7fd84c87ec5e19
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
(cherry picked from commit 66961346448c72102ba7258eec17b77ca0b7a859)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/plugins/platforms/android/qandroidinputcontext.cpp | 36 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformintegration.cpp | 6 |
2 files changed, 24 insertions, 18 deletions
diff --git a/src/plugins/platforms/android/qandroidinputcontext.cpp b/src/plugins/platforms/android/qandroidinputcontext.cpp index 417f3469a8..a6418e94d3 100644 --- a/src/plugins/platforms/android/qandroidinputcontext.cpp +++ b/src/plugins/platforms/android/qandroidinputcontext.cpp @@ -654,22 +654,26 @@ void QAndroidInputContext::updateSelectionHandles() QPoint leftPoint(qPlatformWindow->mapToGlobal(leftRect.bottomLeft().toPoint())); QPoint rightPoint(qPlatformWindow->mapToGlobal(rightRect.bottomRight().toPoint())); - if (m_selectHandleWidth == 0) - m_selectHandleWidth = QtAndroidInput::getSelectHandleWidth() / 2; - int rightSideOfScreen = QtAndroid::androidPlatformIntegration()->screen()->availableGeometry().right(); - if (leftPoint.x() < m_selectHandleWidth) - leftPoint.setX(m_selectHandleWidth); - - if (rightPoint.x() > rightSideOfScreen - m_selectHandleWidth) - rightPoint.setX(rightSideOfScreen - m_selectHandleWidth); - - QPoint editPoint(qPlatformWindow->mapToGlobal(leftRect.united(rightRect).topLeft().toPoint())); - uint32_t buttons = readOnly ? EditContext::CopyButton | EditContext::SelectAllButton - : EditContext::AllButtons; - - QtAndroidInput::updateHandles(m_handleMode, editPoint, buttons, leftPoint, rightPoint, - query.value(Qt::ImCurrentSelection).toString().isRightToLeft()); - m_hideCursorHandleTimer.stop(); + QAndroidPlatformIntegration *platformIntegration = QtAndroid::androidPlatformIntegration(); + if (platformIntegration) { + if (m_selectHandleWidth == 0) + m_selectHandleWidth = QtAndroidInput::getSelectHandleWidth() / 2; + + int rightSideOfScreen = platformIntegration->screen()->availableGeometry().right(); + if (leftPoint.x() < m_selectHandleWidth) + leftPoint.setX(m_selectHandleWidth); + + if (rightPoint.x() > rightSideOfScreen - m_selectHandleWidth) + rightPoint.setX(rightSideOfScreen - m_selectHandleWidth); + + QPoint editPoint(qPlatformWindow->mapToGlobal(leftRect.united(rightRect).topLeft().toPoint())); + uint32_t buttons = readOnly ? EditContext::CopyButton | EditContext::SelectAllButton + : EditContext::AllButtons; + + QtAndroidInput::updateHandles(m_handleMode, editPoint, buttons, leftPoint, rightPoint, + query.value(Qt::ImCurrentSelection).toString().isRightToLeft()); + m_hideCursorHandleTimer.stop(); + } } /* diff --git a/src/plugins/platforms/android/qandroidplatformintegration.cpp b/src/plugins/platforms/android/qandroidplatformintegration.cpp index 2a080db51d..1e6e860e7a 100644 --- a/src/plugins/platforms/android/qandroidplatformintegration.cpp +++ b/src/plugins/platforms/android/qandroidplatformintegration.cpp @@ -491,8 +491,10 @@ void QAndroidPlatformIntegration::setScreenOrientation(Qt::ScreenOrientation cur void QAndroidPlatformIntegration::flushPendingUpdates() { - m_primaryScreen->setSizeParameters(m_defaultPhysicalSize, m_defaultScreenSize, - m_defaultAvailableGeometry); + if (m_primaryScreen) { + m_primaryScreen->setSizeParameters(m_defaultPhysicalSize, m_defaultScreenSize, + m_defaultAvailableGeometry); + } } #ifndef QT_NO_ACCESSIBILITY |