Kaydet (Commit) 0973e1f4 authored tarafından Noel Grandin's avatar Noel Grandin

follow on for tdf#116981

the previous commit 235d61890512894e27f4f81e38a325eee3c67b30, fixed just
exactly the problem reported in tdf#116981.

This commit fixes similar issues that may exist elsewhere.

To recap, this started as a regression from
        commit  433fc221 (patch)
        sal_uIntPtr->sal_Int32 in MultiSelection

Previously, MultiSelection stored it's values internally as sal_uIntPtr,
but returned them as long in FirstSelected(), NextSelected(),
and SFX_ENDOFSELECTION was defined to be ULONG_MAX.
On 64-bit Linux, sal_uIntPtr is typedefed to sal_uInt64, and ULONG_MAX
is 2^64, which means that previously, the SFX_ENDOFSELECTION value was
being converted from 2^64 to -2^63 when it was returned, which was why
these loop worked.

So convert SFX_ENDOFSELECTION to SAL_MIN_INT32, so we get a large
negative value which can never be a valid index, and which works more
like it did before the regression.
Also fix as many loops as I can find, to check against
SFX_ENDOFSELECTION explicitly.

Change-Id: I947d43dbe23a08105be3d849e33d7e774a8a19fa
Reviewed-on: https://gerrit.libreoffice.org/52934Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 914f6385
......@@ -1915,7 +1915,7 @@ void SbaTableQueryBrowser::Execute(sal_uInt16 nId, const Sequence< PropertyValue
aSelection.realloc(pSelection->GetSelectCount());
long nIdx = pSelection->FirstSelected();
Any* pSelectionNos = aSelection.getArray();
while (nIdx >= 0)
while (nIdx != SFX_ENDOFSELECTION)
{
*pSelectionNos++ <<= static_cast<sal_Int32>(nIdx + 1);
nIdx = pSelection->NextSelected();
......
......@@ -715,7 +715,7 @@ void OTableEditorCtrl::CopyRows()
std::vector< std::shared_ptr<OTableRow> > vClipboardList;
vClipboardList.reserve(GetSelectRowCount());
for( long nIndex=FirstSelectedRow(); nIndex >= 0 && nIndex < static_cast<long>(m_pRowList->size()); nIndex=NextSelectedRow() )
for( long nIndex=FirstSelectedRow(); nIndex != SFX_ENDOFSELECTION; nIndex=NextSelectedRow() )
{
pRow = (*m_pRowList)[nIndex];
OSL_ENSURE(pRow,"OTableEditorCtrl::CopyRows: Row is NULL!");
......@@ -814,7 +814,7 @@ void OTableEditorCtrl::DeleteRows()
long nIndex = FirstSelectedRow();
nOldDataPos = nIndex;
while( nIndex >= 0 && nIndex < static_cast<long>(m_pRowList->size()) )
while( nIndex != SFX_ENDOFSELECTION )
{
// Remove rows
m_pRowList->erase( m_pRowList->begin()+nIndex );
......@@ -1120,7 +1120,7 @@ bool OTableEditorCtrl::IsCopyAllowed()
// If one of the selected rows is empty, Copy is not possible
std::shared_ptr<OTableRow> pRow;
long nIndex = FirstSelectedRow();
while( nIndex >= 0 && nIndex < static_cast<long>(m_pRowList->size()) )
while( nIndex != SFX_ENDOFSELECTION )
{
pRow = (*m_pRowList)[nIndex];
if( !pRow->GetActFieldDescr() )
......@@ -1278,7 +1278,7 @@ bool OTableEditorCtrl::IsPrimaryKeyAllowed( long /*nRow*/ )
// - DROP is not permitted (see above) and the column is not Required (not null flag is not set).
long nIndex = FirstSelectedRow();
std::shared_ptr<OTableRow> pRow;
while( nIndex >= 0 && nIndex < static_cast<long>(m_pRowList->size()) )
while( nIndex != SFX_ENDOFSELECTION )
{
pRow = (*m_pRowList)[nIndex];
OFieldDescription* pFieldDescr = pRow->GetActFieldDescr();
......@@ -1513,7 +1513,7 @@ void OTableEditorCtrl::SetPrimaryKey( bool bSet )
if( bSet )
{
long nIndex = FirstSelectedRow();
while( nIndex >= 0 && nIndex < static_cast<long>(m_pRowList->size()) )
while( nIndex != SFX_ENDOFSELECTION )
{
// Set the key
std::shared_ptr<OTableRow> pRow = (*m_pRowList)[nIndex];
......
......@@ -26,7 +26,7 @@
#include <vector>
#include <set>
#define SFX_ENDOFSELECTION SAL_MAX_INT32
#define SFX_ENDOFSELECTION SAL_MIN_INT32
class SAL_WARN_UNUSED TOOLS_DLLPUBLIC MultiSelection
{
......
......@@ -231,7 +231,7 @@ uno::Sequence<uno::Any> OFieldExpressionControl::fillSelectedGroups()
sal_Int32 nCount = xGroups->getCount();
if ( nCount >= 1 )
{
for( long nIndex=FirstSelectedRow(); nIndex >= 0 ; nIndex=NextSelectedRow() )
for( long nIndex=FirstSelectedRow(); nIndex != SFX_ENDOFSELECTION; nIndex=NextSelectedRow() )
{
try
{
......@@ -701,7 +701,7 @@ void OFieldExpressionControl::Command(const CommandEvent& rEvt)
{
bool bEnable = false;
long nIndex = FirstSelectedRow();
while( nIndex >= 0 && !bEnable )
while( nIndex != SFX_ENDOFSELECTION && !bEnable )
{
if ( m_aGroupPositions[nIndex] != NO_GROUP )
bEnable = true;
......@@ -734,7 +734,7 @@ void OFieldExpressionControl::DeleteRows()
DeactivateCell();
}
long nIndex = FirstSelectedRow();
if (nIndex == -1)
if (nIndex == SFX_ENDOFSELECTION)
{
nIndex = GetCurRow();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment