From 823c94ca9c6abf8aa6f55160a02e4b5dec644553 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 24 Feb 2024 13:31:04 +0100 Subject: [PATCH] StorageAPI: support for loading/storing empty strings/binaries --- Dockerfile | 2 +- source/utils/storage/StorageUtils.cpp | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 19572a1..683e15e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM ghcr.io/wiiu-env/devkitppc:20230621 COPY --from=ghcr.io/wiiu-env/wiiumodulesystem:0.3.2-dev-20231203-2e5832b /artifacts $DEVKITPRO -COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:0.8.0-dev-20240223-46f4cf6 /artifacts $DEVKITPRO +COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:0.8.0-dev-20240224-2262844 /artifacts $DEVKITPRO COPY --from=ghcr.io/wiiu-env/libfunctionpatcher:20230621 /artifacts $DEVKITPRO COPY --from=ghcr.io/wiiu-env/libmappedmemory:20230621 /artifacts $DEVKITPRO COPY --from=ghcr.io/wiiu-env/libwupsbackend:20230621 /artifacts $DEVKITPRO diff --git a/source/utils/storage/StorageUtils.cpp b/source/utils/storage/StorageUtils.cpp index d5acc5e..c6121d6 100644 --- a/source/utils/storage/StorageUtils.cpp +++ b/source/utils/storage/StorageUtils.cpp @@ -378,6 +378,12 @@ namespace StorageUtils { std::vector tmp; auto res = GetAndFixBinaryItem(root, parent, key, tmp); if (res == WUPS_STORAGE_ERROR_SUCCESS) { + if (tmp.empty()) { // we need this to support getting empty std::vector + return WUPS_STORAGE_ERROR_SUCCESS; + } + if (data == nullptr) { + return WUPS_STORAGE_ERROR_INVALID_ARGS; + } if (maxSize < tmp.size()) { return WUPS_STORAGE_ERROR_BUFFER_TOO_SMALL; } @@ -581,19 +587,19 @@ namespace StorageUtils { return StorageUtils::Helper::StoreItemGeneric(root, parent, key, *(uint64_t *) data); } case WUPS_STORAGE_ITEM_STRING: { - if (data == nullptr || length == 0) { + if (data == nullptr) { return WUPS_STORAGE_ERROR_INVALID_ARGS; } - std::string tmp((const char *) data, length); + std::string tmp = length > 0 ? std::string((const char *) data, length) : std::string(); DEBUG_FUNCTION_LINE_VERBOSE("Store %s as string: %s", key, tmp.c_str()); return StorageUtils::Helper::StoreItemGeneric(root, parent, key, tmp); } case WUPS_STORAGE_ITEM_BINARY: { - if (data == nullptr || length == 0) { + if (data == nullptr && length > 0) { return WUPS_STORAGE_ERROR_INVALID_ARGS; } - std::vector tmp((uint8_t *) data, ((uint8_t *) data) + length); + std::vector tmp = (data != nullptr && length > 0) ? std::vector((uint8_t *) data, ((uint8_t *) data) + length) : std::vector(); DEBUG_FUNCTION_LINE_VERBOSE("Store %s as binary: size %d", key, tmp.size()); return StorageUtils::Helper::StoreItemGeneric>(root, parent, key, tmp); @@ -637,9 +643,6 @@ namespace StorageUtils { return StorageUtils::Helper::GetStringItem(root, parent, key, data, maxSize, outSize); } case WUPS_STORAGE_ITEM_BINARY: { - if (!data || maxSize == 0) { - return WUPS_STORAGE_ERROR_INVALID_ARGS; - } return StorageUtils::Helper::GetBinaryItem(root, parent, key, data, maxSize, outSize); } case WUPS_STORAGE_ITEM_BOOL: {