diff options
author | Max Horn | 2014-03-30 19:48:08 +0200 |
---|---|---|
committer | Max Horn | 2014-03-30 19:48:08 +0200 |
commit | 8638b29b8933e1cee30c5bac8641278ba039a1f8 (patch) | |
tree | 144244ffedb02a7ca849e0b9dcfdd1dc9bd0e8f1 | |
parent | 4d02f67bd1dc3b7fc9eb8729f92a4d5d41a6831a (diff) | |
download | scummvm-rg350-8638b29b8933e1cee30c5bac8641278ba039a1f8.tar.gz scummvm-rg350-8638b29b8933e1cee30c5bac8641278ba039a1f8.tar.bz2 scummvm-rg350-8638b29b8933e1cee30c5bac8641278ba039a1f8.zip |
SCUMM: Avoid potential issues casting invalid values to enum
A compiler could in principle decide that a ResType enum can
never equal 0xFF or 0xFFFF, and thus incorrectly optimize
the ScummEngine::saveOrLoad code. So check the value
*before* casting it.
-rw-r--r-- | engines/scumm/saveload.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp index fc3c193e74..0aaff4c094 100644 --- a/engines/scumm/saveload.cpp +++ b/engines/scumm/saveload.cpp @@ -1242,7 +1242,9 @@ void ScummEngine::saveOrLoad(Serializer *s) { } s->saveUint16(0xFFFF); // End marker } else { - while ((int)(type = (ResType)s->loadUint16()) != 0xFFFF) { + uint16 tmp; + while ((tmp = s->loadUint16()) != 0xFFFF) { + type = (ResType)tmp; while ((idx = s->loadUint16()) != 0xFFFF) { assert(idx < _res->_types[type].size()); loadResource(s, type, idx); @@ -1430,7 +1432,9 @@ void ScummEngine::saveOrLoad(Serializer *s) { } s->saveByte(0xFF); } else { - while ((int)(type = (ResType)s->loadByte()) != 0xFF) { + uint8 tmp; + while ((tmp = s->loadByte()) != 0xFF) { + type = (ResType)tmp; idx = s->loadUint16(); _res->lock(type, idx); } |