aboutsummaryrefslogtreecommitdiff
path: root/engines/sky
diff options
context:
space:
mode:
authorColin Snover2017-11-07 22:53:19 -0600
committerEugene Sandulenko2017-12-08 07:55:56 +0000
commit8e829371c9d12fc121e9edbd05d40a2f03166cf1 (patch)
treeeac7643d790a606cbbf3fa1e6f1728ab0a5dca78 /engines/sky
parent4c777a9afcd402adda3335e46eac6ffcd24205f0 (diff)
downloadscummvm-rg350-8e829371c9d12fc121e9edbd05d40a2f03166cf1.tar.gz
scummvm-rg350-8e829371c9d12fc121e9edbd05d40a2f03166cf1.tar.bz2
scummvm-rg350-8e829371c9d12fc121e9edbd05d40a2f03166cf1.zip
SKY: Fix unaligned pointer dereferences
Dereferencing an unaligned pointer will cause a memory fault on at least older ARM and SPARC architectures, and is warned about starting in Clang 4.
Diffstat (limited to 'engines/sky')
-rw-r--r--engines/sky/compact.cpp41
-rw-r--r--engines/sky/compact.h3
-rw-r--r--engines/sky/logic.cpp42
3 files changed, 54 insertions, 32 deletions
diff --git a/engines/sky/compact.cpp b/engines/sky/compact.cpp
index ab244c1f84..13ea300942 100644
--- a/engines/sky/compact.cpp
+++ b/engines/sky/compact.cpp
@@ -311,24 +311,47 @@ const char *SkyCompact::nameForType(uint16 type) {
return _typeNames[type];
}
-uint16 *SkyCompact::getSub(Compact *cpt, uint16 mode) {
+uint16 SkyCompact::getSub(Compact *cpt, uint16 mode) {
switch (mode) {
case 0:
- return &(cpt->baseSub);
+ return cpt->baseSub;
case 2:
- return &(cpt->baseSub_off);
+ return cpt->baseSub_off;
case 4:
- return &(cpt->actionSub);
+ return cpt->actionSub;
case 6:
- return &(cpt->actionSub_off);
+ return cpt->actionSub_off;
case 8:
- return &(cpt->getToSub);
+ return cpt->getToSub;
case 10:
- return &(cpt->getToSub_off);
+ return cpt->getToSub_off;
case 12:
- return &(cpt->extraSub);
+ return cpt->extraSub;
case 14:
- return &(cpt->extraSub_off);
+ return cpt->extraSub_off;
+ default:
+ error("Invalid Mode (%d)", mode);
+ }
+}
+
+void SkyCompact::setSub(Compact *cpt, uint16 mode, uint16 value) {
+ switch (mode) {
+ case 0:
+ cpt->baseSub = value;
+ case 2:
+ cpt->baseSub_off = value;
+ case 4:
+ cpt->actionSub = value;
+ case 6:
+ cpt->actionSub_off = value;
+ case 8:
+ cpt->getToSub = value;
+ case 10:
+ cpt->getToSub_off = value;
+ case 12:
+ cpt->extraSub = value;
+ case 14:
+ cpt->extraSub_off = value;
default:
error("Invalid Mode (%d)", mode);
}
diff --git a/engines/sky/compact.h b/engines/sky/compact.h
index 86db0ba55b..57ccb7fdaf 100644
--- a/engines/sky/compact.h
+++ b/engines/sky/compact.h
@@ -62,7 +62,8 @@ public:
~SkyCompact();
Compact *fetchCpt(uint16 cptId);
Compact *fetchCptInfo(uint16 cptId, uint16 *elems = NULL, uint16 *type = NULL, char *name = NULL);
- static uint16 *getSub(Compact *cpt, uint16 mode);
+ static uint16 getSub(Compact *cpt, uint16 mode);
+ static void setSub(Compact *cpt, uint16 mode, uint16 value);
static MegaSet *getMegaSet(Compact *cpt);
uint16 *getGrafixPtr(Compact *cpt);
uint16 *getTurnTable(Compact *cpt, uint16 dir);
diff --git a/engines/sky/logic.cpp b/engines/sky/logic.cpp
index c96d74e950..8833b45078 100644
--- a/engines/sky/logic.cpp
+++ b/engines/sky/logic.cpp
@@ -182,12 +182,13 @@ void Logic::logicScript() {
for (;;) {
uint16 mode = _compact->mode; // get pointer to current script
- uint16 *scriptNo = SkyCompact::getSub(_compact, mode);
- uint16 *offset = SkyCompact::getSub(_compact, mode + 2);
+ uint16 scriptNo = SkyCompact::getSub(_compact, mode);
+ uint16 offset = SkyCompact::getSub(_compact, mode + 2);
- *offset = script(*scriptNo, *offset);
+ offset = script(scriptNo, offset);
+ SkyCompact::setSub(_compact, mode + 2, offset);
- if (!*offset) // script finished
+ if (!offset) // script finished
_compact->mode -= 4;
else if (_compact->mode == mode)
return;
@@ -294,7 +295,7 @@ void Logic::arAnim() {
// tell it it is waiting for us
cpt->waitingFor = (uint16)(_scriptVariables[CUR_ID] & 0xffff);
// restart current script
- *SkyCompact::getSub(_compact, _compact->mode + 2) = 0;
+ SkyCompact::setSub(_compact, _compact->mode + 2, 0);
_compact->logic = L_SCRIPT;
logicScript();
return;
@@ -337,7 +338,7 @@ void Logic::arAnim() {
// changed so restart the current script
// *not suitable for base initiated ARing
- *SkyCompact::getSub(_compact, _compact->mode + 2) = 0;
+ SkyCompact::setSub(_compact, _compact->mode + 2, 0);
_compact->logic = L_SCRIPT;
logicScript();
@@ -414,8 +415,8 @@ void Logic::arTurn() {
void Logic::alt() {
/// change the current script
_compact->logic = L_SCRIPT;
- *SkyCompact::getSub(_compact, _compact->mode) = _compact->alt;
- *SkyCompact::getSub(_compact, _compact->mode + 2) = 0;
+ SkyCompact::setSub(_compact, _compact->mode, _compact->alt);
+ SkyCompact::setSub(_compact, _compact->mode + 2, 0);
logicScript();
}
@@ -633,7 +634,7 @@ void Logic::stopped() {
// we are free, continue processing the script
// restart script one level below
- *SkyCompact::getSub(_compact, _compact->mode - 2) = 0;
+ SkyCompact::setSub(_compact, _compact->mode - 2, 0);
_compact->waitingFor = 0xffff;
_compact->logic = L_SCRIPT;
@@ -782,11 +783,8 @@ void Logic::runGetOff() {
void Logic::stopAndWait() {
_compact->mode += 4;
- uint16 *scriptNo = SkyCompact::getSub(_compact, _compact->mode);
- uint16 *offset = SkyCompact::getSub(_compact, _compact->mode + 2);
-
- *scriptNo = _compact->stopScript;
- *offset = 0;
+ SkyCompact::setSub(_compact, _compact->mode, _compact->stopScript);
+ SkyCompact::setSub(_compact, _compact->mode + 2, 0);
_compact->logic = L_SCRIPT;
logicScript();
@@ -1457,24 +1455,24 @@ bool Logic::fnInteract(uint32 targetId, uint32 b, uint32 c) {
_compact->logic = L_SCRIPT;
Compact *cpt = _skyCompact->fetchCpt(targetId);
- *SkyCompact::getSub(_compact, _compact->mode) = cpt->actionScript;
- *SkyCompact::getSub(_compact, _compact->mode + 2) = 0;
+ SkyCompact::setSub(_compact, _compact->mode, cpt->actionScript);
+ SkyCompact::setSub(_compact, _compact->mode + 2, 0);
return false;
}
bool Logic::fnStartSub(uint32 scr, uint32 b, uint32 c) {
_compact->mode += 4;
- *SkyCompact::getSub(_compact, _compact->mode) = (uint16)(scr & 0xffff);
- *SkyCompact::getSub(_compact, _compact->mode + 2) = (uint16)(scr >> 16);
+ SkyCompact::setSub(_compact, _compact->mode, scr & 0xffff);
+ SkyCompact::setSub(_compact, _compact->mode + 2, scr >> 16);
return false;
}
bool Logic::fnTheyStartSub(uint32 mega, uint32 scr, uint32 c) {
Compact *cpt = _skyCompact->fetchCpt(mega);
cpt->mode += 4;
- *SkyCompact::getSub(cpt, cpt->mode) = (uint16)(scr & 0xffff);
- *SkyCompact::getSub(cpt, cpt->mode + 2) = (uint16)(scr >> 16);
+ SkyCompact::setSub(cpt, cpt->mode, scr & 0xffff);
+ SkyCompact::setSub(cpt, cpt->mode + 2, scr >> 16);
return true;
}
@@ -1558,8 +1556,8 @@ bool Logic::fnGetTo(uint32 targetPlaceId, uint32 mode, uint32 c) {
getToTable += 2;
// get new script
- *SkyCompact::getSub(_compact, _compact->mode) = *(getToTable + 1);
- *SkyCompact::getSub(_compact, _compact->mode + 2) = 0;
+ SkyCompact::setSub(_compact, _compact->mode, *(getToTable + 1));
+ SkyCompact::setSub(_compact, _compact->mode + 2, 0);
return false; // drop out of script
}