task_save_handler - rewrite code - put string on stack instead

of heap, avoid using strlcat
This commit is contained in:
libretroadmin 2024-06-16 18:44:08 +02:00
parent c722653c97
commit c05ec27334
1 changed files with 14 additions and 17 deletions

View File

@ -54,12 +54,12 @@
read/write is a possible suspend to JS code */ read/write is a possible suspend to JS code */
#define SAVE_STATE_CHUNK 4096 * 4096 #define SAVE_STATE_CHUNK 4096 * 4096
#else #else
/* A low common denominator write chunk size. On a slow /* A low common denominator write chunk size. On a slow
(speed class 6) SD card, we can write 6MB/s. That gives us (speed class 6) SD card, we can write 6MB/s. That gives us
roughly 100KB/frame. roughly 100KB/frame.
This means we can write savestates with one syscall for cores This means we can write savestates with one syscall for cores
with less than 100KB of state. Class 10 is the standard now with less than 100KB of state. Class 10 is the standard now
even for lousy cards and supports 10MB/s, so you may prefer even for lousy cards and supports 10MB/s, so you may prefer
to put this to 170KB. This all assumes that task_save's loop to put this to 170KB. This all assumes that task_save's loop
is iterated once per frame at 60 FPS; if it's updated less is iterated once per frame at 60 FPS; if it's updated less
frequently this number could be doubled or quadrupled depending frequently this number could be doubled or quadrupled depending
@ -537,8 +537,7 @@ static void task_save_handler(retro_task_t *task)
if (task_get_cancelled(task) || written != remaining) if (task_get_cancelled(task) || written != remaining)
{ {
size_t err_size = 8192 * sizeof(char); char msg[PATH_MAX_LENGTH];
char *err = (char*)malloc(err_size);
if (state->flags & SAVE_TASK_FLAG_UNDO_SAVE) if (state->flags & SAVE_TASK_FLAG_UNDO_SAVE)
{ {
@ -546,21 +545,19 @@ static void task_save_handler(retro_task_t *task)
MSG_FAILED_TO_UNDO_SAVE_STATE); MSG_FAILED_TO_UNDO_SAVE_STATE);
RARCH_ERR("[State]: %s \"%s\".\n", failed_undo_str, RARCH_ERR("[State]: %s \"%s\".\n", failed_undo_str,
undo_save_buf.path); undo_save_buf.path);
err[0] = '\0'; snprintf(msg, sizeof(msg), "%s \"RAM\".", failed_undo_str);
snprintf(err, err_size - 1, "%s \"RAM\".", failed_undo_str);
} }
else else
{ {
size_t _len = strlcpy(err, size_t _len = strlcpy(msg,
msg_hash_to_str(MSG_FAILED_TO_SAVE_STATE_TO), msg_hash_to_str(MSG_FAILED_TO_SAVE_STATE_TO),
err_size - 1); sizeof(msg));
err[ _len] = ' '; msg[ _len] = ' ';
err[++_len] = '\0'; msg[++_len] = '\0';
strlcat(err, state->path, err_size - 1); strlcpy(msg + _len, state->path, sizeof(msg) - _len);
} }
task_set_error(task, strdup(err)); task_set_error(task, strdup(msg));
free(err);
task_save_handler_finished(task, state); task_save_handler_finished(task, state);
return; return;
} }