From a6caf3a951b695c6f42683598043531f82a54b20 Mon Sep 17 00:00:00 2001 From: Thierry Crozat Date: Fri, 6 Oct 2017 00:59:11 +0100 Subject: MOHAWK: Fix undefined behaviour in variadic functions Passing a type that undergoes default argument promotion as last argument of a variadic function results in undefined behaviour. --- engines/mohawk/riven_scripts.cpp | 4 ++-- engines/mohawk/riven_scripts.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/mohawk') diff --git a/engines/mohawk/riven_scripts.cpp b/engines/mohawk/riven_scripts.cpp index cb040ee4a0..18a3597086 100644 --- a/engines/mohawk/riven_scripts.cpp +++ b/engines/mohawk/riven_scripts.cpp @@ -147,13 +147,13 @@ void RivenScriptManager::runQueuedScripts() { _runningQueuedScripts = false; } -RivenScriptPtr RivenScriptManager::createScriptFromData(uint16 commandCount, ...) { +RivenScriptPtr RivenScriptManager::createScriptFromData(uint commandCount, ...) { va_list args; va_start(args, commandCount); // Build a script from the variadic arguments Common::MemoryWriteStreamDynamic writeStream = Common::MemoryWriteStreamDynamic(DisposeAfterUse::YES); - writeStream.writeUint16BE(commandCount); + writeStream.writeUint16BE((uint16)commandCount); for (uint i = 0; i < commandCount; i++) { uint16 command = va_arg(args, int); diff --git a/engines/mohawk/riven_scripts.h b/engines/mohawk/riven_scripts.h index 25cf363450..423434fe59 100644 --- a/engines/mohawk/riven_scripts.h +++ b/engines/mohawk/riven_scripts.h @@ -179,7 +179,7 @@ public: RivenScriptPtr readScriptFromData(uint16 *data, uint16 size); /** Create a script from the caller provided arguments containing raw data */ - RivenScriptPtr createScriptFromData(uint16 commandCount, ...); + RivenScriptPtr createScriptFromData(uint commandCount, ...); /** * Create a script with a single user provided command -- cgit v1.2.3