Fix strcpy_trunc type validation

This commit is contained in:
Elad 2026-01-30 10:22:36 +02:00
parent 3b6afc1d9a
commit cc1b4c8fd1
2 changed files with 18 additions and 18 deletions

View file

@ -13,13 +13,13 @@ std::string wchar_to_utf8(std::wstring_view src);
std::string utf16_to_utf8(std::u16string_view src);
std::u16string utf8_to_utf16(std::string_view src);
// Copy null-terminated string from a std::string or a char array to a char array with truncation
template <typename D, typename T>
// Copy null-terminated string from a std::basic_string or a char array to a char array with truncation
template <typename D, typename T> requires requires (D& d, T& t) { std::declval<decltype(&t[0])&>() = &d[0]; }
inline void strcpy_trunc(D&& dst, const T& src)
{
const usz count = std::size(src) >= std::size(dst) ? std::max<usz>(std::size(dst), 1) - 1 : std::size(src);
std::memcpy(std::data(dst), std::data(src), count);
std::memset(std::data(dst) + count, 0, std::size(dst) - count);
std::copy_n(std::data(src), count, std::data(dst));
std::fill_n(std::data(dst) + count, std::size(dst) - count, std::remove_cvref_t<decltype(dst[0])>{});
}
// Convert string to signed integer

View file

@ -1397,9 +1397,9 @@ struct SceNpBasicMessageDetails
// Presence details of an user
struct SceNpBasicPresenceDetails
{
s8 title[SCE_NP_BASIC_PRESENCE_TITLE_SIZE_MAX];
s8 status[SCE_NP_BASIC_PRESENCE_STATUS_SIZE_MAX];
s8 comment[SCE_NP_BASIC_PRESENCE_COMMENT_SIZE_MAX];
char title[SCE_NP_BASIC_PRESENCE_TITLE_SIZE_MAX];
char status[SCE_NP_BASIC_PRESENCE_STATUS_SIZE_MAX];
char comment[SCE_NP_BASIC_PRESENCE_COMMENT_SIZE_MAX];
u8 data[SCE_NP_BASIC_MAX_PRESENCE_SIZE];
be_t<u32> size;
be_t<s32> state;
@ -1410,9 +1410,9 @@ struct SceNpBasicPresenceDetails2
{
be_t<u32> struct_size;
be_t<s32> state;
s8 title[SCE_NP_BASIC_PRESENCE_TITLE_SIZE_MAX];
s8 status[SCE_NP_BASIC_PRESENCE_EXTENDED_STATUS_SIZE_MAX];
s8 comment[SCE_NP_BASIC_PRESENCE_COMMENT_SIZE_MAX];
char title[SCE_NP_BASIC_PRESENCE_TITLE_SIZE_MAX];
char status[SCE_NP_BASIC_PRESENCE_EXTENDED_STATUS_SIZE_MAX];
char comment[SCE_NP_BASIC_PRESENCE_COMMENT_SIZE_MAX];
u8 data[SCE_NP_BASIC_MAX_PRESENCE_SIZE];
be_t<u32> size;
};
@ -1420,9 +1420,9 @@ struct SceNpBasicPresenceDetails2
// Country/region code
struct SceNpCountryCode
{
s8 data[2];
s8 term;
s8 padding[1];
char data[2];
char term;
char padding[1];
};
// Date information
@ -1451,8 +1451,8 @@ struct SceNpScoreGameInfo
// Ranking comment structure
struct SceNpScoreComment
{
s8 data[SCE_NP_SCORE_COMMENT_MAXLEN];
s8 term[1];
char data[SCE_NP_SCORE_COMMENT_MAXLEN];
char term[1];
};
// Ranking information structure
@ -1524,15 +1524,15 @@ struct SceNpScoreNpIdPcId
// Basic clan information to be used in raking
struct SceNpScoreClanBasicInfo
{
s8 clanName[SCE_NP_CLANS_CLAN_NAME_MAX_LENGTH + 1];
s8 clanTag[SCE_NP_CLANS_CLAN_TAG_MAX_LENGTH + 1];
char clanName[SCE_NP_CLANS_CLAN_NAME_MAX_LENGTH + 1];
char clanTag[SCE_NP_CLANS_CLAN_TAG_MAX_LENGTH + 1];
u8 reserved[10];
};
// Clan member information handled in ranking
struct SceNpScoreClansMemberDescription
{
s8 description[SCE_NP_CLANS_CLAN_DESCRIPTION_MAX_LENGTH + 1];
char description[SCE_NP_CLANS_CLAN_DESCRIPTION_MAX_LENGTH + 1];
};
// Clan ranking information