mirror of
https://github.com/RPCS3/rpcs3.git
synced 2026-06-06 23:25:02 -06:00
Fix strcpy_trunc type validation
This commit is contained in:
parent
3b6afc1d9a
commit
cc1b4c8fd1
@ -13,13 +13,13 @@ std::string wchar_to_utf8(std::wstring_view src);
|
|||||||
std::string utf16_to_utf8(std::u16string_view src);
|
std::string utf16_to_utf8(std::u16string_view src);
|
||||||
std::u16string utf8_to_utf16(std::string_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
|
// Copy null-terminated string from a std::basic_string or a char array to a char array with truncation
|
||||||
template <typename D, typename T>
|
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)
|
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);
|
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::copy_n(std::data(src), count, std::data(dst));
|
||||||
std::memset(std::data(dst) + count, 0, std::size(dst) - count);
|
std::fill_n(std::data(dst) + count, std::size(dst) - count, std::remove_cvref_t<decltype(dst[0])>{});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert string to signed integer
|
// Convert string to signed integer
|
||||||
|
|||||||
@ -1397,9 +1397,9 @@ struct SceNpBasicMessageDetails
|
|||||||
// Presence details of an user
|
// Presence details of an user
|
||||||
struct SceNpBasicPresenceDetails
|
struct SceNpBasicPresenceDetails
|
||||||
{
|
{
|
||||||
s8 title[SCE_NP_BASIC_PRESENCE_TITLE_SIZE_MAX];
|
char title[SCE_NP_BASIC_PRESENCE_TITLE_SIZE_MAX];
|
||||||
s8 status[SCE_NP_BASIC_PRESENCE_STATUS_SIZE_MAX];
|
char status[SCE_NP_BASIC_PRESENCE_STATUS_SIZE_MAX];
|
||||||
s8 comment[SCE_NP_BASIC_PRESENCE_COMMENT_SIZE_MAX];
|
char comment[SCE_NP_BASIC_PRESENCE_COMMENT_SIZE_MAX];
|
||||||
u8 data[SCE_NP_BASIC_MAX_PRESENCE_SIZE];
|
u8 data[SCE_NP_BASIC_MAX_PRESENCE_SIZE];
|
||||||
be_t<u32> size;
|
be_t<u32> size;
|
||||||
be_t<s32> state;
|
be_t<s32> state;
|
||||||
@ -1410,9 +1410,9 @@ struct SceNpBasicPresenceDetails2
|
|||||||
{
|
{
|
||||||
be_t<u32> struct_size;
|
be_t<u32> struct_size;
|
||||||
be_t<s32> state;
|
be_t<s32> state;
|
||||||
s8 title[SCE_NP_BASIC_PRESENCE_TITLE_SIZE_MAX];
|
char title[SCE_NP_BASIC_PRESENCE_TITLE_SIZE_MAX];
|
||||||
s8 status[SCE_NP_BASIC_PRESENCE_EXTENDED_STATUS_SIZE_MAX];
|
char status[SCE_NP_BASIC_PRESENCE_EXTENDED_STATUS_SIZE_MAX];
|
||||||
s8 comment[SCE_NP_BASIC_PRESENCE_COMMENT_SIZE_MAX];
|
char comment[SCE_NP_BASIC_PRESENCE_COMMENT_SIZE_MAX];
|
||||||
u8 data[SCE_NP_BASIC_MAX_PRESENCE_SIZE];
|
u8 data[SCE_NP_BASIC_MAX_PRESENCE_SIZE];
|
||||||
be_t<u32> size;
|
be_t<u32> size;
|
||||||
};
|
};
|
||||||
@ -1420,9 +1420,9 @@ struct SceNpBasicPresenceDetails2
|
|||||||
// Country/region code
|
// Country/region code
|
||||||
struct SceNpCountryCode
|
struct SceNpCountryCode
|
||||||
{
|
{
|
||||||
s8 data[2];
|
char data[2];
|
||||||
s8 term;
|
char term;
|
||||||
s8 padding[1];
|
char padding[1];
|
||||||
};
|
};
|
||||||
|
|
||||||
// Date information
|
// Date information
|
||||||
@ -1451,8 +1451,8 @@ struct SceNpScoreGameInfo
|
|||||||
// Ranking comment structure
|
// Ranking comment structure
|
||||||
struct SceNpScoreComment
|
struct SceNpScoreComment
|
||||||
{
|
{
|
||||||
s8 data[SCE_NP_SCORE_COMMENT_MAXLEN];
|
char data[SCE_NP_SCORE_COMMENT_MAXLEN];
|
||||||
s8 term[1];
|
char term[1];
|
||||||
};
|
};
|
||||||
|
|
||||||
// Ranking information structure
|
// Ranking information structure
|
||||||
@ -1524,15 +1524,15 @@ struct SceNpScoreNpIdPcId
|
|||||||
// Basic clan information to be used in raking
|
// Basic clan information to be used in raking
|
||||||
struct SceNpScoreClanBasicInfo
|
struct SceNpScoreClanBasicInfo
|
||||||
{
|
{
|
||||||
s8 clanName[SCE_NP_CLANS_CLAN_NAME_MAX_LENGTH + 1];
|
char clanName[SCE_NP_CLANS_CLAN_NAME_MAX_LENGTH + 1];
|
||||||
s8 clanTag[SCE_NP_CLANS_CLAN_TAG_MAX_LENGTH + 1];
|
char clanTag[SCE_NP_CLANS_CLAN_TAG_MAX_LENGTH + 1];
|
||||||
u8 reserved[10];
|
u8 reserved[10];
|
||||||
};
|
};
|
||||||
|
|
||||||
// Clan member information handled in ranking
|
// Clan member information handled in ranking
|
||||||
struct SceNpScoreClansMemberDescription
|
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
|
// Clan ranking information
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user