diff --git a/command.c b/command.c index 62cc725441..f4cca97af7 100644 --- a/command.c +++ b/command.c @@ -246,28 +246,31 @@ bool command_set_shader(const char *arg) } #if defined(HAVE_COMMAND) && defined(HAVE_CHEEVOS) +#define SMY_CMD_STR "READ_CORE_RAM" static bool command_read_ram(const char *arg) { cheevos_var_t var; unsigned i; - char reply[256] = {0}; + char *reply = NULL; const uint8_t * data = NULL; char *reply_at = NULL; + unsigned int nbytes = 0; + unsigned int alloc_size = 0; + int addr = -1; - reply[0] = '\0'; + if (sscanf(arg, "%x %d", &addr, &nbytes) != 2) + return true; + alloc_size = 40 + nbytes * 3; //We alloc more than needed, saving 20 bytes is not really relevant + reply = (char*) malloc(alloc_size); + reply[0] = '\0'; + reply_at = reply + sprintf(reply, SMY_CMD_STR " %x", addr); - strlcpy(reply, "READ_CORE_RAM ", sizeof(reply)); - reply_at = reply + strlen("READ_CORE_RAM "); - strlcpy(reply_at, arg, sizeof(reply)-strlen(reply)); - - var.value = strtoul(reply_at, (char**)&reply_at, 16); + var.value = addr; cheevos_var_patch_addr(&var, cheevos_get_console()); data = cheevos_var_get_memory(&var); if (data) { - unsigned nbytes = strtol(reply_at, NULL, 10); - for (i=0;i