Add and use Common::TruncateString

This commit is contained in:
PabloMK7 2023-10-04 22:53:42 +02:00
parent 3ccbe657b1
commit 937ffb267c
2 changed files with 12 additions and 3 deletions

View File

@ -6,6 +6,7 @@
#include <algorithm> #include <algorithm>
#include <cstddef> #include <cstddef>
#include <span>
#include <string> #include <string>
#include <string_view> #include <string_view>
#include <vector> #include <vector>
@ -84,6 +85,15 @@ std::string UTF16BufferToUTF8(const T& text) {
return UTF16ToUTF8(buffer); 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 * 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. * NUL-terminated then the string ends at max_len characters.

View File

@ -10,6 +10,7 @@
#include <cryptopp/modes.h> #include <cryptopp/modes.h>
#include "common/archives.h" #include "common/archives.h"
#include "common/assert.h" #include "common/assert.h"
#include "common/string_util.h"
#include "core/core.h" #include "core/core.h"
#include "core/file_sys/archive_ncch.h" #include "core/file_sys/archive_ncch.h"
#include "core/file_sys/file_backend.h" #include "core/file_sys/file_backend.h"
@ -796,9 +797,7 @@ void HTTP_C::GetResponseHeader(Kernel::HLERequestContext& ctx) {
std::string header_name_str( std::string header_name_str(
reinterpret_cast<const char*>(async_data->header_name.data()), reinterpret_cast<const char*>(async_data->header_name.data()),
async_data->name_len); async_data->name_len);
while (header_name_str.size() && header_name_str.back() == '\0') { Common::TruncateString(header_name_str);
header_name_str.pop_back();
}
Context& http_context = async_data->own->GetContext(async_data->context_handle); Context& http_context = async_data->own->GetContext(async_data->context_handle);