From 20204fe58b77d7f62d3dac4e574bdef528199518 Mon Sep 17 00:00:00 2001 From: Jan Arve Saether Date: Tue, 5 Feb 2013 16:43:07 +0100 Subject: [PATCH] Do not crash if the child index is out of range. Task-number: QTBUG-29077 Change-Id: I934101cdc121e9ef99de2e9eeaef154dd4cae0d8 Reviewed-by: Frederik Gladhorn --- .../windows/accessible/qwindowsmsaaaccessible.cpp | 7 ++++--- tests/auto/other/qaccessibility/tst_qaccessibility.cpp | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/plugins/platforms/windows/accessible/qwindowsmsaaaccessible.cpp b/src/plugins/platforms/windows/accessible/qwindowsmsaaaccessible.cpp index 7cc2b2aeb0..c23902014c 100644 --- a/src/plugins/platforms/windows/accessible/qwindowsmsaaaccessible.cpp +++ b/src/plugins/platforms/windows/accessible/qwindowsmsaaaccessible.cpp @@ -577,9 +577,10 @@ HRESULT STDMETHODCALLTYPE QWindowsMsaaAccessible::accLocation(long *pxLeft, long QRect rect; if (varID.lVal) { - QAIPointer child = QAIPointer(accessible->child(varID.lVal - 1)); - if (child->isValid()) - rect = child->rect(); + QAIPointer child(childPointer(varID)); + if (!child) + return E_FAIL; + rect = child->rect(); } else { rect = accessible->rect(); } diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp index 68fde2fd2e..b0d0459326 100644 --- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp @@ -3113,6 +3113,11 @@ void tst_QAccessibility::bridgeTest() // **** Test accLocation **** long x, y, w, h; + // Do not crash on insane arguments. + varChild.lVal = 999; + hr = iaccButton->accLocation(&x, &y, &w, &h, varChild); + QCOMPARE(SUCCEEDED(hr), false); + hr = iaccButton->accLocation(&x, &y, &w, &h, varSELF); QCOMPARE(buttonRect, QRect(x, y, w, h));