From 33c7170fcb7632311c42a3c69ccdee03a9a568ca Mon Sep 17 00:00:00 2001 From: Wladimir Leuschner Date: Tue, 2 Jul 2024 12:35:00 +0200 Subject: [PATCH] QWindowsUiaProvider: Check for empty narrator string In case of password fields, the narrator may return a emptry QString, this was not checked when using operator[]. This patch explicitly checks for an empty string returned by the QWindowsUiaProvider. Fixes: QTBUG-126822 Change-Id: I9e2c3cfc5fb6dc9a7dd7badff4280f60b24c0a4b Reviewed-by: Oliver Wolff (cherry picked from commit 1ee349bf9d249ea45bc01c45473db44b9d335eed) Reviewed-by: Qt Cherry-pick Bot --- .../windows/uiautomation/qwindowsuiatextrangeprovider.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp b/src/plugins/platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp index 50dc1d0b35c..b1bcfcf96c9 100644 --- a/src/plugins/platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp +++ b/src/plugins/platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp @@ -111,7 +111,7 @@ HRESULT QWindowsUiaTextRangeProvider::ExpandToEnclosingUnit(TextUnit unit) const int start = m_startOffset >= 0 && m_startOffset < len ? m_startOffset : len - 1; for (int t = start; t >= 0; --t) { - if (!isTextUnitSeparator(unit, text[t]) && ((t == 0) || isTextUnitSeparator(unit, text[t - 1]))) { + if (!text.isEmpty() && !isTextUnitSeparator(unit, text[t]) && ((t == 0) || isTextUnitSeparator(unit, text[t - 1]))) { m_startOffset = t; break; } @@ -412,7 +412,7 @@ HRESULT QWindowsUiaTextRangeProvider::MoveEndpointByUnit(TextPatternRangeEndpoin if (endpoint == TextPatternRangeEndpoint_Start) { if (count > 0) { for (int t = m_startOffset; (t < len - 1) && (moved < count); ++t) { - if (isTextUnitSeparator(unit, text[t]) && !isTextUnitSeparator(unit, text[t + 1])) { + if (!text.isEmpty() && isTextUnitSeparator(unit, text[t]) && !isTextUnitSeparator(unit, text[t + 1])) { m_startOffset = t + 1; ++moved; } @@ -422,7 +422,7 @@ HRESULT QWindowsUiaTextRangeProvider::MoveEndpointByUnit(TextPatternRangeEndpoin const int start = m_startOffset >= 0 && m_startOffset <= len ? m_startOffset : len; for (int t = start - 1; (t >= 0) && (moved > count); --t) { - if (!isTextUnitSeparator(unit, text[t]) && ((t == 0) || isTextUnitSeparator(unit, text[t - 1]))) { + if (!text.isEmpty() &&!isTextUnitSeparator(unit, text[t]) && ((t == 0) || isTextUnitSeparator(unit, text[t - 1]))) { m_startOffset = t; --moved; }