From 94c08e56ee2df43621b676b05848b39640f2a285 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Tue, 9 Jul 2024 17:08:11 +0100 Subject: [PATCH] Codechange: Replace GetSavegameFormat's compression output pointer with reference. This parameter must always be present and is not checked, so a reference is safer. --- src/saveload/saveload.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index 34589f8dfd..6282c4c52e 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -2679,10 +2679,10 @@ static const SaveLoadFormat _saveload_formats[] = { * Return the savegameformat of the game. Whether it was created with ZLIB compression * uncompressed, or another type * @param full_name Name of the savegame format. If empty it picks the first available one - * @param compression_level Output for telling what compression level we want. + * @param[out] compression_level Output for telling what compression level we want. * @return Reference to SaveLoadFormat struct giving all characteristics of this type of savegame */ -static const SaveLoadFormat &GetSavegameFormat(const std::string &full_name, uint8_t *compression_level) +static const SaveLoadFormat &GetSavegameFormat(const std::string &full_name, uint8_t &compression_level) { /* Find default savegame format, the highest one with which files can be written. */ auto it = std::find_if(std::rbegin(_saveload_formats), std::rend(_saveload_formats), [](const auto &slf) { return slf.init_write != nullptr; }); @@ -2698,7 +2698,7 @@ static const SaveLoadFormat &GetSavegameFormat(const std::string &full_name, uin for (const auto &slf : _saveload_formats) { if (slf.init_write != nullptr && name.compare(slf.name) == 0) { - *compression_level = slf.default_compression; + compression_level = slf.default_compression; if (has_comp_level) { const std::string complevel(full_name, separator + 1); @@ -2709,7 +2709,7 @@ static const SaveLoadFormat &GetSavegameFormat(const std::string &full_name, uin SetDParamStr(0, complevel); ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_SAVEGAME_COMPRESSION_LEVEL, WL_CRITICAL); } else { - *compression_level = level; + compression_level = level; } } return slf; @@ -2720,7 +2720,7 @@ static const SaveLoadFormat &GetSavegameFormat(const std::string &full_name, uin SetDParamStr(1, def.name); ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_SAVEGAME_COMPRESSION_ALGORITHM, WL_CRITICAL); } - *compression_level = def.default_compression; + compression_level = def.default_compression; return def; } @@ -2806,7 +2806,7 @@ static SaveOrLoadResult SaveFileToDisk(bool threaded) { try { uint8_t compression; - const SaveLoadFormat &fmt = GetSavegameFormat(_savegame_format, &compression); + const SaveLoadFormat &fmt = GetSavegameFormat(_savegame_format, compression); /* We have written our stuff to memory, now write it to file! */ uint32_t hdr[2] = { fmt.tag, TO_BE32(SAVEGAME_VERSION << 16) };