summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--basic/source/sbx/sbxvalue.cxx16
-rw-r--r--include/basic/sbxvar.hxx12
2 files changed, 17 insertions, 11 deletions
diff --git a/basic/source/sbx/sbxvalue.cxx b/basic/source/sbx/sbxvalue.cxx
index dcf336544c3e..0f609d866135 100644
--- a/basic/source/sbx/sbxvalue.cxx
+++ b/basic/source/sbx/sbxvalue.cxx
@@ -44,8 +44,7 @@ SbxValue::SbxValue( SbxDataType t ) : SbxBase()
n = SbxEMPTY;
else
SetFlag( SbxFlagBits::Fixed );
- memset( &aData, 0, sizeof( SbxValues ) );
- aData.eType = SbxDataType( n );
+ aData.clear(SbxDataType( n ));
}
SbxValue::SbxValue( const SbxValue& r )
@@ -172,8 +171,7 @@ void SbxValue::Clear()
default:
{
SbxValues aEmpty;
- memset( &aEmpty, 0, sizeof( SbxValues ) );
- aEmpty.eType = GetType();
+ aEmpty.clear(GetType());
Put( aEmpty );
}
}
@@ -341,8 +339,7 @@ bool SbxValue::Get( SbxValues& rRes ) const
{
// Object contained itself
SbxDataType eTemp = rRes.eType;
- memset( &rRes, 0, sizeof( SbxValues ) );
- rRes.eType = eTemp;
+ rRes.clear(eTemp);
}
}
if( !IsError() )
@@ -753,9 +750,7 @@ bool SbxValue::SetType( SbxDataType t )
break;
default: break;
}
- // This works always, because the Float representations are 0 as well.
- memset( &aData, 0, sizeof( SbxValues ) );
- aData.eType = t;
+ aData.clear(t);
}
}
return true;
@@ -1502,9 +1497,8 @@ bool SbxValue::LoadData( SvStream& r, sal_uInt16 )
case SbxWCHAR:
break;
default:
- memset (&aData,0,sizeof(aData));
+ aData.clear(SbxNULL);
ResetFlag(SbxFlagBits::Fixed);
- aData.eType = SbxNULL;
SAL_WARN( "basic.sbx", "Loaded a non-supported data type" );
return false;
diff --git a/include/basic/sbxvar.hxx b/include/basic/sbxvar.hxx
index b189d4e32c26..1908ce83b73e 100644
--- a/include/basic/sbxvar.hxx
+++ b/include/basic/sbxvar.hxx
@@ -24,6 +24,9 @@
#include <com/sun/star/bridge/oleautomation/Decimal.hpp>
#include <basic/sbxcore.hxx>
#include <basic/basicdllapi.h>
+
+#include <cstddef>
+#include <cstring>
#include <memory>
@@ -71,6 +74,15 @@ struct SbxValues
SbxValues(): pData( nullptr ), eType(SbxEMPTY) {}
SbxValues( SbxDataType e ): eType(e) {}
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