[Scummvm-git-logs] scummvm master -> e909861527b810b4c50df1bc2b1feaa6267900e3
elasota
noreply at scummvm.org
Mon Aug 8 02:09:41 UTC 2022
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
e909861527 MTROPOLIS: Fix unrestricted unions still using memset
Commit: e909861527b810b4c50df1bc2b1feaa6267900e3
https://github.com/scummvm/scummvm/commit/e909861527b810b4c50df1bc2b1feaa6267900e3
Author: elasota (ejlasota at gmail.com)
Date: 2022-08-07T22:06:18-04:00
Commit Message:
MTROPOLIS: Fix unrestricted unions still using memset
Changed paths:
engines/mtropolis/miniscript.cpp
engines/mtropolis/miniscript.h
engines/mtropolis/runtime.cpp
diff --git a/engines/mtropolis/miniscript.cpp b/engines/mtropolis/miniscript.cpp
index 18e9f152acb..9de742715cb 100644
--- a/engines/mtropolis/miniscript.cpp
+++ b/engines/mtropolis/miniscript.cpp
@@ -1565,21 +1565,20 @@ MiniscriptInstructionOutcome GetChild::readRValueAttribIndexed(MiniscriptThread
PushValue::PushValue(DataType dataType, const void *value, bool isLValue)
: _dataType(dataType), _isLValue(isLValue) {
- memset(&this->_value, 0, sizeof(this->_value));
switch (dataType) {
case DataType::kDataTypeBool:
- _value.b = *static_cast<const bool *>(value);
+ new (static_cast<bool *>(&_value.b)) bool(*static_cast<const bool *>(value));
break;
case DataType::kDataTypeDouble:
- _value.f = *static_cast<const double *>(value);
+ new (static_cast<double *>(&_value.f)) double(*static_cast<const double *>(value));
break;
case DataType::kDataTypeLocalRef:
case DataType::kDataTypeGlobalRef:
- _value.ref = *static_cast<const uint32 *>(value);
+ new (static_cast<uint32 *>(&_value.ref)) uint32(*static_cast<const uint32 *>(value));
break;
case DataType::kDataTypeLabel:
- _value.lbl = *static_cast<const Label *>(value);
+ new (static_cast<Label *>(&_value.lbl)) Label(*static_cast<const Label *>(value));
break;
case DataType::kDataTypeNull:
break;
@@ -1589,6 +1588,19 @@ PushValue::PushValue(DataType dataType, const void *value, bool isLValue)
}
}
+PushValue::ValueUnion::ValueUnion() {
+}
+
+PushValue::~PushValue() {
+ switch (_dataType) {
+ case DataType::kDataTypeLabel:
+ _value.lbl.~Label();
+ break;
+ default:
+ break;
+ }
+}
+
MiniscriptInstructionOutcome ListCreate::execute(MiniscriptThread *thread) const {
if (thread->getStackSize() < 2) {
thread->error("Stack underflow");
diff --git a/engines/mtropolis/miniscript.h b/engines/mtropolis/miniscript.h
index d866147bcd7..ccdc3d24177 100644
--- a/engines/mtropolis/miniscript.h
+++ b/engines/mtropolis/miniscript.h
@@ -329,11 +329,14 @@ namespace MiniscriptInstructions {
};
PushValue(DataType dataType, const void *value, bool isLValue);
+ ~PushValue();
private:
MiniscriptInstructionOutcome execute(MiniscriptThread *thread) const override;
union ValueUnion {
+ ValueUnion();
+
bool b;
double f;
uint32 ref;
diff --git a/engines/mtropolis/runtime.cpp b/engines/mtropolis/runtime.cpp
index b9c1bd4d376..acdaaaa3b79 100644
--- a/engines/mtropolis/runtime.cpp
+++ b/engines/mtropolis/runtime.cpp
@@ -1162,7 +1162,6 @@ void DynamicValue::ValueUnion::destruct() {
}
DynamicValue::DynamicValue() : _type(DynamicValueTypes::kNull) {
- memset(&this->_value, 0, sizeof(this->_value));
}
DynamicValue::DynamicValue(const DynamicValue &other) : _type(DynamicValueTypes::kNull) {
More information about the Scummvm-git-logs
mailing list