diff options
Diffstat (limited to 'src/cart.c')
| -rw-r--r-- | src/cart.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -60,6 +60,8 @@ struct pw_carts *pw_carts_list(char const *dir) { goto error; } + // Set an SDL error while returning an empty carts list. This allows a + // caller to disambiguate between empty and missing directories. SDL_SetError("missing carts directory"); carts->count = 0; return carts; @@ -73,6 +75,10 @@ struct pw_carts *pw_carts_list(char const *dir) { } size_t count = (size_t)icount; + if (count > SIZE_MAX / sizeof(struct pw_cart_entry)) { + goto error; + } + carts = SDL_malloc(sizeof(struct pw_carts) + count * sizeof(struct pw_cart_entry)); if (!carts) { @@ -349,8 +355,8 @@ static int cmp_cart_name(void const *a, void const *b) { struct pw_multicart *pw_multicart_init(struct pw_cart_entry *entry, struct pw_cart *cart) { if (!entry) { - SDL_InvalidParamError("cart"); - return false; + SDL_InvalidParamError("entry"); + return NULL; } struct pw_multicart *multi = SDL_malloc(sizeof(*multi)); @@ -368,6 +374,8 @@ struct pw_multicart *pw_multicart_init(struct pw_cart_entry *entry, for (size_t i = 0; i < entry->nmulti; ++i) { SDL_memcpy(&dst->multi[i], &entry->multi[i], sizeof(struct pw_cart_file)); } + } else { + dst->multi = NULL; } SDL_memcpy(&dst->file, &entry->file, sizeof(struct pw_cart_file)); dst->nmulti = entry->nmulti; |
