aboutsummaryrefslogtreecommitdiff
path: root/engines/lure
diff options
context:
space:
mode:
authorThierry Crozat2017-11-10 22:20:54 +0000
committerGitHub2017-11-10 22:20:54 +0000
commit2b00829f09609447758dc55956dd6a345b878c4b (patch)
tree06de1770adfa05ba89df7398dc48eb9fef1da133 /engines/lure
parentb73892e441bc3fde3b36f76aa675c59a652ca95c (diff)
parentb1ba071ea8a128f94f70f9a28270644e5d70b6fb (diff)
downloadscummvm-rg350-2b00829f09609447758dc55956dd6a345b878c4b.tar.gz
scummvm-rg350-2b00829f09609447758dc55956dd6a345b878c4b.tar.bz2
scummvm-rg350-2b00829f09609447758dc55956dd6a345b878c4b.zip
Merge pull request #1041 from criezy/variadic-undefined
Fix undefined behaviour in variadic functions
Diffstat (limited to 'engines/lure')
-rw-r--r--engines/lure/res_struct.cpp14
-rw-r--r--engines/lure/res_struct.h4
2 files changed, 12 insertions, 6 deletions
diff --git a/engines/lure/res_struct.cpp b/engines/lure/res_struct.cpp
index ec1a546d05..286489da82 100644
--- a/engines/lure/res_struct.cpp
+++ b/engines/lure/res_struct.cpp
@@ -827,9 +827,13 @@ void SequenceDelayList::loadFromStream(Common::ReadStream *stream) {
// The following classes hold the NPC schedules
-CharacterScheduleEntry::CharacterScheduleEntry(Action theAction, ...) {
+// The following function should really take a Action parameter, but the
+// behaviour is undefined if the last argument of a variadic function
+// undergoes default argument promotion, which might be the case for enum
+// types.
+CharacterScheduleEntry::CharacterScheduleEntry(int theAction, ...) {
_parent = NULL;
- _action = theAction;
+ _action = (Action)theAction;
va_list u_Arg;
va_start(u_Arg, theAction);
@@ -870,8 +874,10 @@ uint16 CharacterScheduleEntry::param(int index) {
return _params[index];
}
-void CharacterScheduleEntry::setDetails(Action theAction, ...) {
- _action = theAction;
+// The parameter to this function should really be an Action.
+// But... (see comment above for CharacterScheduleEntry(int, ...))
+void CharacterScheduleEntry::setDetails(int theAction, ...) {
+ _action = (Action)theAction;
_numParams = actionNumParams[_action];
va_list list;
diff --git a/engines/lure/res_struct.h b/engines/lure/res_struct.h
index 685c55ab13..a8a5e5aca8 100644
--- a/engines/lure/res_struct.h
+++ b/engines/lure/res_struct.h
@@ -404,7 +404,7 @@ private:
int _numParams;
public:
CharacterScheduleEntry() { _action = NONE; _parent = NULL; }
- CharacterScheduleEntry(Action theAction, ...);
+ CharacterScheduleEntry(int theAction, ...);
CharacterScheduleEntry(CharacterScheduleSet *parentSet,
CharacterScheduleResource *&rec);
CharacterScheduleEntry(CharacterScheduleEntry *src);
@@ -412,7 +412,7 @@ public:
Action action() { return _action; }
int numParams() { return _numParams; }
uint16 param(int index);
- void setDetails(Action theAction, ...);
+ void setDetails(int theAction, ...);
void setDetails2(Action theAction, int numParamEntries, uint16 *paramList);
CharacterScheduleEntry *next();
CharacterScheduleSet *parent() { return _parent; }