From 4b4b2d5cbc7ea3db104ebe8f6a16c5c4c093a37b Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 3 Jul 2024 17:37:16 +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 | 3 +-- src/r_segs.c | 3 ++- src/sdl/mixer_sound.c | 1 + 7 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index c032ec77b..31734af84 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -529,6 +529,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 6c98c8c97..d5c789368 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -54,8 +54,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 // ========================================================================== @@ -6271,6 +6269,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 2857eddf3..7419387c4 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -9350,11 +9350,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 6b5d177db..b67311d76 100644 --- a/src/r_draw8.c +++ b/src/r_draw8.c @@ -43,16 +43,15 @@ void R_DrawColumn_8(void) // Use ylookup LUT to avoid multiply with ScreenWidth. // Use columnofs LUT for subwindows? - //dest = ylookup[dc_yl] + columnofs[dc_x]; 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 + (dc_yl - centery)*fracstep; frac = (dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep))*(!dc_hires); + // 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 b70e06ff6..7cb7e7397 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; } }