From b757601f019605cc873527db675da188ab218fec Mon Sep 17 00:00:00 2001 From: Gliniak Date: Wed, 1 Jan 2025 18:43:52 +0100 Subject: [PATCH] [XAM] XamUserGetName: Fixed issue introduced in previous commit --- src/xenia/kernel/xam/xam_user.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/xenia/kernel/xam/xam_user.cc b/src/xenia/kernel/xam/xam_user.cc index aafddc0d6..7e6cc2202 100644 --- a/src/xenia/kernel/xam/xam_user.cc +++ b/src/xenia/kernel/xam/xam_user.cc @@ -145,23 +145,25 @@ dword_result_t XamUserGetName_entry(dword_t user_index, dword_t buffer, return X_ERROR_INVALID_PARAMETER; } - kernel_memory()->Zero(buffer, buffer_len); - if (!kernel_state()->xam_state()->IsUserSignedIn(user_index)) { + // Based on XAM only first byte is cleared in case of lack of user. + kernel_memory()->Zero(buffer, 1); return X_ERROR_NO_SUCH_USER; } const auto& user_profile = kernel_state()->xam_state()->GetUserProfile(user_index); - // Because name is always limited to 16 characters we can assume length will + // Because name is always limited to 15 characters we can assume length will // never exceed that limit. const auto& user_name = user_profile->name(); + // buffer_len includes null-terminator. user_name does not. + const uint32_t bytes_to_copy = std::min( + buffer_len.value(), static_cast(user_name.length()) + 1); + char* str_buffer = kernel_memory()->TranslateVirtual(buffer); - xe::string_util::copy_truncating( - str_buffer, user_name, - std::min(buffer_len.value(), static_cast(user_name.length()))); + xe::string_util::copy_truncating(str_buffer, user_name, bytes_to_copy); return X_ERROR_SUCCESS; } DECLARE_XAM_EXPORT1(XamUserGetName, kUserProfiles, kImplemented);