From bd8ebabfee75f1f8f05512808dcb690495e6b82a Mon Sep 17 00:00:00 2001 From: Eidolon Date: Thu, 14 Dec 2023 21:00:42 -0600 Subject: [PATCH 1/8] Enforce C++17 standard compliance --- src/CMakeLists.txt | 5 +++++ src/hwr2/twodee_renderer.cpp | 6 +++--- src/hwr2/twodee_renderer.hpp | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6f1a3bf1b..d285752c0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -200,6 +200,11 @@ if("${CMAKE_COMPILER_IS_GNUCC}" AND "${CMAKE_SYSTEM_NAME}" MATCHES "Windows") endif() target_compile_features(SRB2SDL2 PRIVATE c_std_11 cxx_std_17) +set_target_properties(SRB2SDL2 PROPERTIES + CXX_STANDARD 17 + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS OFF +) set(SRB2_ASM_SOURCES vid_copy.s) diff --git a/src/hwr2/twodee_renderer.cpp b/src/hwr2/twodee_renderer.cpp index ac9ed0dbd..95f64bd11 100644 --- a/src/hwr2/twodee_renderer.cpp +++ b/src/hwr2/twodee_renderer.cpp @@ -397,7 +397,7 @@ void TwodeeRenderer::flush(Rhi& rhi, Handle ctx, Twodee& twodee else { srb2::NotNull atlas = patch_atlas_cache_->find_patch(cmd.patch); - typeof(merged_cmd.texture) atlas_index_texture = atlas->texture(); + std::optional atlas_index_texture = atlas->texture(); new_cmd_needed = new_cmd_needed || (merged_cmd.texture != atlas_index_texture); } @@ -411,7 +411,7 @@ void TwodeeRenderer::flush(Rhi& rhi, Handle ctx, Twodee& twodee } else { - typeof(merged_cmd.texture) flat_tex = MergedTwodeeCommandFlatTexture {cmd.flat_lump}; + std::optional flat_tex = MergedTwodeeCommandFlatTexture {cmd.flat_lump}; new_cmd_needed |= (merged_cmd.texture != flat_tex); } @@ -444,7 +444,7 @@ void TwodeeRenderer::flush(Rhi& rhi, Handle ctx, Twodee& twodee if (cmd.flat_lump != LUMPERROR) { flat_manager_->find_or_create_indexed(rhi, ctx, cmd.flat_lump); - typeof(the_new_one.texture) t = MergedTwodeeCommandFlatTexture {cmd.flat_lump}; + std::optional t = MergedTwodeeCommandFlatTexture {cmd.flat_lump}; the_new_one.texture = t; } else diff --git a/src/hwr2/twodee_renderer.hpp b/src/hwr2/twodee_renderer.hpp index fe674c009..68096daf4 100644 --- a/src/hwr2/twodee_renderer.hpp +++ b/src/hwr2/twodee_renderer.hpp @@ -63,9 +63,10 @@ struct MergedTwodeeCommandFlatTexture struct MergedTwodeeCommand { + using Texture = std::variant, MergedTwodeeCommandFlatTexture>; TwodeePipelineKey pipeline_key = {}; rhi::Handle binding_set = {}; - std::optional, MergedTwodeeCommandFlatTexture>> texture; + std::optional texture; const uint8_t* colormap; uint32_t index_offset = 0; uint32_t elements = 0; From 88ee385ee3b9488d198301c25dbd4852a2bc58e9 Mon Sep 17 00:00:00 2001 From: Eidolon Date: Thu, 14 Dec 2023 21:53:18 -0600 Subject: [PATCH 2/8] Enforce C11 standard compliance, -Werror=vla --- src/CMakeLists.txt | 4 ++++ src/d_netcmd.c | 9 ++++++++- src/deh_soc.c | 12 ++++++++---- src/k_hud.c | 30 ++++++++++++++++-------------- src/m_cond.c | 36 ++++++++++++++++++------------------ 5 files changed, 54 insertions(+), 37 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d285752c0..d21f1f137 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -201,6 +201,9 @@ endif() target_compile_features(SRB2SDL2 PRIVATE c_std_11 cxx_std_17) set_target_properties(SRB2SDL2 PROPERTIES + C_STANDARD 11 + C_STANDARD_REQUIRED ON + C_STANDARD_EXTENSIONS OFF CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF @@ -468,6 +471,7 @@ target_compile_options(SRB2SDL2 PRIVATE $<$,4.6.0>: -Wno-suggest-attribute=noreturn -Wno-error=suggest-attribute=noreturn + -Werror=vla > $<$,5.4.0>: diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 95f938e68..600e46969 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -4314,12 +4314,13 @@ static void Command_Addfile(void) size_t argc = COM_Argc(); // amount of arguments total size_t curarg; // current argument index - const char *addedfiles[argc]; // list of filenames already processed + const char **addedfiles = Z_Calloc(sizeof(const char*) * argc, PU_STATIC, NULL); size_t numfilesadded = 0; // the amount of filenames processed if (argc < 2) { CONS_Printf(M_GetText("addfile [filename2...] [...]: Load add-ons\n")); + Z_Free(addedfiles); return; } @@ -4357,7 +4358,10 @@ static void Command_Addfile(void) // Disallow non-printing characters and semicolons. for (i = 0; fn[i] != '\0'; i++) if (!isprint(fn[i]) || fn[i] == ';') + { + Z_Free(addedfiles); return; + } musiconly = W_VerifyNMUSlumps(fn, false); @@ -4397,6 +4401,7 @@ static void Command_Addfile(void) if (numwadfiles >= MAX_WADFILES) { CONS_Alert(CONS_ERROR, M_GetText("Too many files loaded to add %s\n"), fn); + Z_Free(addedfiles); return; } @@ -4447,6 +4452,8 @@ static void Command_Addfile(void) else SendNetXCmd(XD_ADDFILE, buf, buf_p - buf); } + + Z_Free(addedfiles); #endif/*TESTERS*/ } diff --git a/src/deh_soc.c b/src/deh_soc.c index 974532c24..274e06477 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -578,7 +578,7 @@ void readskincolor(MYFILE *f, INT32 num) if (fastcmp(word, "NAME")) { size_t namesize = sizeof(skincolors[num].name); - char truncword[namesize]; + char *truncword = Z_Malloc(sizeof(char) * namesize, PU_STATIC, NULL); UINT16 dupecheck; deh_strlcpy(truncword, word2, namesize, va("Skincolor %d: name", num)); // truncate here to check for dupes @@ -586,7 +586,7 @@ void readskincolor(MYFILE *f, INT32 num) if (truncword[0] != '\0' && (!stricmp(truncword, skincolors[SKINCOLOR_NONE].name) || (dupecheck && dupecheck != num))) { size_t lastchar = strlen(truncword); - char oldword[lastchar+1]; + char *oldword = Z_Calloc(sizeof(char) * (lastchar + 1), PU_STATIC, NULL); char dupenum = '1'; strlcpy(oldword, truncword, lastchar+1); @@ -611,9 +611,11 @@ void readskincolor(MYFILE *f, INT32 num) } deh_warning("Skincolor %d: name %s is a duplicate of another skincolor's name - renamed to %s", num, oldword, truncword); + Z_Free(oldword); } strlcpy(skincolors[num].name, truncword, namesize); // already truncated + Z_Free(truncword); } else if (fastcmp(word, "RAMP")) { @@ -2506,7 +2508,7 @@ static void conditiongetparam(char **params, UINT8 paramid, char **spos) static void readcondition(UINT16 set, UINT32 id, char *word2) { INT32 i; - const UINT8 MAXCONDITIONPARAMS = 5; +#define MAXCONDITIONPARAMS 5 char *params[MAXCONDITIONPARAMS]; // condition, requirement, extra info, extra info, stringvar char *spos = NULL; char *stringvar = NULL; @@ -2974,7 +2976,7 @@ static void readcondition(UINT16 set, UINT32 id, char *word2) { PARAMCHECK(1); ty = UCRP_PODIUMCUP; - + re = -1; if (!fastcmp(params[1], "ANY")) { @@ -3250,6 +3252,8 @@ static void readcondition(UINT16 set, UINT32 id, char *word2) setcondition: M_AddRawCondition(set, (UINT8)id, ty, re, x1, x2, stringvar); + +#undef MAXCONDITIONPARAMS } void readconditionset(MYFILE *f, UINT16 setnum) diff --git a/src/k_hud.c b/src/k_hud.c index b450c3e81..6da496e03 100644 --- a/src/k_hud.c +++ b/src/k_hud.c @@ -792,7 +792,7 @@ void K_LoadKartHUDGraphics(void) { buffer[7] = '0'+i; HU_UpdatePatch(&kp_superflickytarget[0][i], "%s", buffer); - } + } sprintf(buffer, "H4PFLKAx"); for (i = 0; i < 4; i++) @@ -2860,17 +2860,17 @@ static void K_drawKartAccessibilityIcons(boolean gametypeinfoshown, INT32 fx) { INT32 fy = LAPS_Y-14; INT32 splitflags = V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_SPLITSCREEN; - + boolean mirror = false; - + fx += LAPS_X; - + if (r_splitscreen < 2) // adjust to speedometer height { if (gametypeinfoshown) { fy -= 11; - + if ((gametyperules & (GTR_BUMPERS|GTR_CIRCUIT)) == GTR_BUMPERS) fy -= 4; } @@ -2890,21 +2890,21 @@ static void K_drawKartAccessibilityIcons(boolean gametypeinfoshown, INT32 fx) mirror = true; } } - + // Kickstart Accel if (stplyr->pflags & PF_KICKSTARTACCEL) { if (mirror) fx -= 10; - + SINT8 col = 0, wid, fil, ofs; UINT8 i = 7; ofs = (stplyr->kickstartaccel == ACCEL_KICKSTART) ? 1 : 0; fil = i-(stplyr->kickstartaccel*i)/ACCEL_KICKSTART; - + V_DrawFill(fx+4, fy+ofs-1, 2, 1, 31|V_SLIDEIN|splitflags); V_DrawFill(fx, (fy+ofs-1)+8, 10, 1, 31|V_SLIDEIN|splitflags); - + while (i--) { wid = (i/2)+1; @@ -2924,21 +2924,21 @@ static void K_drawKartAccessibilityIcons(boolean gametypeinfoshown, INT32 fx) col = 3; V_DrawFill(fx+5-wid, fy+ofs+i, (wid*2), 1, col|V_SLIDEIN|splitflags); } - + if (mirror) fx--; else fx += 10 + 1; } - + // Auto Roulette if (stplyr->pflags & PF_AUTOROULETTE) { if (mirror) fx -= 12; - + V_DrawScaledPatch(fx, fy-1, V_SLIDEIN|splitflags, kp_autoroulette); - + if (mirror) fx--; else @@ -3743,7 +3743,7 @@ static void K_drawKartNameTags(void) if (sortlen > 0) { - UINT8 sortedplayers[sortlen]; + UINT8 *sortedplayers = Z_Malloc(sizeof(UINT8) * sortlen, PU_STATIC, NULL); for (i = 0; i < sortlen; i++) { @@ -3822,6 +3822,8 @@ static void K_drawKartNameTags(void) } } } + + Z_Free(sortedplayers); } V_ClearClipRect(); diff --git a/src/m_cond.c b/src/m_cond.c index 3518fa12d..b619f08ce 100644 --- a/src/m_cond.c +++ b/src/m_cond.c @@ -150,13 +150,13 @@ void M_PopulateChallengeGrid(void) UINT16 numspots = (gamedata->challengegridwidth - (challengegridloops ? 0 : majorcompact)) * ((CHALLENGEGRIDHEIGHT-1) / majorcompact); // 0 is row, 1 is column - INT16 quickcheck[numspots][2]; + INT16 *quickcheck = Z_Calloc(sizeof(INT16) * 2 * numspots, PU_STATIC, NULL); // Prepare the easy-grab spots. for (i = 0; i < numspots; i++) { - quickcheck[i][0] = i%(CHALLENGEGRIDHEIGHT-1); - quickcheck[i][1] = majorcompact * i/(CHALLENGEGRIDHEIGHT-1); + quickcheck[i * 2 + 0] = i%(CHALLENGEGRIDHEIGHT-1); + quickcheck[i * 2 + 1] = majorcompact * i/(CHALLENGEGRIDHEIGHT-1); } // Place in random valid locations. @@ -164,8 +164,8 @@ void M_PopulateChallengeGrid(void) { INT16 row, col; j = M_RandomKey(numspots); - row = quickcheck[j][0]; - col = quickcheck[j][1]; + row = quickcheck[j * 2 + 0]; + col = quickcheck[j * 2 + 1]; // We always take from selection[1][] in order, but the PLACEMENT is still random. nummajorunlocks--; @@ -183,7 +183,7 @@ void M_PopulateChallengeGrid(void) i += CHALLENGEGRIDHEIGHT; } gamedata->challengegrid[i] = gamedata->challengegrid[i+1] = selection[1][nummajorunlocks]; - + if (nummajorunlocks == 0) { break; @@ -192,17 +192,17 @@ void M_PopulateChallengeGrid(void) for (i = 0; i < numspots; i++) { quickcheckagain: - if (abs((quickcheck[i][0]) - (row)) <= 1 // Row distance - && (abs((quickcheck[i][1]) - (col)) <= 1 // Column distance - || (quickcheck[i][1] == 0 && col == gamedata->challengegridwidth-1) // Wraparounds l->r - || (quickcheck[i][1] == gamedata->challengegridwidth-1 && col == 0))) // Wraparounds r->l + if (abs((quickcheck[i * 2 + 0]) - (row)) <= 1 // Row distance + && (abs((quickcheck[i * 2 + 1]) - (col)) <= 1 // Column distance + || (quickcheck[i * 2 + 1] == 0 && col == gamedata->challengegridwidth-1) // Wraparounds l->r + || (quickcheck[i * 2 + 1] == gamedata->challengegridwidth-1 && col == 0))) // Wraparounds r->l { numspots--; // Remove from possible indicies if (i == numspots) break; // Shuffle remaining so we can keep on using M_RandomKey - quickcheck[i][0] = quickcheck[numspots][0]; - quickcheck[i][1] = quickcheck[numspots][1]; + quickcheck[i * 2 + 0] = quickcheck[numspots * 2 + 0]; + quickcheck[i * 2 + 1] = quickcheck[numspots * 2 + 1]; // Woah there - we've gotta check the one that just got put in our place. goto quickcheckagain; } @@ -972,7 +972,7 @@ cacheprisoneggpickup: // Okay, this should be available. // Bring to the front! swap = gamedata->prisoneggpickups[gamedata->gettableprisoneggpickups]; - gamedata->prisoneggpickups[gamedata->gettableprisoneggpickups] = + gamedata->prisoneggpickups[gamedata->gettableprisoneggpickups] = gamedata->prisoneggpickups[i]; gamedata->prisoneggpickups[i] = swap; @@ -990,7 +990,7 @@ cacheprisoneggpickup: // Push this all the way to the back, and lop it off! swap = gamedata->prisoneggpickups[gamedata->numprisoneggpickups]; - gamedata->prisoneggpickups[gamedata->numprisoneggpickups] = + gamedata->prisoneggpickups[gamedata->numprisoneggpickups] = gamedata->prisoneggpickups[i]; gamedata->prisoneggpickups[i] = swap; @@ -1250,7 +1250,7 @@ void M_UpdateConditionSetsPending(void) } } - + } } @@ -1404,7 +1404,7 @@ boolean M_CheckCondition(condition_t *cn, player_t *player) UINT8 difficulty = cn->extrainfo2; if (difficulty > KARTGP_MASTER) difficulty = KARTGP_MASTER; - + cupheader_t *cup; for (cup = kartcupheaders; cup; cup = cup->next) { @@ -1725,7 +1725,7 @@ boolean M_CheckCondition(condition_t *cn, player_t *player) && player->position != 0 && player->position <= cn->requirement); case UCRP_FINISHPLACEEXACT: - return (player->exiting + return (player->exiting && !(player->pflags & PF_NOCONTEST) && M_NotFreePlay() && player->position == cn->requirement); @@ -3314,7 +3314,7 @@ boolean M_MapLocked(UINT16 mapnum) if (mapnum == 0 || mapnum > nummapheaders) return false; - + if (!mapheaderinfo[mapnum-1]) return false; From 1db9898c42c3b9b423412360980c7bc85dad0724 Mon Sep 17 00:00:00 2001 From: Eidolon Date: Thu, 14 Dec 2023 22:45:53 -0600 Subject: [PATCH 3/8] Fix apple clang compilation issues --- src/m_avrecorder.cpp | 8 ++------ src/math/fixed.hpp | 2 +- src/p_sweep.cpp | 6 +++--- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/m_avrecorder.cpp b/src/m_avrecorder.cpp index bff239070..ca5cd73a4 100644 --- a/src/m_avrecorder.cpp +++ b/src/m_avrecorder.cpp @@ -91,14 +91,10 @@ static AVRecorder::Config configure() if (sound_started && cv_movie_sound.value) { - cfg.audio = { - .sample_rate = 44100, - }; + cfg.audio = { 44100 }; } - cfg.video = { - .frame_rate = cv_movie_fps.value, - }; + cfg.video = { cv_movie_fps.value }; AVRecorder::Config::Video& v = *cfg.video; diff --git a/src/math/fixed.hpp b/src/math/fixed.hpp index 0e5cae4c1..c39a0aba6 100644 --- a/src/math/fixed.hpp +++ b/src/math/fixed.hpp @@ -66,7 +66,7 @@ struct Fixed Fixed operator-() const { return -val_; } #define X(op) \ - template \ + template >> \ Fixed operator op(const T& b) const { return val_ op b; } \ Fixed operator op(const Fixed& b) const \ { \ diff --git a/src/p_sweep.cpp b/src/p_sweep.cpp index d4e9d22ef..c59aaa3b5 100644 --- a/src/p_sweep.cpp +++ b/src/p_sweep.cpp @@ -21,7 +21,7 @@ Result SlopeAABBvsLine::vs_slope(const line_segment& l) const LineEquation ql{l}; unit ls = copysign(kUnit, ql.m()); - auto hit = [&](const vec2& k, unit xr, unit x, const vec2& n) -> Contact + auto hit = [&, &a = a, &b = b](const vec2& k, unit xr, unit x, const vec2& n) -> Contact { std::optional k2; @@ -92,7 +92,7 @@ Result SlopeAABBvsLine::vs_slope(const line_segment& l) const // xrs.x = x radius // xrs.y = x sign - auto bind = [&](const vec2& k, const vec2& xrs, unit ns) -> std::optional + auto bind = [&, &a = a, &b = b](const vec2& k, const vec2& xrs, unit ns) -> std::optional { if (k.x < a.x) { @@ -206,7 +206,7 @@ Result VerticalAABBvsLine::vs_slope(const line_segment& l) const auto [a, b] = l.by_x(); // left, right LineEquation ql{l}; - auto hit = [&](const vec2& k, unit xr, unit y, const vec2& n) -> Contact + auto hit = [&, &a = a, &b = b](const vec2& k, unit xr, unit y, const vec2& n) -> Contact { std::optional k2; From 22809e928bc4b1a4785801d6a9acebb884629e61 Mon Sep 17 00:00:00 2001 From: Eidolon Date: Thu, 14 Dec 2023 23:25:34 -0600 Subject: [PATCH 4/8] Fix MSVC C++ warnings --- src/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d21f1f137..c139d5d64 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -428,6 +428,7 @@ target_compile_options(SRB2SDL2 PRIVATE -Wno-trigraphs -W # Was controlled by RELAXWARNINGS -pedantic + -Wpedantic -Wfloat-equal -Wundef -Wpointer-arith @@ -527,7 +528,7 @@ target_compile_options(SRB2SDL2 PRIVATE > # C++, MSVC - $<$,$>: + $<$,$>: /Wv:19.20.27004.0 > From 0ca9fca86900f1663606a4e9b2cb49256599108c Mon Sep 17 00:00:00 2001 From: Eidolon Date: Thu, 14 Dec 2023 23:27:44 -0600 Subject: [PATCH 5/8] Pass _CRT_SECURE_NO_WARNINGS on MSVC --- src/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c139d5d64..7c4d89203 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -417,6 +417,11 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") target_compile_options(SRB2SDL2 PRIVATE -mno-ms-bitfields) endif() +# Yes we know we use insecure CRT functions... +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + target_compile_definitions(SRB2SDL2 PRIVATE -D_CRT_SECURE_NO_WARNINGS) +endif() + # Compiler warnings configuration target_compile_options(SRB2SDL2 PRIVATE # Using generator expressions to handle per-language compile options From 8bc610bf408d555676e4e05d7644b21adce2e71e Mon Sep 17 00:00:00 2001 From: toaster Date: Sat, 16 Dec 2023 21:51:36 +0000 Subject: [PATCH 6/8] K_drawKartNameTags: Move to static sized array We don't need to dedicate time to allocation - we know the upper bound to this array size, and it's not very much at all. --- src/k_hud.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/k_hud.c b/src/k_hud.c index 6da496e03..3f49b0d02 100644 --- a/src/k_hud.c +++ b/src/k_hud.c @@ -3743,7 +3743,7 @@ static void K_drawKartNameTags(void) if (sortlen > 0) { - UINT8 *sortedplayers = Z_Malloc(sizeof(UINT8) * sortlen, PU_STATIC, NULL); + UINT8 sortedplayers[MAXPLAYERS]; for (i = 0; i < sortlen; i++) { @@ -3822,8 +3822,6 @@ static void K_drawKartNameTags(void) } } } - - Z_Free(sortedplayers); } V_ClearClipRect(); From 933faf1d9de2b96d855560d3b5d6c74eb8d8dd7f Mon Sep 17 00:00:00 2001 From: toaster Date: Sat, 16 Dec 2023 21:55:42 +0000 Subject: [PATCH 7/8] Command_Addfile: Only allocate after argc is sanity checked --- src/d_netcmd.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 600e46969..386182a4a 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -4314,16 +4314,15 @@ static void Command_Addfile(void) size_t argc = COM_Argc(); // amount of arguments total size_t curarg; // current argument index - const char **addedfiles = Z_Calloc(sizeof(const char*) * argc, PU_STATIC, NULL); - size_t numfilesadded = 0; // the amount of filenames processed - if (argc < 2) { CONS_Printf(M_GetText("addfile [filename2...] [...]: Load add-ons\n")); - Z_Free(addedfiles); return; } + const char **addedfiles = Z_Calloc(sizeof(const char*) * argc, PU_STATIC, NULL); + size_t numfilesadded = 0; // the amount of filenames processed + // start at one to skip command name for (curarg = 1; curarg < argc; curarg++) { From 436ba88220f3993b96bfc4b15ae7a1adad32a2b5 Mon Sep 17 00:00:00 2001 From: toaster Date: Sat, 16 Dec 2023 22:00:58 +0000 Subject: [PATCH 8/8] readskincolor: sizeof is compile-time evaluated, literally why do we need to run the allocator for this --- src/deh_soc.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/deh_soc.c b/src/deh_soc.c index 274e06477..20e46153f 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -577,8 +577,8 @@ void readskincolor(MYFILE *f, INT32 num) if (fastcmp(word, "NAME")) { - size_t namesize = sizeof(skincolors[num].name); - char *truncword = Z_Malloc(sizeof(char) * namesize, PU_STATIC, NULL); + char truncword[sizeof(skincolors[num].name)]; + size_t namesize = sizeof(truncword); UINT16 dupecheck; deh_strlcpy(truncword, word2, namesize, va("Skincolor %d: name", num)); // truncate here to check for dupes @@ -586,7 +586,7 @@ void readskincolor(MYFILE *f, INT32 num) if (truncword[0] != '\0' && (!stricmp(truncword, skincolors[SKINCOLOR_NONE].name) || (dupecheck && dupecheck != num))) { size_t lastchar = strlen(truncword); - char *oldword = Z_Calloc(sizeof(char) * (lastchar + 1), PU_STATIC, NULL); + char oldword[sizeof(truncword)]; char dupenum = '1'; strlcpy(oldword, truncword, lastchar+1); @@ -611,11 +611,9 @@ void readskincolor(MYFILE *f, INT32 num) } deh_warning("Skincolor %d: name %s is a duplicate of another skincolor's name - renamed to %s", num, oldword, truncword); - Z_Free(oldword); } strlcpy(skincolors[num].name, truncword, namesize); // already truncated - Z_Free(truncword); } else if (fastcmp(word, "RAMP")) {