From 0a46a960de6efa35fcce922b75827aa1f60a3b8e Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Mon, 24 Jan 2022 21:58:19 +0100 Subject: [PATCH 1/4] Remove utf8_is_bom() --- src/openrct2/util/Util.cpp | 6 ------ src/openrct2/util/Util.h | 1 - 2 files changed, 7 deletions(-) diff --git a/src/openrct2/util/Util.cpp b/src/openrct2/util/Util.cpp index 5c16ef5676..1ce888248f 100644 --- a/src/openrct2/util/Util.cpp +++ b/src/openrct2/util/Util.cpp @@ -533,12 +533,6 @@ char* strcasestr(const char* haystack, const char* needle) } #endif -bool utf8_is_bom(const char* str) -{ - return str[0] == static_cast(static_cast(0xEF)) && str[1] == static_cast(static_cast(0xBB)) - && str[2] == static_cast(static_cast(0xBF)); -} - bool str_is_null_or_empty(const char* str) { return str == nullptr || str[0] == 0; diff --git a/src/openrct2/util/Util.h b/src/openrct2/util/Util.h index 95dfc282df..152e76c6be 100644 --- a/src/openrct2/util/Util.h +++ b/src/openrct2/util/Util.h @@ -49,7 +49,6 @@ char* safe_strcat_path(char* destination, const char* source, size_t size); char* strcasestr(const char* haystack, const char* needle); #endif -bool utf8_is_bom(const char* str); bool str_is_null_or_empty(const char* str); uint32_t util_rand(); From 93f3e94b3f7d1c02179752967f491fb8635ab91a Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Mon, 24 Jan 2022 22:00:14 +0100 Subject: [PATCH 2/4] Remove util_zlib_inflate() --- src/openrct2/util/Util.cpp | 50 -------------------------------------- src/openrct2/util/Util.h | 1 - 2 files changed, 51 deletions(-) diff --git a/src/openrct2/util/Util.cpp b/src/openrct2/util/Util.cpp index 1ce888248f..b0cf8c9ce3 100644 --- a/src/openrct2/util/Util.cpp +++ b/src/openrct2/util/Util.cpp @@ -547,56 +547,6 @@ uint32_t util_rand() constexpr size_t CHUNK = 128 * 1024; constexpr int32_t MAX_ZLIB_REALLOC = 4 * 1024 * 1024; -/** - * @brief Inflates zlib-compressed data - * @param data Data to be decompressed - * @param data_in_size Size of data to be decompressed - * @param data_out_size Pointer to a variable where output size will be written. If not 0, it will be used to set initial output - * buffer size. - * @return Returns a pointer to memory holding decompressed data or NULL on failure. - * @note It is caller's responsibility to free() the returned pointer once done with it. - */ -uint8_t* util_zlib_inflate(const uint8_t* data, size_t data_in_size, size_t* data_out_size) -{ - int32_t ret = Z_OK; - uLongf out_size = static_cast(*data_out_size); - if (out_size == 0) - { - // Try to guesstimate the size needed for output data by applying the - // same ratio it would take to compress data_in_size. - out_size = static_cast(data_in_size) * static_cast(data_in_size) - / compressBound(static_cast(data_in_size)); - out_size = std::min(static_cast(MAX_ZLIB_REALLOC), out_size); - } - uLongf buffer_size = out_size; - uint8_t* buffer = static_cast(malloc(buffer_size)); - do - { - if (ret == Z_BUF_ERROR) - { - buffer_size *= 2; - out_size = buffer_size; - buffer = static_cast(realloc(buffer, buffer_size)); - } - else if (ret == Z_STREAM_ERROR) - { - log_error("Your build is shipped with broken zlib. Please use the official build."); - free(buffer); - return nullptr; - } - else if (ret < 0) - { - log_error("Error uncompressing data."); - free(buffer); - return nullptr; - } - ret = uncompress(buffer, &out_size, data, static_cast(data_in_size)); - } while (ret != Z_OK); - buffer = static_cast(realloc(buffer, out_size)); - *data_out_size = out_size; - return buffer; -} - /** * @brief Deflates input using zlib * @param data Data to be compressed diff --git a/src/openrct2/util/Util.h b/src/openrct2/util/Util.h index 152e76c6be..bfa2c74d98 100644 --- a/src/openrct2/util/Util.h +++ b/src/openrct2/util/Util.h @@ -54,7 +54,6 @@ bool str_is_null_or_empty(const char* str); uint32_t util_rand(); std::optional> util_zlib_deflate(const uint8_t* data, size_t data_in_size); -uint8_t* util_zlib_inflate(const uint8_t* data, size_t data_in_size, size_t* data_out_size); bool util_gzip_compress(FILE* source, FILE* dest); std::vector Gzip(const void* data, const size_t dataLen); std::vector Ungzip(const void* data, const size_t dataLen); From 615c07977da222f1644f945a649b7b92187b9ed5 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Mon, 24 Jan 2022 22:00:37 +0100 Subject: [PATCH 3/4] Remove util_zlib_deflate() --- src/openrct2/util/Util.cpp | 31 ------------------------------- src/openrct2/util/Util.h | 1 - 2 files changed, 32 deletions(-) diff --git a/src/openrct2/util/Util.cpp b/src/openrct2/util/Util.cpp index b0cf8c9ce3..dd83aa50ba 100644 --- a/src/openrct2/util/Util.cpp +++ b/src/openrct2/util/Util.cpp @@ -547,37 +547,6 @@ uint32_t util_rand() constexpr size_t CHUNK = 128 * 1024; constexpr int32_t MAX_ZLIB_REALLOC = 4 * 1024 * 1024; -/** - * @brief Deflates input using zlib - * @param data Data to be compressed - * @param data_in_size Size of data to be compressed - * @return Returns an optional std::vector of bytes, which is equal to std::nullopt when deflate has failed - */ -std::optional> util_zlib_deflate(const uint8_t* data, size_t data_in_size) -{ - int32_t ret = Z_OK; - uLongf out_size = 0; - uLong buffer_size = compressBound(static_cast(data_in_size)); - std::vector buffer(buffer_size); - do - { - if (ret == Z_BUF_ERROR) - { - buffer_size *= 2; - out_size = buffer_size; - buffer.resize(buffer_size); - } - else if (ret == Z_STREAM_ERROR) - { - log_error("Your build is shipped with broken zlib. Please use the official build."); - return std::nullopt; - } - ret = compress(buffer.data(), &out_size, data, static_cast(data_in_size)); - } while (ret != Z_OK); - buffer.resize(out_size); - return buffer; -} - // Compress the source to gzip-compatible stream, write to dest. // Mainly used for compressing the crashdumps bool util_gzip_compress(FILE* source, FILE* dest) diff --git a/src/openrct2/util/Util.h b/src/openrct2/util/Util.h index bfa2c74d98..6fa3914a0a 100644 --- a/src/openrct2/util/Util.h +++ b/src/openrct2/util/Util.h @@ -53,7 +53,6 @@ bool str_is_null_or_empty(const char* str); uint32_t util_rand(); -std::optional> util_zlib_deflate(const uint8_t* data, size_t data_in_size); bool util_gzip_compress(FILE* source, FILE* dest); std::vector Gzip(const void* data, const size_t dataLen); std::vector Ungzip(const void* data, const size_t dataLen); From fd0788fc7fa565053ee12f5bdbe88b92006d2129 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Mon, 24 Jan 2022 22:00:51 +0100 Subject: [PATCH 4/4] Remove MAX_ZLIB_REALLOC --- src/openrct2/util/Util.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/openrct2/util/Util.cpp b/src/openrct2/util/Util.cpp index dd83aa50ba..35521adf21 100644 --- a/src/openrct2/util/Util.cpp +++ b/src/openrct2/util/Util.cpp @@ -545,7 +545,6 @@ uint32_t util_rand() } constexpr size_t CHUNK = 128 * 1024; -constexpr int32_t MAX_ZLIB_REALLOC = 4 * 1024 * 1024; // Compress the source to gzip-compatible stream, write to dest. // Mainly used for compressing the crashdumps