From 59a0eb99afce1337cea26923ac6de678c5531098 Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 10 Sep 2023 22:06:56 +0300 Subject: [PATCH] libretro: allow unlimited cheat length notaz/pcsx_rearmed#306 --- frontend/libretro.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/frontend/libretro.c b/frontend/libretro.c index b64c3cae..4fe86376 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -995,12 +995,13 @@ void retro_cheat_reset(void) void retro_cheat_set(unsigned index, bool enabled, const char *code) { - char buf[256]; - int ret; + int ret = -1; + char *buf; - // cheat funcs are destructive, need a copy.. - strncpy(buf, code, sizeof(buf)); - buf[sizeof(buf) - 1] = 0; + // cheat funcs are destructive, need a copy... + buf = strdup(code); + if (buf == NULL) + goto finish; //Prepare buffered cheat for PCSX's AddCheat fucntion. int cursor = 0; @@ -1026,10 +1027,12 @@ void retro_cheat_set(unsigned index, bool enabled, const char *code) else ret = AddCheat("", buf); +finish: if (ret != 0) SysPrintf("Failed to set cheat %#u\n", index); else if (index < NumCheats) Cheats[index].Enabled = enabled; + free(buf); } // just in case, maybe a win-rt port in the future? -- 2.39.5