From eac5310f5e2ed457fa8bb0e766b044dcbc8f088c Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 3 Jul 2024 10:12:04 +0200 Subject: [PATCH] some crap from asan --- src/doomdef.h | 4 ++++ src/hardware/hw_main.c | 4 ---- src/k_kart.c | 5 ++--- src/lua_consolelib.c | 6 +++++- src/r_draw8.c | 6 +++++- src/r_segs.c | 3 ++- src/sdl/mixer_sound.c | 1 + 7 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index c7d9bbc4a..1c9a055d3 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -524,6 +524,10 @@ INT32 I_GetKey(void); #define max(x, y) (((x) > (y)) ? (x) : (y)) #endif +#ifndef CLAMP +#define CLAMP(x, min_val, max_val) ((x) < (min_val) ? (min_val) : ((x) > (max_val) ? (max_val) : (x))) +#endif + #ifndef M_PIl #define M_PIl 3.1415926535897932384626433832795029L #endif diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index e7ff935d6..9ec698437 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -55,8 +55,6 @@ #define SOFTLIGHT(llevel) HWR_ShouldUsePaletteRendering() ? ((llevel) >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : (llevel) -#define CLAMP(x, min_val, max_val) ((x) < (min_val) ? (min_val) : ((x) > (max_val) ? (max_val) : (x))) - // ========================================================================== // the hardware driver object // ========================================================================== @@ -6125,6 +6123,4 @@ void HWR_DrawScreenFinalTexture(INT32 width, INT32 height) HWD.pfnDrawScreenFinalTexture(HWD_SCREENTEXTURE_GENERIC2, width, height); } -#undef CLAMP - #endif // HWRENDER diff --git a/src/k_kart.c b/src/k_kart.c index e4db32b5f..9ca6b90dc 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -9556,11 +9556,10 @@ static void K_drawDriftGauge(void) if (driftcharge >= driftval*4) // rainbow sparks { + int index = CLAMP((leveltime % 18) + 1, 0, 18 - 1); cmap = R_GetTranslationColormap(TC_RAINBOW, 1 + leveltime % (MAXSKINCOLORS-1),GTC_CACHE); for (i = 0; i < 4; i++) - { - V_DrawFill(barx, bary+dup*1+dup*i, BAR_WIDTH, dup, (driftrainbow[(leveltime % 18) + 1] + i*2) | V_NOSCALESTART|drifttrans); - } + V_DrawFill(barx, bary+dup*1+dup*i, BAR_WIDTH, dup, (driftrainbow[index] + i*2) | V_NOSCALESTART|drifttrans); } else // none/blue/red { diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c index ad1df2b22..3e70ce008 100644 --- a/src/lua_consolelib.c +++ b/src/lua_consolelib.c @@ -453,9 +453,11 @@ static int lib_cvRegisterVar(lua_State *L) if (!(((cvar->flags & CV_HIDEN)) || (cvar->flags & CV_NOSHOWHELP)) && (cvar->PossibleValue || !(cvar->value == 0 && stricmp(cvar->string, "0")))) { + char *temp = NULL; + if (!category) { - char *temp = strdup(wadfiles[numwadfiles - 1]->filename); + temp = strdup(wadfiles[numwadfiles - 1]->filename); nameonly(temp); category = temp; @@ -465,6 +467,8 @@ static int lib_cvRegisterVar(lua_State *L) M_SlotCvarIntoModMenu(cvar, category, menu_name); else M_SlotCvarIntoModMenu(cvar, category, cvar->name); + + free (temp); } // return cvar userdata diff --git a/src/r_draw8.c b/src/r_draw8.c index 4580ff3b9..f309b8ec7 100644 --- a/src/r_draw8.c +++ b/src/r_draw8.c @@ -40,13 +40,17 @@ void R_DrawColumn_8(void) #endif // Framebuffer destination address. + // Use ylookup LUT to avoid multiply with ScreenWidth. + // Use columnofs LUT for subwindows? + dest = &topleft[dc_yl*vid.width + dc_x]; count++; // Determine scaling, which is the only mapping to be done. fracstep = dc_iscale; - frac = dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep); + frac = (dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep)); + // Inner loop that does the actual texture mapping, e.g. a DDA-like scaling. // This is as fast as it gets. diff --git a/src/r_segs.c b/src/r_segs.c index dd66b7b5c..f8998da14 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -1374,7 +1374,8 @@ static void R_RenderSegLoop (void) //SoM: Calculate offsets for Thick fake floors. // calculate texture offset angle = (rw_centerangle + xtoviewangle[rw_x])>>ANGLETOFINESHIFT; - texturecolumn = rw_offset-FixedMul(FINETANGENT(angle),rw_distance); + // Mask 4095 to guarantee this index is within bounds + texturecolumn = rw_offset-FixedMul(FINETANGENT(angle & 4095),rw_distance); if (oldtexturecolumn != -1) { rw_bottomtexturemid += FixedMul(rw_bottomtextureslide, oldtexturecolumn-texturecolumn); diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index aef996772..806c77e47 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -1115,6 +1115,7 @@ boolean I_LoadSong(char *data, size_t len) if (!gme_open_data(inflatedData, inflatedLen, &gme, SAMPLERATE)) { Z_Free(inflatedData); // GME supposedly makes a copy for itself, so we don't need this lying around + inflateEnd(&stream); return true; } }