[Base] Fixed issue with unnecessary null terminator after reading u16string
This commit is contained in:
@@ -435,6 +435,7 @@ inline std::u16string read_u16string_and_swap(const char16_t* string_ptr) {
|
||||
std::u16string output_str = {};
|
||||
output_str.resize(input_str.size() + 1);
|
||||
copy_and_swap_truncating(output_str.data(), input_str, input_str.size() + 1);
|
||||
output_str.pop_back(); // Remove nullptr added by copy_and_swap.
|
||||
return output_str;
|
||||
}
|
||||
|
||||
|
||||
@@ -754,17 +754,17 @@ dword_result_t XamParseGamerTileKey_entry(pointer_t<X_USER_DATA> key_ptr,
|
||||
return X_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
std::string tile_key = xe::to_utf8(string_util::read_u16string_and_swap(
|
||||
const std::string tile_key = xe::to_utf8(string_util::read_u16string_and_swap(
|
||||
kernel_memory()->TranslateVirtual<const char16_t*>(
|
||||
key_ptr->data.unicode.ptr)));
|
||||
|
||||
// Default key size is 24 bytes, but we need to include null terminator
|
||||
if (tile_key.empty() || tile_key.size() != 25) {
|
||||
if (tile_key.empty() || tile_key.size() != 24) {
|
||||
return X_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
const bool is_valid_hex_string =
|
||||
std::all_of(tile_key.begin(), --tile_key.end(),
|
||||
std::all_of(tile_key.cbegin(), tile_key.cend(),
|
||||
[](unsigned char c) { return std::isxdigit(c); });
|
||||
|
||||
if (!is_valid_hex_string) {
|
||||
|
||||
@@ -40,8 +40,8 @@ const char16_t* GpdInfoTitle::GetAchievementDescriptionPtr(const uint32_t id) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return reinterpret_cast<const char16_t*>(title_ptr +
|
||||
GetAchievementTitle(id).length());
|
||||
return reinterpret_cast<const char16_t*>(
|
||||
title_ptr + GetAchievementTitle(id).length() + 1);
|
||||
}
|
||||
|
||||
const char16_t* GpdInfoTitle::GetAchievementUnachievedDescriptionPtr(
|
||||
@@ -52,7 +52,7 @@ const char16_t* GpdInfoTitle::GetAchievementUnachievedDescriptionPtr(
|
||||
}
|
||||
|
||||
return reinterpret_cast<const char16_t*>(
|
||||
title_ptr + GetAchievementDescription(id).length());
|
||||
title_ptr + GetAchievementDescription(id).length() + 1);
|
||||
}
|
||||
|
||||
std::u16string GpdInfoTitle::GetAchievementTitle(const uint32_t id) {
|
||||
|
||||
Reference in New Issue
Block a user