Refix the network command READ_CORE_RAM to not crash on read supperior to 78
This commit is contained in:
parent
eeaa34f024
commit
587424e0ef
|
@ -277,66 +277,43 @@ bool command_set_shader(const char *arg)
|
||||||
#define SMY_CMD_STR "READ_CORE_RAM"
|
#define SMY_CMD_STR "READ_CORE_RAM"
|
||||||
static bool command_read_ram(const char *arg)
|
static bool command_read_ram(const char *arg)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_NEW_CHEEVOS)
|
|
||||||
unsigned i;
|
unsigned i;
|
||||||
char *reply = NULL;
|
char *reply = NULL;
|
||||||
const uint8_t * data = NULL;
|
const uint8_t *data = NULL;
|
||||||
char *reply_at = NULL;
|
char *reply_at = NULL;
|
||||||
unsigned int nbytes = 0;
|
unsigned int nbytes = 0;
|
||||||
unsigned int alloc_size = 0;
|
unsigned int alloc_size = 0;
|
||||||
unsigned int addr = -1;
|
unsigned int addr = -1;
|
||||||
|
|
||||||
if (sscanf(arg, "%x %d", &addr, &nbytes) != 2)
|
if (sscanf(arg, "%x %d", &addr, &nbytes) != 2)
|
||||||
return true;
|
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);
|
||||||
|
|
||||||
|
#if defined(HAVE_NEW_CHEEVOS)
|
||||||
data = cheevos_patch_address(addr, cheevos_get_console());
|
data = cheevos_patch_address(addr, cheevos_get_console());
|
||||||
|
|
||||||
if (data)
|
|
||||||
{
|
|
||||||
for (i = 0; i < nbytes; i++)
|
|
||||||
sprintf(reply_at+3*i, " %.2X", data[i]);
|
|
||||||
reply_at[3*nbytes] = '\n';
|
|
||||||
command_reply(reply, reply_at+3*nbytes+1 - reply);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
strlcpy(reply_at, " -1\n", sizeof(reply)-strlen(reply));
|
|
||||||
command_reply(reply, reply_at+strlen(" -1\n") - reply);
|
|
||||||
}
|
|
||||||
free(reply);
|
|
||||||
#else
|
#else
|
||||||
cheevos_var_t var;
|
cheevos_var_t var;
|
||||||
unsigned i;
|
var.value = addr;
|
||||||
char reply[256] = {0};
|
|
||||||
const uint8_t * data = NULL;
|
|
||||||
char *reply_at = NULL;
|
|
||||||
|
|
||||||
reply[0] = '\0';
|
|
||||||
|
|
||||||
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);
|
|
||||||
cheevos_var_patch_addr(&var, cheevos_get_console());
|
cheevos_var_patch_addr(&var, cheevos_get_console());
|
||||||
data = cheevos_var_get_memory(&var);
|
data = cheevos_var_get_memory(&var);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (data)
|
if (data)
|
||||||
{
|
{
|
||||||
unsigned nbytes = strtol(reply_at, NULL, 10);
|
|
||||||
|
|
||||||
for (i = 0; i < nbytes; i++)
|
for (i = 0; i < nbytes; i++)
|
||||||
sprintf(reply_at+3*i, " %.2X", data[i]);
|
sprintf(reply_at + 3 * i, " %.2X", data[i]);
|
||||||
reply_at[3*nbytes] = '\n';
|
reply_at[3 * nbytes] = '\n';
|
||||||
command_reply(reply, reply_at+3*nbytes+1 - reply);
|
command_reply(reply, reply_at + 3 * nbytes + 1 - reply);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strlcpy(reply_at, " -1\n", sizeof(reply)-strlen(reply));
|
strlcpy(reply_at, " -1\n", sizeof(reply) - strlen(reply));
|
||||||
command_reply(reply, reply_at+strlen(" -1\n") - reply);
|
command_reply(reply, reply_at + strlen(" -1\n") - reply);
|
||||||
}
|
}
|
||||||
#endif
|
free(reply);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#undef SMY_CMD_STR
|
#undef SMY_CMD_STR
|
||||||
|
|
Loading…
Reference in New Issue