Kaydet (Commit) ad9871a5 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Introduce SbxValues::clear

...to avoid upcoming GCC 8 -Werror=class-memaccess ("clearing an object of non-
trivial type ‘struct SbxValues’")

Change-Id: Icf610e692b81030bfd6f2f940c43ee8bf6f1d4e0
Reviewed-on: https://gerrit.libreoffice.org/48389Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst 42907261
...@@ -44,8 +44,7 @@ SbxValue::SbxValue( SbxDataType t ) : SbxBase() ...@@ -44,8 +44,7 @@ SbxValue::SbxValue( SbxDataType t ) : SbxBase()
n = SbxEMPTY; n = SbxEMPTY;
else else
SetFlag( SbxFlagBits::Fixed ); SetFlag( SbxFlagBits::Fixed );
memset( &aData, 0, sizeof( SbxValues ) ); aData.clear(SbxDataType( n ));
aData.eType = SbxDataType( n );
} }
SbxValue::SbxValue( const SbxValue& r ) SbxValue::SbxValue( const SbxValue& r )
...@@ -172,8 +171,7 @@ void SbxValue::Clear() ...@@ -172,8 +171,7 @@ void SbxValue::Clear()
default: default:
{ {
SbxValues aEmpty; SbxValues aEmpty;
memset( &aEmpty, 0, sizeof( SbxValues ) ); aEmpty.clear(GetType());
aEmpty.eType = GetType();
Put( aEmpty ); Put( aEmpty );
} }
} }
...@@ -341,8 +339,7 @@ bool SbxValue::Get( SbxValues& rRes ) const ...@@ -341,8 +339,7 @@ bool SbxValue::Get( SbxValues& rRes ) const
{ {
// Object contained itself // Object contained itself
SbxDataType eTemp = rRes.eType; SbxDataType eTemp = rRes.eType;
memset( &rRes, 0, sizeof( SbxValues ) ); rRes.clear(eTemp);
rRes.eType = eTemp;
} }
} }
if( !IsError() ) if( !IsError() )
...@@ -753,9 +750,7 @@ bool SbxValue::SetType( SbxDataType t ) ...@@ -753,9 +750,7 @@ bool SbxValue::SetType( SbxDataType t )
break; break;
default: break; default: break;
} }
// This works always, because the Float representations are 0 as well. aData.clear(t);
memset( &aData, 0, sizeof( SbxValues ) );
aData.eType = t;
} }
} }
return true; return true;
...@@ -1502,9 +1497,8 @@ bool SbxValue::LoadData( SvStream& r, sal_uInt16 ) ...@@ -1502,9 +1497,8 @@ bool SbxValue::LoadData( SvStream& r, sal_uInt16 )
case SbxWCHAR: case SbxWCHAR:
break; break;
default: default:
memset (&aData,0,sizeof(aData)); aData.clear(SbxNULL);
ResetFlag(SbxFlagBits::Fixed); ResetFlag(SbxFlagBits::Fixed);
aData.eType = SbxNULL;
SAL_WARN( "basic.sbx", "Loaded a non-supported data type" ); SAL_WARN( "basic.sbx", "Loaded a non-supported data type" );
return false; return false;
......
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
#include <com/sun/star/bridge/oleautomation/Decimal.hpp> #include <com/sun/star/bridge/oleautomation/Decimal.hpp>
#include <basic/sbxcore.hxx> #include <basic/sbxcore.hxx>
#include <basic/basicdllapi.h> #include <basic/basicdllapi.h>
#include <cstddef>
#include <cstring>
#include <memory> #include <memory>
...@@ -71,6 +74,15 @@ struct SbxValues ...@@ -71,6 +74,15 @@ struct SbxValues
SbxValues(): pData( nullptr ), eType(SbxEMPTY) {} SbxValues(): pData( nullptr ), eType(SbxEMPTY) {}
SbxValues( SbxDataType e ): eType(e) {} SbxValues( SbxDataType e ): eType(e) {}
SbxValues( double _nDouble ): nDouble( _nDouble ), eType(SbxDOUBLE) {} SbxValues( double _nDouble ): nDouble( _nDouble ), eType(SbxDOUBLE) {}
void clear(SbxDataType type) {
// A hacky way of zeroing the union value corresponding to the given type (even though the
// relevant zero value need not be represented by all-zero bits, in general) without evoking
// GCC 8 -Wclass-memaccess, and without having to turn the anonymous union into a non-
// anonymous one:
std::memset(static_cast<void *>(this), 0, offsetof(SbxValues, eType));
eType = type;
}
}; };
class BASIC_DLLPUBLIC SbxValue : public SbxBase class BASIC_DLLPUBLIC SbxValue : public SbxBase
......
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