diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index c8e47943cf..1624f9f2d8 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -277,8 +277,10 @@ bool path_is_compressed_file(const char* path) * out_path = "/foo/bar/baz/boo.asm" * E.g.: in_path = "/foo/bar/baz/boo.c", replace = "" => * out_path = "/foo/bar/baz/boo" + * + * @return Length of the string copied into @out */ -void fill_pathname(char *out_path, const char *in_path, +size_t fill_pathname(char *out_path, const char *in_path, const char *replace, size_t size) { char tmp_path[PATH_MAX_LENGTH]; @@ -288,7 +290,7 @@ void fill_pathname(char *out_path, const char *in_path, *tok = '\0'; strlcpy(out_path, tmp_path, size); - strlcat(out_path, replace, size); + return strlcat(out_path, replace, size); } diff --git a/libretro-common/include/file/file_path.h b/libretro-common/include/file/file_path.h index 33db4a57e1..eefed8d310 100644 --- a/libretro-common/include/file/file_path.h +++ b/libretro-common/include/file/file_path.h @@ -264,8 +264,10 @@ bool path_is_absolute(const char *path); * - calls strlcpy 2x * - calls strrchr * - calls strlcat + * + * @return Length of the string copied into @out */ -void fill_pathname(char *out_path, const char *in_path, +size_t fill_pathname(char *out_path, const char *in_path, const char *replace, size_t size); /** diff --git a/playlist.c b/playlist.c index c3525586f8..8734107331 100644 --- a/playlist.c +++ b/playlist.c @@ -1499,8 +1499,7 @@ void playlist_write_runtime_file(playlist_t *playlist) return; } - writer = rjsonwriter_open_stream(file); - if (!writer) + if (!(writer = rjsonwriter_open_stream(file))) { RARCH_ERR("Failed to create JSON writer\n"); goto end; @@ -1722,13 +1721,11 @@ void playlist_write_file(playlist_t *playlist) RARCH_ERR("Failed to create JSON writer\n"); goto end; } + /* When compressing playlists, human readability + * is not a factor - can skip all indentation + * and new line characters */ if (compressed) - { - /* When compressing playlists, human readability - * is not a factor - can skip all indentation - * and new line characters */ rjsonwriter_set_options(writer, RJSONWRITER_OPTION_SKIP_WHITESPACE); - } rjsonwriter_raw(writer, "{", 1); rjsonwriter_raw(writer, "\n", 1); @@ -2142,13 +2139,9 @@ static bool JSONEndArrayHandler(void *context) pCtx->array_depth--; if (pCtx->in_items && pCtx->array_depth == 0 && pCtx->object_depth <= 1) - { pCtx->in_items = false; - } else if (pCtx->in_subsystem_roms && pCtx->array_depth <= 1 && pCtx->object_depth <= 2) - { pCtx->in_subsystem_roms = false; - } return true; } @@ -2498,9 +2491,8 @@ static bool playlist_read_file(playlist_t *playlist) * non-whitespace ASCII character */ do { - test_char = intfstream_getc(file); - - if (test_char == EOF) /* read error or end of file */ + /* Read error or EOF (end of file) */ + if ((test_char = intfstream_getc(file)) == EOF) goto end; }while (!isgraph(test_char) || test_char > 0x7F); @@ -2975,9 +2967,7 @@ static int playlist_qsort_func(const struct playlist_entry *a, * have no other option...) */ if (string_is_empty(a_str)) { - a_fallback_label = (char*)calloc(PATH_MAX_LENGTH, sizeof(char)); - - if (!a_fallback_label) + if (!(a_fallback_label = (char*)calloc(PATH_MAX_LENGTH, sizeof(char)))) goto end; if (!string_is_empty(a->path)) @@ -3000,9 +2990,7 @@ static int playlist_qsort_func(const struct playlist_entry *a, if (string_is_empty(b_str)) { - b_fallback_label = (char*)calloc(PATH_MAX_LENGTH, sizeof(char)); - - if (!b_fallback_label) + if (!(b_fallback_label = (char*)calloc(PATH_MAX_LENGTH, sizeof(char)))) goto end; if (!string_is_empty(b->path)) diff --git a/retroarch.c b/retroarch.c index 6e38c39778..ee5f9001c0 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1450,7 +1450,6 @@ void dir_check_defaults(const char *custom_ini_path) if (string_is_empty(dir_path)) continue; - new_path[0] = '\0'; fill_pathname_expand_special(new_path, dir_path, sizeof(new_path));