From 1b5a7bb302d6506d7c38203cb62e8e296d997970 Mon Sep 17 00:00:00 2001 From: shchmue Date: Wed, 9 Dec 2020 19:04:59 -0700 Subject: [PATCH] nx_savedata: Fix storage length init on v5 save --- bdk/libs/nx_savedata/cached_storage.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bdk/libs/nx_savedata/cached_storage.c b/bdk/libs/nx_savedata/cached_storage.c index 52d38a3..78528a3 100644 --- a/bdk/libs/nx_savedata/cached_storage.c +++ b/bdk/libs/nx_savedata/cached_storage.c @@ -49,7 +49,7 @@ static ALWAYS_INLINE cache_block_t *cache_block_init(cached_storage_ctx_t *ctx) void save_cached_storage_init(cached_storage_ctx_t *ctx, substorage *base_storage, uint32_t block_size, uint32_t cache_size) { memcpy(&ctx->base_storage, base_storage, sizeof(substorage)); ctx->block_size = block_size; - substorage_get_size(base_storage, &ctx->length); + ctx->length = base_storage->length; ctx->cache_size = cache_size; list_init(&ctx->blocks); @@ -69,6 +69,8 @@ static void cache_block_finalize(cache_block_t **block) { } void save_cached_storage_finalize(cached_storage_ctx_t *ctx) { + if (!ctx->blocks.next) + return; LIST_FOREACH_SAFE(curr_block, &ctx->blocks) { cache_block_t *block = CONTAINER_OF(curr_block, cache_block_t, link) ; cache_block_finalize(&block); @@ -76,6 +78,8 @@ void save_cached_storage_finalize(cached_storage_ctx_t *ctx) { } static bool try_get_block_by_value(cached_storage_ctx_t *ctx, uint64_t index, cache_block_t **out_block) { + if (!ctx->blocks.next) + return false; LIST_FOREACH_ENTRY(cache_block_t, block, &ctx->blocks, link) { if (block->index == index) { *out_block = block;