From 7984f24b1fcb9cc2785d4659d877ae2aaf377ac1 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 22 Feb 2016 16:46:21 +0100 Subject: Fix potential crash in QWindowsIA2Accessible::QueryInterface(). QWindowsIA2Accessible does not implement IAccessibleRelation (found when replacing the C-style casts by static_cast<>). Remove the corresponding branch. Task-number: QTBUG-50804 Change-Id: I80901634044f85e413666f34b91be2e6ad70da91 Reviewed-by: Joerg Bornemann --- src/plugins/platforms/windows/accessible/iaccessible2.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/plugins/platforms/windows/accessible/iaccessible2.cpp') diff --git a/src/plugins/platforms/windows/accessible/iaccessible2.cpp b/src/plugins/platforms/windows/accessible/iaccessible2.cpp index 9531272a07..e34c86158d 100644 --- a/src/plugins/platforms/windows/accessible/iaccessible2.cpp +++ b/src/plugins/platforms/windows/accessible/iaccessible2.cpp @@ -249,8 +249,6 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::QueryInterface(REFIID id, LPVOI //*iface = (IAccessibleHypertext*)this; } else if (id == IID_IAccessibleImage) { //*iface = (IAccessibleImage*)this; - } else if (id == IID_IAccessibleRelation) { - *iface = (IAccessibleRelation*)this; } else if (id == IID_IAccessibleTable) { //*iface = (IAccessibleTable*)this; // not supported } else if (id == IID_IAccessibleTable2) { -- cgit v1.2.3 From 403b7d4a21bba14bc059ad0c84a7614f221255e9 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 22 Feb 2016 16:56:07 +0100 Subject: Windows Accessibility: Refactor code creating COM arrays. Introduce a convenience function for allocating arrays and use algorithms. Task-number: QTBUG-50804 Change-Id: Iead75f8297923fd13efcfc7987f76262777d074b Reviewed-by: Joerg Bornemann --- .../platforms/windows/accessible/iaccessible2.cpp | 47 +++++++++++++--------- 1 file changed, 29 insertions(+), 18 deletions(-) (limited to 'src/plugins/platforms/windows/accessible/iaccessible2.cpp') diff --git a/src/plugins/platforms/windows/accessible/iaccessible2.cpp b/src/plugins/platforms/windows/accessible/iaccessible2.cpp index e34c86158d..abca91a7db 100644 --- a/src/plugins/platforms/windows/accessible/iaccessible2.cpp +++ b/src/plugins/platforms/windows/accessible/iaccessible2.cpp @@ -41,8 +41,16 @@ #include #include +#include + QT_BEGIN_NAMESPACE +template +static inline T *coTaskMemAllocArray(int size) +{ + return static_cast(::CoTaskMemAlloc(sizeof(T) * size_t(size))); +} + /**************************************************************\ * AccessibleApplication * **************************************************************/ @@ -591,9 +599,9 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_keyBinding(long actionIndex numBindings = keyBindings.count(); if (numBindings > 0) { // The IDL documents that the client must free with CoTaskMemFree - arrayOfBindingsToReturn = (BSTR*)::CoTaskMemAlloc(sizeof(BSTR) * numBindings); - for (int i = 0; i < numBindings; ++i) - arrayOfBindingsToReturn[i] = QStringToBSTR(keyBindings.at(i)); + arrayOfBindingsToReturn = coTaskMemAllocArray(numBindings); + std::transform(keyBindings.constBegin(), keyBindings.constEnd(), + arrayOfBindingsToReturn, QStringToBSTR); } } *keyBindings = arrayOfBindingsToReturn; @@ -970,12 +978,13 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_selectedColumns(long **sele if (QAccessibleTableInterface *tableIface = tableInterface()) { const QList selectedIndices = tableIface->selectedColumns(); - const int &count = selectedIndices.count(); - long *selected = (count ? (long*)::CoTaskMemAlloc(sizeof(long) * count) : (long*)0); - for (int i = 0; i < count; ++i) - selected[i] = selectedIndices.at(i); - *selectedColumns = selected; + const int count = selectedIndices.count(); *nColumns = count; + *selectedColumns = Q_NULLPTR; + if (count) { + *selectedColumns = coTaskMemAllocArray(count); + std::copy(selectedIndices.constBegin(), selectedIndices.constEnd(), *selectedColumns); + } return count ? S_OK : S_FALSE; } return E_FAIL; @@ -991,12 +1000,13 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_selectedRows(long **selecte if (QAccessibleTableInterface *tableIface = tableInterface()) { const QList selectedIndices = tableIface->selectedRows(); - const int &count = selectedIndices.count(); - long *selected = (count ? (long*)::CoTaskMemAlloc(sizeof(long) * count) : (long*)0); - for (int i = 0; i < count; ++i) - selected[i] = selectedIndices.at(i); - *selectedRows = selected; + const int count = selectedIndices.count(); *nRows = count; + *selectedRows = Q_NULLPTR; + if (count) { + *selectedRows = coTaskMemAllocArray(count); + std::copy(selectedIndices.constBegin(), selectedIndices.constEnd(), *selectedRows); + } return count ? S_OK : S_FALSE; } return E_FAIL; @@ -1648,12 +1658,13 @@ HRESULT QWindowsIA2Accessible::wrapListOfCells(const QList(count); + std::transform(inputCells.constBegin(), inputCells.constEnd(), + *outputAccessibles, QWindowsAccessibility::wrap); + } return count > 0 ? S_OK : S_FALSE; } -- cgit v1.2.3 From 4905bf06549ce33250b13e837d192e92bffffcdb Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 22 Feb 2016 16:58:38 +0100 Subject: Windows Accessibility: Fix warnings as shown by Qt Creator's Clang based code model. Introduce C++ casts and add some conversions. Where possible, increase const-correctness. Remove trivial conversion function BSTRToQString(). Task-number: QTBUG-50804 Change-Id: I1820d4693db8bc0dfa6c4a5fecd768cf64a4405c Reviewed-by: Joerg Bornemann --- .../platforms/windows/accessible/iaccessible2.cpp | 71 +++++++++++++--------- 1 file changed, 41 insertions(+), 30 deletions(-) (limited to 'src/plugins/platforms/windows/accessible/iaccessible2.cpp') diff --git a/src/plugins/platforms/windows/accessible/iaccessible2.cpp b/src/plugins/platforms/windows/accessible/iaccessible2.cpp index abca91a7db..7c0b0370b3 100644 --- a/src/plugins/platforms/windows/accessible/iaccessible2.cpp +++ b/src/plugins/platforms/windows/accessible/iaccessible2.cpp @@ -60,7 +60,7 @@ HRESULT STDMETHODCALLTYPE AccessibleApplication::QueryInterface(REFIID id, LPVOI *iface = 0; if (id == IID_IUnknown) { qCDebug(lcQpaAccessibility) << "AccessibleApplication::QI(): IID_IUnknown"; - *iface = (IUnknown*)this; + *iface = static_cast(this); } else if (id == IID_IAccessibleApplication) { qCDebug(lcQpaAccessibility) << "AccessibleApplication::QI(): IID_IAccessibleApplication"; *iface = static_cast(this); @@ -130,7 +130,7 @@ HRESULT STDMETHODCALLTYPE AccessibleRelation::QueryInterface(REFIID id, LPVOID * { *iface = 0; if (id == IID_IUnknown || id == IID_IAccessibleRelation) - *iface = (IUnknown*)this; + *iface = static_cast(this); if (*iface) { AddRef(); @@ -208,7 +208,7 @@ HRESULT STDMETHODCALLTYPE AccessibleRelation::get_targets( /* [retval][out] */ long *nTargets) { - const int numTargets = qMin((int)maxTargets, m_targets.count()); + const int numTargets = qMin(int(maxTargets), m_targets.count()); for (int i = 0; i < numTargets; ++i) { QAccessibleInterface *iface = m_targets.at(i); IAccessible *iacc = QWindowsAccessibility::wrap(iface); @@ -237,40 +237,40 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::QueryInterface(REFIID id, LPVOI HRESULT hr = QWindowsMsaaAccessible::QueryInterface(id, iface); if (!SUCCEEDED(hr)) { if (id == IID_IServiceProvider) { - *iface = (IServiceProvider*)this; + *iface = static_cast(this); } else if (id == IID_IAccessible2) { - *iface = (IAccessible2*)this; + *iface = static_cast(this); } else if (id == IID_IAccessibleAction) { if (accessible->actionInterface()) - *iface = (IAccessibleAction*)this; + *iface = static_cast(this); } else if (id == IID_IAccessibleComponent) { - *iface = (IAccessibleComponent*)this; + *iface = static_cast(this); } else if (id == IID_IAccessibleEditableText) { if (accessible->editableTextInterface() || accessible->role() == QAccessible::EditableText) { - *iface = (IAccessibleEditableText*)this; + *iface = static_cast(this); } } else if (id == IID_IAccessibleHyperlink) { - //*iface = (IAccessibleHyperlink*)this; + //*iface = static_cast(this); } else if (id == IID_IAccessibleHypertext) { - //*iface = (IAccessibleHypertext*)this; + //*iface = static_cast(this); } else if (id == IID_IAccessibleImage) { - //*iface = (IAccessibleImage*)this; + //*iface = static_cast(this); } else if (id == IID_IAccessibleTable) { - //*iface = (IAccessibleTable*)this; // not supported + //*iface = static_cast(this); // not supported } else if (id == IID_IAccessibleTable2) { if (accessible->tableInterface()) - *iface = (IAccessibleTable2*)this; + *iface = static_cast(this); } else if (id == IID_IAccessibleTableCell) { if (accessible->tableCellInterface()) - *iface = (IAccessibleTableCell*)this; + *iface = static_cast(this); } else if (id == IID_IAccessibleText) { if (accessible->textInterface()) - *iface = (IAccessibleText*)this; + *iface = static_cast(this); } else if (id == IID_IAccessibleValue) { if (accessible->valueInterface()) - *iface = (IAccessibleValue*)this; + *iface = static_cast(this); } if (*iface) { AddRef(); @@ -674,7 +674,7 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_foreground(IA2Color *foregr return E_FAIL; // IA2Color is a typedef for long - *foreground = (IA2Color)accessible->foregroundColor().rgb(); + *foreground = static_cast(accessible->foregroundColor().rgb()); return S_OK; } @@ -686,7 +686,7 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_background(IA2Color *backgr return E_FAIL; // IA2Color is a typedef for long - *background = (IA2Color)accessible->backgroundColor().rgb(); + *background = static_cast(accessible->backgroundColor().rgb()); return S_OK; } @@ -760,7 +760,7 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::insertText(long offset, BSTR *t { QAccessibleInterface *accessible = accessibleInterface(); accessibleDebugClientCalls(accessible); - const QString txt(BSTRToQString(*text)); + const QString txt = QString::fromWCharArray(*text); if (QAccessibleEditableTextInterface *editableTextIface = accessible->editableTextInterface()) editableTextIface->insertText(offset, txt); else @@ -805,7 +805,7 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::replaceText(long startOffset, l { QAccessibleInterface *accessible = accessibleInterface(); accessibleDebugClientCalls(accessible); - const QString txt(BSTRToQString(*text)); + const QString txt = QString::fromWCharArray(*text); if (QAccessibleEditableTextInterface *editableTextIface = accessible->editableTextInterface()) editableTextIface->replaceText(startOffset, endOffset, txt); else @@ -1206,10 +1206,10 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_rowColumnExtents(long *row, if (!accessible || !tableCellInterface()) return E_FAIL; - *row = (long)tableCellInterface()->rowIndex(); - *column = (long)tableCellInterface()->columnIndex(); - *rowExtents = (long)tableCellInterface()->rowExtent(); - *columnExtents = (long)tableCellInterface()->columnExtent(); + *row = tableCellInterface()->rowIndex(); + *column = tableCellInterface()->columnIndex(); + *rowExtents = tableCellInterface()->rowExtent(); + *columnExtents = tableCellInterface()->columnExtent(); *isSelected = tableCellInterface()->isSelected(); return S_OK; } @@ -1250,7 +1250,8 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_attributes(long offset, QAccessibleInterface *accessible = accessibleInterface(); accessibleDebugClientCalls(accessible); if (QAccessibleTextInterface *text = textInterface()) { - const QString attrs = text->attributes(offset, (int*)startOffset, (int*)endOffset); + const QString attrs = text->attributes(offset, reinterpret_cast(startOffset), + reinterpret_cast(endOffset)); *textAttributes = QStringToBSTR(attrs); return S_OK; } @@ -1322,7 +1323,8 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_selection(long selectionInd QAccessibleInterface *accessible = accessibleInterface(); accessibleDebugClientCalls(accessible); if (QAccessibleTextInterface *text = textInterface()) { - text->selection(selectionIndex, (int*)startOffset, (int*)endOffset); + text->selection(selectionIndex, reinterpret_cast(startOffset), + reinterpret_cast(endOffset)); return S_OK; } return E_FAIL; @@ -1354,7 +1356,10 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_textBeforeOffset(long offse QAccessibleInterface *accessible = accessibleInterface(); accessibleDebugClientCalls(accessible); if (QAccessibleTextInterface *textIface = textInterface()) { - const QString txt = textIface->textBeforeOffset(offset, (QAccessible::TextBoundaryType)boundaryType, (int*)startOffset, (int*)endOffset); + const QString txt = + textIface->textBeforeOffset(offset, static_cast(boundaryType), + reinterpret_cast(startOffset), + reinterpret_cast(endOffset)); if (!txt.isEmpty()) { *text = QStringToBSTR(txt); return S_OK; @@ -1374,7 +1379,10 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_textAfterOffset( QAccessibleInterface *accessible = accessibleInterface(); accessibleDebugClientCalls(accessible); if (QAccessibleTextInterface *textIface = textInterface()) { - const QString txt = textIface->textAfterOffset(offset, (QAccessible::TextBoundaryType)boundaryType, (int*)startOffset, (int*)endOffset); + const QString txt = + textIface->textAfterOffset(offset, static_cast(boundaryType), + reinterpret_cast(startOffset), + reinterpret_cast(endOffset)); if (!txt.isEmpty()) { *text = QStringToBSTR(txt); return S_OK; @@ -1393,7 +1401,10 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_textAtOffset(long offset, QAccessibleInterface *accessible = accessibleInterface(); accessibleDebugClientCalls(accessible); if (QAccessibleTextInterface *textIface = textInterface()) { - const QString txt = textIface->textAtOffset(offset, (QAccessible::TextBoundaryType)boundaryType, (int*)startOffset, (int*)endOffset); + const QString txt = + textIface->textAtOffset(offset, static_cast(boundaryType), + reinterpret_cast(startOffset), + reinterpret_cast(endOffset)); if (!txt.isEmpty()) { *text = QStringToBSTR(txt); return S_OK; @@ -1632,7 +1643,7 @@ HRESULT QWindowsIA2Accessible::getRelationsHelper(IAccessibleRelation **relation QList keys = relationMap.keys(); const int numRelations = keys.count(); if (relations) { - for (int i = startIndex; i < qMin(startIndex + (int)maxRelations, numRelations); ++i) { + for (int i = startIndex; i < qMin(startIndex + int(maxRelations), numRelations); ++i) { QAccessible::Relation relation = keys.at(i); QList targets = relationMap.values(relation); AccessibleRelation *rel = new AccessibleRelation(targets, relation); -- cgit v1.2.3