From 2be049069f25532e5e72ad38283d634f381e6f78 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Mon, 6 Mar 2023 18:39:32 +0100 Subject: [PATCH] Fix -Warray-bounds warnings on gcc With optimizations/inlining enabled GCC complains about gl - 10 resulting in a pointer to invalid memory when Dst is an array type rather than a pointer. --- dynasm/dasm_arm.h | 16 +++++++++++++++- dynasm/dasm_arm64.h | 16 +++++++++++++++- dynasm/dasm_mips.h | 16 +++++++++++++++- dynasm/dasm_ppc.h | 16 +++++++++++++++- dynasm/dasm_x86.h | 16 +++++++++++++++- 5 files changed, 75 insertions(+), 5 deletions(-) diff --git a/dynasm/dasm_arm.h b/dynasm/dasm_arm.h index fbfebee0..6a1b1afc 100644 --- a/dynasm/dasm_arm.h +++ b/dynasm/dasm_arm.h @@ -9,6 +9,20 @@ #include #include +#if defined(_MSC_VER) && (_MSC_VER < 1700) +/* Old MSVC is stuck in the last century and doesn't have C99's stdint.h. */ +#ifdef _WIN64 +typedef unsigned __int64 uintptr_t; +#else +typedef unsigned __int32 uintptr_t; +#endif +#elif defined(__symbian__) +/* Cough. */ +typedef unsigned int uintptr_t; +#else +#include +#endif + #define DASM_ARCH "arm" #ifndef DASM_EXTERN @@ -123,7 +137,7 @@ void dasm_free(Dst_DECL) void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl) { dasm_State *D = Dst_REF; - D->globals = gl - 10; /* Negative bias to compensate for locals. */ + D->globals = (void **)((uintptr_t)gl - 10); /* Negative bias to compensate for locals. */ DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int)); } diff --git a/dynasm/dasm_arm64.h b/dynasm/dasm_arm64.h index 47c9c37d..8fca98af 100644 --- a/dynasm/dasm_arm64.h +++ b/dynasm/dasm_arm64.h @@ -9,6 +9,20 @@ #include #include +#if defined(_MSC_VER) && (_MSC_VER < 1700) +/* Old MSVC is stuck in the last century and doesn't have C99's stdint.h. */ +#ifdef _WIN64 +typedef unsigned __int64 uintptr_t; +#else +typedef unsigned __int32 uintptr_t; +#endif +#elif defined(__symbian__) +/* Cough. */ +typedef unsigned int uintptr_t; +#else +#include +#endif + #define DASM_ARCH "arm64" #ifndef DASM_EXTERN @@ -125,7 +139,7 @@ void dasm_free(Dst_DECL) void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl) { dasm_State *D = Dst_REF; - D->globals = gl - 10; /* Negative bias to compensate for locals. */ + D->globals = (void **)((uintptr_t)gl - 10); /* Negative bias to compensate for locals. */ DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int)); } diff --git a/dynasm/dasm_mips.h b/dynasm/dasm_mips.h index 3e99a005..92f1f2df 100644 --- a/dynasm/dasm_mips.h +++ b/dynasm/dasm_mips.h @@ -9,6 +9,20 @@ #include #include +#if defined(_MSC_VER) && (_MSC_VER < 1700) +/* Old MSVC is stuck in the last century and doesn't have C99's stdint.h. */ +#ifdef _WIN64 +typedef unsigned __int64 uintptr_t; +#else +typedef unsigned __int32 uintptr_t; +#endif +#elif defined(__symbian__) +/* Cough. */ +typedef unsigned int uintptr_t; +#else +#include +#endif + #define DASM_ARCH "mips" #ifndef DASM_EXTERN @@ -122,7 +136,7 @@ void dasm_free(Dst_DECL) void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl) { dasm_State *D = Dst_REF; - D->globals = gl - 10; /* Negative bias to compensate for locals. */ + D->globals = (void **)((uintptr_t)gl - 10); /* Negative bias to compensate for locals. */ DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int)); } diff --git a/dynasm/dasm_ppc.h b/dynasm/dasm_ppc.h index fdb89bce..43eb94c9 100644 --- a/dynasm/dasm_ppc.h +++ b/dynasm/dasm_ppc.h @@ -9,6 +9,20 @@ #include #include +#if defined(_MSC_VER) && (_MSC_VER < 1700) +/* Old MSVC is stuck in the last century and doesn't have C99's stdint.h. */ +#ifdef _WIN64 +typedef unsigned __int64 uintptr_t; +#else +typedef unsigned __int32 uintptr_t; +#endif +#elif defined(__symbian__) +/* Cough. */ +typedef unsigned int uintptr_t; +#else +#include +#endif + #define DASM_ARCH "ppc" #ifndef DASM_EXTERN @@ -122,7 +136,7 @@ void dasm_free(Dst_DECL) void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl) { dasm_State *D = Dst_REF; - D->globals = gl - 10; /* Negative bias to compensate for locals. */ + D->globals = (void **)((uintptr_t)gl - 10); /* Negative bias to compensate for locals. */ DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int)); } diff --git a/dynasm/dasm_x86.h b/dynasm/dasm_x86.h index f0327302..56f463ac 100644 --- a/dynasm/dasm_x86.h +++ b/dynasm/dasm_x86.h @@ -9,6 +9,20 @@ #include #include +#if defined(_MSC_VER) && (_MSC_VER < 1700) +/* Old MSVC is stuck in the last century and doesn't have C99's stdint.h. */ +#ifdef _WIN64 +typedef unsigned __int64 uintptr_t; +#else +typedef unsigned __int32 uintptr_t; +#endif +#elif defined(__symbian__) +/* Cough. */ +typedef unsigned int uintptr_t; +#else +#include +#endif + #define DASM_ARCH "x86" #ifndef DASM_EXTERN @@ -121,7 +135,7 @@ void dasm_free(Dst_DECL) void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl) { dasm_State *D = Dst_REF; - D->globals = gl - 10; /* Negative bias to compensate for locals. */ + D->globals = (void **)((uintptr_t)gl - 10); /* Negative bias to compensate for locals. */ DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int)); }