From 2dcf33bd42b068b8f9c2b191ff2bbe7196be619d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Thu, 16 Feb 2017 16:50:35 +0100 Subject: [PATCH] Ensure set_format_body macro only accepts properly sized arguments --- CMakeLists.txt | 2 +- src/openrct2/localisation/localisation.h | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f71324f85f..145d1e0a22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -289,7 +289,7 @@ else () endif () # set necessary flags to compile code as is -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TARGET_M} -std=gnu99 ${COMMON_COMPILE_OPTIONS} -Wimplicit") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TARGET_M} -std=gnu11 ${COMMON_COMPILE_OPTIONS} -Wimplicit") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TARGET_M} -std=gnu++14 ${COMMON_COMPILE_OPTIONS} -Wnon-virtual-dtor") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${TARGET_M}") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS} ${PIE_FLAG}") diff --git a/src/openrct2/localisation/localisation.h b/src/openrct2/localisation/localisation.h index 8a2b671c2c..439db31af5 100644 --- a/src/openrct2/localisation/localisation.h +++ b/src/openrct2/localisation/localisation.h @@ -85,9 +85,11 @@ static inline void set_format_arg_body(uint8 *args, size_t offset, uintptr_t val } #define set_format_arg(offset, type, value) \ - set_format_arg_body(gCommonFormatArgs, offset, (uintptr_t)value, sizeof(type)) + do { static_assert(sizeof(type) <= sizeof(uintptr_t), "Type too large"); \ + set_format_arg_body(gCommonFormatArgs, offset, (uintptr_t)value, sizeof(type)); } while (0) #define set_map_tooltip_format_arg(offset, type, value) \ - set_format_arg_body(gMapTooltipFormatArgs, offset, (uintptr_t)value, sizeof(type)) + do { static_assert(sizeof(type) <= sizeof(uintptr_t), "Type too large"); \ + set_format_arg_body(gMapTooltipFormatArgs, offset, (uintptr_t)value, sizeof(type)); } while (0) #endif