diff --git a/autosave.c b/autosave.c index 1abb23c927..1870788e61 100644 --- a/autosave.c +++ b/autosave.c @@ -16,13 +16,13 @@ #include #include -#include #include +#include + #include #include "general.h" -#include "autosave.h" struct autosave { diff --git a/dynamic.c b/dynamic.c index 31932be98e..a8e3372686 100644 --- a/dynamic.c +++ b/dynamic.c @@ -17,14 +17,6 @@ #include #include -#ifdef NEED_DYNAMIC -#ifdef _WIN32 -#include -#else -#include -#endif -#endif - #include #include #include @@ -35,13 +27,11 @@ #include "config.h" #endif -#include "dynamic.h" #include "performance.h" #include "libretro_private.h" #include "cores/internal_cores.h" #include "retroarch.h" -#include "runloop.h" #include "configuration.h" #include "general.h" #include "msg_hash.h" diff --git a/libretro-db/libretrodb.c b/libretro-db/libretrodb.c index bd498d0726..c36bbf2e2f 100644 --- a/libretro-db/libretrodb.c +++ b/libretro-db/libretrodb.c @@ -101,26 +101,27 @@ int libretrodb_create(FILE *fp, libretrodb_value_provider value_provider, while ((rv = value_provider(ctx, &item)) == 0) { if ((rv = validate_document(&item)) < 0) - goto clean; + goto error; if ((rv = rmsgpack_dom_write(fp, &item)) < 0) - goto clean; + goto error; item_count++; } if (rv < 0) - goto clean; + goto error; if ((rv = rmsgpack_dom_write(fp, &sentinal)) < 0) - goto clean; + goto error; header.metadata_offset = httobe64(flseek(fp, 0, SEEK_CUR)); md.count = item_count; libretrodb_write_metadata(fp, &md); flseek(fp, root, SEEK_SET); fwrite(&header, 1, sizeof(header), fp); -clean: + +error: rmsgpack_dom_value_free(&item); return rv; } @@ -405,7 +406,6 @@ static uint64_t libretrodb_tell(libretrodb_t *db) int libretrodb_create_index(libretrodb_t *db, const char *name, const char *field_name) { - int rv; struct node_iter_ctx nictx; struct rmsgpack_dom_value key; libretrodb_index_t idx; @@ -422,10 +422,7 @@ int libretrodb_create_index(libretrodb_t *db, bintree_new(&tree, node_compare, &field_size); if (libretrodb_cursor_open(db, &cur, NULL) != 0) - { - rv = -1; - goto clean; - } + goto error; key.type = RDT_STRING; key.val.string.len = strlen(field_name); @@ -437,49 +434,41 @@ int libretrodb_create_index(libretrodb_t *db, { if (item.type != RDT_MAP) { - rv = -EINVAL; printf("Only map keys are supported\n"); - goto clean; + goto error; } field = rmsgpack_dom_value_map_value(&item, &key); if (!field) { - rv = -EINVAL; printf("field not found in item\n"); - goto clean; + goto error; } if (field->type != RDT_BINARY) { - rv = -EINVAL; printf("field is not binary\n"); - goto clean; + goto error; } if (field->val.binary.len == 0) { - rv = -EINVAL; printf("field is empty\n"); - goto clean; + goto error; } if (field_size == 0) field_size = field->val.binary.len; else if (field->val.binary.len != field_size) { - rv = -EINVAL; printf("field is not of correct size\n"); - goto clean; + goto error; } buff = malloc(field_size + sizeof(uint64_t)); if (!buff) - { - rv = -ENOMEM; - goto clean; - } + goto error; memcpy(buff, field->val.binary.buff, field_size); @@ -492,18 +481,15 @@ int libretrodb_create_index(libretrodb_t *db, printf("Value is not unique: "); rmsgpack_dom_value_print(field); printf("\n"); - rv = -EINVAL; - goto clean; + goto error; } buff = NULL; rmsgpack_dom_value_free(&item); item_loc = libretrodb_tell(db); } - (void)rv; - (void)idx_header_offset; - idx_header_offset = flseek(db->fp, 0, SEEK_END); + (void)idx_header_offset; strncpy(idx.name, name, 50); idx.name[49] = '\0'; @@ -515,7 +501,8 @@ int libretrodb_create_index(libretrodb_t *db, nictx.idx = &idx; bintree_iterate(&tree, node_iter, &nictx); bintree_free(&tree); -clean: + +error: rmsgpack_dom_value_free(&item); if (buff) free(buff); diff --git a/libretro-db/rmsgpack.c b/libretro-db/rmsgpack.c index fd65d9627f..ee4dd15220 100644 --- a/libretro-db/rmsgpack.c +++ b/libretro-db/rmsgpack.c @@ -57,8 +57,7 @@ static const uint8_t MPF_NIL = 0xc0; static INLINE ssize_t fpwrite(FILE *fp, const void *buf, size_t count) { - size_t num_written = fwrite(buf, 1, count, fp); - return num_written != count ? -1 : (ssize_t)count; + return (fwrite(buf, 1, count, fp) != count) ? -1 : (ssize_t)count; } static INLINE ssize_t fpread(FILE *fp, void *buf, size_t count) @@ -367,7 +366,6 @@ static int read_uint(FILE *fp, uint64_t *out, size_t size) static int read_int(FILE *fp, int64_t *out, size_t size) { - uint8_t tmp8 = 0; uint16_t tmp16; uint32_t tmp32; uint64_t tmp64; @@ -375,8 +373,6 @@ static int read_int(FILE *fp, int64_t *out, size_t size) if (fpread(fp, &tmp64, size) == -1) return -errno; - (void)tmp8; - switch (size) { case 1: @@ -395,6 +391,7 @@ static int read_int(FILE *fp, int64_t *out, size_t size) *out = *((int64_t *)(&tmp64)); break; } + return 0; } @@ -403,18 +400,21 @@ static int read_buff(FILE *fp, size_t size, char **pbuff, uint64_t *len) uint64_t tmp_len = 0; if (read_uint(fp, &tmp_len, size) == -1) - return -errno; + goto error; *pbuff = (char *)calloc((size_t)tmp_len + 1, sizeof(char)); if (fpread(fp, *pbuff, (size_t)tmp_len) == -1) - { - free(*pbuff); - return -errno; - } + goto error; *len = tmp_len; return 0; + +error: + if (*pbuff) + free(*pbuff); + return -errno; + } static int read_map(FILE *fp, uint32_t len, diff --git a/libretro-db/rmsgpack_dom.c b/libretro-db/rmsgpack_dom.c index b5fadcf888..41e41b5bc1 100644 --- a/libretro-db/rmsgpack_dom.c +++ b/libretro-db/rmsgpack_dom.c @@ -354,8 +354,7 @@ void rmsgpack_dom_value_print(struct rmsgpack_dom_value *obj) break; case RDT_STRING: printf("\"%s\"", obj->val.string.buff); - break; - case RDT_BINARY: + break; case RDT_BINARY: printf("\""); for (i = 0; i < obj->val.binary.len; i++) printf("%02X", (unsigned char) obj->val.binary.buff[i]); @@ -462,14 +461,11 @@ int rmsgpack_dom_read_into(FILE *fp, ...) uint64_t min_len; char *buff_value = NULL; const char *key_name = NULL; - int value_type = 0; va_start(ap, fp); rv = rmsgpack_dom_read(fp, &map); - (void)value_type; - if (rv < 0) { va_end(ap); @@ -477,20 +473,14 @@ int rmsgpack_dom_read_into(FILE *fp, ...) } if (map.type != RDT_MAP) - { - rv = -EINVAL; - goto clean; - } + goto error; while (1) { key_name = va_arg(ap, const char *); if (!key_name) - { - rv = 0; - goto clean; - } + goto error; key.type = RDT_STRING; key.val.string.len = strlen(key_name); @@ -531,12 +521,11 @@ int rmsgpack_dom_read_into(FILE *fp, ...) memcpy(buff_value, value->val.string.buff, (size_t)min_len); break; default: - rv = -1; - goto clean; + goto error; } } -clean: +error: va_end(ap); rmsgpack_dom_value_free(&map); return 0; diff --git a/movie.c b/movie.c index db67ce5e72..aa11092274 100644 --- a/movie.c +++ b/movie.c @@ -14,13 +14,13 @@ * If not, see . */ -#include "movie.h" -#include #include #include #include + +#include + #include "general.h" -#include "dynamic.h" struct bsv_movie {