aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/engine/klists.cpp
diff options
context:
space:
mode:
authorColin Snover2017-09-23 20:01:05 -0500
committerColin Snover2017-09-23 20:57:03 -0500
commitdced2fb9f54bafa0770e479e0088021f59fc0a16 (patch)
treed7835919537ae9f9a91e305af478b440972ce3ca /engines/sci/engine/klists.cpp
parent6972c9ae46acba424bcdfb5a002ca03b0edf2874 (diff)
downloadscummvm-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.
Diffstat (limited to 'engines/sci/engine/klists.cpp')
-rw-r--r--engines/sci/engine/klists.cpp12
1 files changed, 6 insertions, 6 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];
}