From 19f27381a167c3713ff0417fd96651bb0469d2a6 Mon Sep 17 00:00:00 2001 From: Cloudwalk Date: Tue, 25 May 2021 16:13:24 -0400 Subject: [PATCH] Merge intoverflow.h into qdefs.h --- darkplaces-sdl2-vs2017.vcxproj | 1 - darkplaces-sdl2-vs2019.vcxproj | 1 - gl_textures.c | 1 - intoverflow.h | 22 ---------------------- qdefs.h | 18 ++++++++++++++++++ 5 files changed, 18 insertions(+), 25 deletions(-) delete mode 100644 intoverflow.h diff --git a/darkplaces-sdl2-vs2017.vcxproj b/darkplaces-sdl2-vs2017.vcxproj index eb3ac72a..b984b24b 100644 --- a/darkplaces-sdl2-vs2017.vcxproj +++ b/darkplaces-sdl2-vs2017.vcxproj @@ -352,7 +352,6 @@ - diff --git a/darkplaces-sdl2-vs2019.vcxproj b/darkplaces-sdl2-vs2019.vcxproj index c24c3c28..70055977 100644 --- a/darkplaces-sdl2-vs2019.vcxproj +++ b/darkplaces-sdl2-vs2019.vcxproj @@ -353,7 +353,6 @@ - diff --git a/gl_textures.c b/gl_textures.c index ee3d575b..d1ec62a3 100644 --- a/gl_textures.c +++ b/gl_textures.c @@ -3,7 +3,6 @@ #include "image.h" #include "jpeg.h" #include "image_png.h" -#include "intoverflow.h" cvar_t gl_max_size = {CF_CLIENT | CF_ARCHIVE, "gl_max_size", "2048", "maximum allowed texture size, can be used to reduce video memory usage, limited by hardware capabilities (typically 2048, 4096, or 8192)"}; cvar_t gl_max_lightmapsize = {CF_CLIENT | CF_ARCHIVE, "gl_max_lightmapsize", "512", "maximum allowed texture size for lightmap textures, use larger values to improve rendering speed, as long as there is enough video memory available (setting it too high for the hardware will cause very bad performance)"}; diff --git a/intoverflow.h b/intoverflow.h deleted file mode 100644 index df906168..00000000 --- a/intoverflow.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef INTOVERFLOW_H -#define INTOVERFLOW_H - -// simple safe library to handle integer overflows when doing buffer size calculations -// Usage: -// - calculate data size using INTOVERFLOW_??? macros -// - compare: calculated-size <= INTOVERFLOW_NORMALIZE(buffersize) -// Functionality: -// - all overflows (values > INTOVERFLOW_MAX) and errors are mapped to INTOVERFLOW_MAX -// - if any input of an operation is INTOVERFLOW_MAX, INTOVERFLOW_MAX will be returned -// - otherwise, regular arithmetics apply - -#define INTOVERFLOW_MAX 2147483647 - -#define INTOVERFLOW_ADD(a,b) (((a) < INTOVERFLOW_MAX && (b) < INTOVERFLOW_MAX && (a) < INTOVERFLOW_MAX - (b)) ? ((a) + (b)) : INTOVERFLOW_MAX) -#define INTOVERFLOW_SUB(a,b) (((a) < INTOVERFLOW_MAX && (b) < INTOVERFLOW_MAX && (b) <= (a)) ? ((a) - (b)) : INTOVERFLOW_MAX) -#define INTOVERFLOW_MUL(a,b) (((a) < INTOVERFLOW_MAX && (b) < INTOVERFLOW_MAX && (a) < INTOVERFLOW_MAX / (b)) ? ((a) * (b)) : INTOVERFLOW_MAX) -#define INTOVERFLOW_DIV(a,b) (((a) < INTOVERFLOW_MAX && (b) < INTOVERFLOW_MAX && (b) > 0) ? ((a) / (b)) : INTOVERFLOW_MAX) - -#define INTOVERFLOW_NORMALIZE(a) (((a) < INTOVERFLOW_MAX) ? (a) : (INTOVERFLOW_MAX - 1)) - -#endif diff --git a/qdefs.h b/qdefs.h index 463761e9..5d0655f7 100644 --- a/qdefs.h +++ b/qdefs.h @@ -208,4 +208,22 @@ #define INT_LOSSLESS_FORMAT_CONVERT_U(x) ((uintmax_t)(x)) #endif +// simple safe library to handle integer overflows when doing buffer size calculations +// Usage: +// - calculate data size using INTOVERFLOW_??? macros +// - compare: calculated-size <= INTOVERFLOW_NORMALIZE(buffersize) +// Functionality: +// - all overflows (values > INTOVERFLOW_MAX) and errors are mapped to INTOVERFLOW_MAX +// - if any input of an operation is INTOVERFLOW_MAX, INTOVERFLOW_MAX will be returned +// - otherwise, regular arithmetics apply + +#define INTOVERFLOW_MAX 2147483647 + +#define INTOVERFLOW_ADD(a,b) (((a) < INTOVERFLOW_MAX && (b) < INTOVERFLOW_MAX && (a) < INTOVERFLOW_MAX - (b)) ? ((a) + (b)) : INTOVERFLOW_MAX) +#define INTOVERFLOW_SUB(a,b) (((a) < INTOVERFLOW_MAX && (b) < INTOVERFLOW_MAX && (b) <= (a)) ? ((a) - (b)) : INTOVERFLOW_MAX) +#define INTOVERFLOW_MUL(a,b) (((a) < INTOVERFLOW_MAX && (b) < INTOVERFLOW_MAX && (a) < INTOVERFLOW_MAX / (b)) ? ((a) * (b)) : INTOVERFLOW_MAX) +#define INTOVERFLOW_DIV(a,b) (((a) < INTOVERFLOW_MAX && (b) < INTOVERFLOW_MAX && (b) > 0) ? ((a) / (b)) : INTOVERFLOW_MAX) + +#define INTOVERFLOW_NORMALIZE(a) (((a) < INTOVERFLOW_MAX) ? (a) : (INTOVERFLOW_MAX - 1)) + #endif -- 2.39.2