diff --git a/src/common/string_util.h b/src/common/string_util.h index 74c342e5bb..20cfec770d 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -84,6 +85,15 @@ std::string UTF16BufferToUTF8(const T& text) { return UTF16ToUTF8(buffer); } +/** + * Removes trailing null bytes from the string. + */ +[[nodiscard]] void TruncateString(std::string& str) { + while (str.size() && str.back() == '\0') { + str.pop_back(); + } +} + /** * Creates a std::string from a fixed-size NUL-terminated char buffer. If the buffer isn't * NUL-terminated then the string ends at max_len characters. diff --git a/src/core/hle/service/http/http_c.cpp b/src/core/hle/service/http/http_c.cpp index d0dbf410ba..4776cbc73f 100644 --- a/src/core/hle/service/http/http_c.cpp +++ b/src/core/hle/service/http/http_c.cpp @@ -10,6 +10,7 @@ #include #include "common/archives.h" #include "common/assert.h" +#include "common/string_util.h" #include "core/core.h" #include "core/file_sys/archive_ncch.h" #include "core/file_sys/file_backend.h" @@ -796,9 +797,7 @@ void HTTP_C::GetResponseHeader(Kernel::HLERequestContext& ctx) { std::string header_name_str( reinterpret_cast(async_data->header_name.data()), async_data->name_len); - while (header_name_str.size() && header_name_str.back() == '\0') { - header_name_str.pop_back(); - } + Common::TruncateString(header_name_str); Context& http_context = async_data->own->GetContext(async_data->context_handle);