From e9eaedfb64808f39d9204271ffc21c2ae6bb6cff Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Thu, 21 Jul 2022 17:25:38 +0200 Subject: [PATCH] Reduce strlens --- src/cheat.c | 17 ++++++----------- src/drivers/libretro/libretro.c | 5 +++-- src/ines.c | 15 ++++++++------- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/cheat.c b/src/cheat.c index e7b73b2..e8243c0 100644 --- a/src/cheat.c +++ b/src/cheat.c @@ -202,8 +202,8 @@ void FCEU_ResetCheats(void) int FCEUI_AddCheat(const char *name, uint32 addr, uint8 val, int compare, int type) { char *t; - - if (!(t = (char*)malloc(strlen(name) + 1))) { + if (!(t = (char*)malloc(strlen(name) + 1))) + { CheatMemErr(); return(0); } @@ -318,16 +318,11 @@ static int GGtobin(char c) { /* Returns 1 on success, 0 on failure. Sets *a,*v,*c. */ int FCEUI_DecodeGG(const char *str, uint16 *a, uint8 *v, int *c) { - uint16 A; - uint8 V, C; uint8 t; - int s; - - A = 0x8000; - V = 0; - C = 0; - - s = strlen(str); + uint16 A = 0x8000; + uint8 V = 0; + uint8 C = 0; + int s = strlen(str); if (s != 6 && s != 8) return(0); t = GGtobin(*str++); diff --git a/src/drivers/libretro/libretro.c b/src/drivers/libretro/libretro.c index b828104..3f3cae0 100644 --- a/src/drivers/libretro/libretro.c +++ b/src/drivers/libretro/libretro.c @@ -2763,7 +2763,8 @@ void retro_cheat_set(unsigned index, bool enabled, const char *code) while (codepart) { - if ((strlen(codepart) == 7) && (codepart[4]==':')) + size_t codepart_len = strlen(codepart); + if ((codepart_len == 7) && (codepart[4]==':')) { /* raw code in xxxx:xx format */ log_cb.log(RETRO_LOG_DEBUG, "Cheat code added: '%s' (Raw)\n", codepart); @@ -2776,7 +2777,7 @@ void retro_cheat_set(unsigned index, bool enabled, const char *code) if (a < 0x0100) type = 0; FCEUI_AddCheat(name, a, v, c, type); } - else if ((strlen(codepart) == 10) && (codepart[4] == '?') && (codepart[7] == ':')) + else if ((codepart_len == 10) && (codepart[4] == '?') && (codepart[7] == ':')) { /* raw code in xxxx?xx:xx */ log_cb.log(RETRO_LOG_DEBUG, "Cheat code added: '%s' (Raw)\n", codepart); diff --git a/src/ines.c b/src/ines.c index a025647..6e34333 100644 --- a/src/ines.c +++ b/src/ines.c @@ -364,11 +364,12 @@ static void CheckHInfo(void) if (tofix) { char gigastr[768]; strcpy(gigastr, " The iNES header contains incorrect information. For now, the information will be corrected in RAM. "); + size_t gigastr_len = strlen(gigastr); if (tofix & 1) - sprintf(gigastr + strlen(gigastr), "Current mapper # is %d. The mapper number should be set to %d. ", current_mapper, iNESCart.mapper); + sprintf(gigastr + gigastr_len, "Current mapper # is %d. The mapper number should be set to %d. ", current_mapper, iNESCart.mapper); if (tofix & 2) { uint8 *mstr[3] = { (uint8_t*)"Horizontal", (uint8_t*)"Vertical", (uint8_t*)"Four-screen" }; - sprintf(gigastr + strlen(gigastr), "Current mirroring is %s. Mirroring should be set to \"%s\". ", mstr[cur_mirr & 3], mstr[iNESCart.mirror & 3]); + sprintf(gigastr + gigastr_len, "Current mirroring is %s. Mirroring should be set to \"%s\". ", mstr[cur_mirr & 3], mstr[iNESCart.mirror & 3]); } if (tofix & 4) strcat(gigastr, "The battery-backed bit should be set. "); @@ -376,19 +377,19 @@ static void CheckHInfo(void) strcat(gigastr, "This game should not have any CHR ROM. "); if (tofix & 16) { uint8 *rstr[4] = { (uint8*)"NTSC", (uint8*)"PAL", (uint8*)"Multi", (uint8*)"Dendy" }; - sprintf(gigastr + strlen(gigastr), "This game should run with \"%s\" timings.", rstr[iNESCart.region]); + sprintf(gigastr + gigastr_len, "This game should run with \"%s\" timings.", rstr[iNESCart.region]); } if (tofix & 32) { unsigned PRGRAM = iNESCart.PRGRamSize + iNESCart.PRGRamSaveSize; unsigned CHRRAM = iNESCart.CHRRamSize + iNESCart.CHRRamSaveSize; if (PRGRAM || CHRRAM) { if (iNESCart.PRGRamSaveSize == 0) - sprintf(gigastr + strlen(gigastr), "workram: %d KB, ", PRGRAM / 1024); + sprintf(gigastr + gigastr_len, "workram: %d KB, ", PRGRAM / 1024); else if (iNESCart.PRGRamSize == 0) - sprintf(gigastr + strlen(gigastr), "saveram: %d KB, ", PRGRAM / 1024); + sprintf(gigastr + gigastr_len, "saveram: %d KB, ", PRGRAM / 1024); else - sprintf(gigastr + strlen(gigastr), "workram: %d KB (%dKB battery-backed), ", PRGRAM / 1024, iNESCart.PRGRamSaveSize / 1024); - sprintf(gigastr + strlen(gigastr), "chrram: %d KB.", (CHRRAM + iNESCart.CHRRamSaveSize) / 1024); + sprintf(gigastr + gigastr_len, "workram: %d KB (%dKB battery-backed), ", PRGRAM / 1024, iNESCart.PRGRamSaveSize / 1024); + sprintf(gigastr + gigastr_len, "chrram: %d KB.", (CHRRAM + iNESCart.CHRRamSaveSize) / 1024); } } strcat(gigastr, "\n");