diff options
author | Colin Snover | 2017-09-23 20:01:05 -0500 |
---|---|---|
committer | Colin Snover | 2017-09-23 20:57:03 -0500 |
commit | dced2fb9f54bafa0770e479e0088021f59fc0a16 (patch) | |
tree | d7835919537ae9f9a91e305af478b440972ce3ca | |
parent | 6972c9ae46acba424bcdfb5a002ca03b0edf2874 (diff) | |
download | scummvm-rg350-dced2fb9f54bafa0770e479e0088021f59fc0a16.tar.gz scummvm-rg350-dced2fb9f54bafa0770e479e0088021f59fc0a16.tar.bz2 scummvm-rg350-dced2fb9f54bafa0770e479e0088021f59fc0a16.zip |
SCI32: Fix handling of array copies
kArrayCopy would perform an unnecessary memory copy of the source
array, the treatment of the count value as unsigned was clearly
not correct since it was being sign-extended and checked against
-1.
-rw-r--r-- | engines/sci/engine/klists.cpp | 12 | ||||
-rw-r--r-- | engines/sci/engine/segment.h | 6 |
2 files changed, 9 insertions, 9 deletions
diff --git a/engines/sci/engine/klists.cpp b/engines/sci/engine/klists.cpp index 2f66e51a6e..2ca5a65fc0 100644 --- a/engines/sci/engine/klists.cpp +++ b/engines/sci/engine/klists.cpp @@ -859,19 +859,19 @@ reg_t kArrayFill(EngineState *s, int argc, reg_t *argv) { reg_t kArrayCopy(EngineState *s, int argc, reg_t *argv) { SciArray &target = *s->_segMan->lookupArray(argv[0]); const uint16 targetIndex = argv[1].toUint16(); + const uint16 sourceIndex = argv[3].toUint16(); + const int16 count = argv[4].toSint16(); - SciArray source; - // String copies may be made from static script data if (!s->_segMan->isArray(argv[2])) { + // String copies may be made from static script data + SciArray source; source.setType(kArrayTypeString); source.fromString(s->_segMan->getString(argv[2])); + target.copy(source, sourceIndex, targetIndex, count); } else { - source = *s->_segMan->lookupArray(argv[2]); + target.copy(*s->_segMan->lookupArray(argv[2]), sourceIndex, targetIndex, count); } - const uint16 sourceIndex = argv[3].toUint16(); - const uint16 count = argv[4].toUint16(); - target.copy(source, sourceIndex, targetIndex, count); return argv[0]; } diff --git a/engines/sci/engine/segment.h b/engines/sci/engine/segment.h index a0c9f7f0dd..2b2e9466a2 100644 --- a/engines/sci/engine/segment.h +++ b/engines/sci/engine/segment.h @@ -761,12 +761,12 @@ public: * Copies values from the source array. Both arrays will be grown if needed * to prevent out-of-bounds reads/writes. */ - void copy(SciArray &source, const uint16 sourceIndex, const uint16 targetIndex, uint16 count) { - if (count == 65535 /* -1 */) { + void copy(SciArray &source, const uint16 sourceIndex, const uint16 targetIndex, int16 count) { + if (count == -1) { count = source.size() - sourceIndex; } - if (!count) { + if (count < 1) { return; } |