mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-03-14 01:27:00 +00:00
Fix old warnings: remove strncpy
Use strcpy_trunc instead. Change some sce structs.
This commit is contained in:
parent
c66b155dcb
commit
f944573b3c
@ -853,8 +853,7 @@ struct SceNpDrmOpenArg
|
||||
// NP communication ID structure
|
||||
struct SceNpCommunicationId
|
||||
{
|
||||
char data[9];
|
||||
char term;
|
||||
char data[9 + 1]; // char term;
|
||||
u8 num;
|
||||
char dummy;
|
||||
};
|
||||
@ -862,8 +861,7 @@ struct SceNpCommunicationId
|
||||
// OnlineId structure
|
||||
struct SceNpOnlineId
|
||||
{
|
||||
char data[16];
|
||||
char term;
|
||||
char data[16 + 1]; // char term;
|
||||
char dummy[3];
|
||||
};
|
||||
|
||||
@ -888,16 +886,14 @@ CHECK_SIZE_ALIGN(SceNpId, 0x24, 1);
|
||||
// Online Name structure
|
||||
struct SceNpOnlineName
|
||||
{
|
||||
char data[48];
|
||||
char term;
|
||||
char data[48 + 1]; // char term;
|
||||
char padding[3];
|
||||
};
|
||||
|
||||
// Avatar structure
|
||||
struct SceNpAvatarUrl
|
||||
{
|
||||
char data[127];
|
||||
char term;
|
||||
char data[127 + 1]; // char term;
|
||||
};
|
||||
|
||||
// Avatar image structure
|
||||
@ -911,8 +907,7 @@ struct SceNpAvatarImage
|
||||
// Self introduction structure
|
||||
struct SceNpAboutMe
|
||||
{
|
||||
char data[SCE_NET_NP_ABOUT_ME_MAX_LENGTH];
|
||||
char term;
|
||||
char data[SCE_NET_NP_ABOUT_ME_MAX_LENGTH + 1]; // char term;
|
||||
};
|
||||
|
||||
// User information structure
|
||||
|
@ -392,7 +392,7 @@ error_code sceNpTrophyCreateContext(vm::ptr<u32> context, vm::cptr<SceNpCommunic
|
||||
name_sv = name_sv.substr(0, pos);
|
||||
}
|
||||
|
||||
sceNpTrophy.warning("sceNpTrophyCreateContext(): data='%s' term='%c' (0x%x) num=%d", name_sv, commId->term, commId->term, commId->num);
|
||||
sceNpTrophy.warning("sceNpTrophyCreateContext(): data='%s' term='%c' (0x%x) num=%d", name_sv, commId->data[9], commId->data[9], commId->num);
|
||||
|
||||
// append the commId number as "_xx"
|
||||
const std::string name = fmt::format("%s_%02d", name_sv, commId->num);
|
||||
|
@ -41,17 +41,17 @@ void np_handler::RoomGroup_to_SceNpMatching2RoomGroup(const flatbuffers::Vector<
|
||||
void np_handler::UserInfo2_to_SceNpUserInfo2(const UserInfo2* user, SceNpUserInfo2* user_info)
|
||||
{
|
||||
if (user->npId())
|
||||
memcpy(user_info->npId.handle.data, user->npId()->c_str(), std::min(sizeof(user_info->npId.handle.data), static_cast<usz>(user->npId()->size())));
|
||||
std::memcpy(user_info->npId.handle.data, user->npId()->c_str(), std::min<usz>(9, user->npId()->size()));
|
||||
|
||||
if (user->onlineName())
|
||||
{
|
||||
user_info->onlineName.set(allocate(sizeof(SceNpOnlineName)));
|
||||
memcpy(user_info->onlineName->data, user->onlineName()->c_str(), std::min(sizeof(user_info->onlineName->data), static_cast<usz>(user->onlineName()->size())));
|
||||
std::memcpy(user_info->onlineName->data, user->onlineName()->c_str(), std::min<usz>(48, user->onlineName()->size()));
|
||||
}
|
||||
if (user->avatarUrl())
|
||||
{
|
||||
user_info->avatarUrl.set(allocate(sizeof(SceNpAvatarUrl)));
|
||||
memcpy(user_info->avatarUrl->data, user->avatarUrl()->c_str(), std::min(sizeof(user_info->avatarUrl->data), static_cast<usz>(user->avatarUrl()->size())));
|
||||
std::memcpy(user_info->avatarUrl->data, user->avatarUrl()->c_str(), std::min<usz>(127, user->avatarUrl()->size()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
score_ctx::score_ctx(vm::cptr<SceNpCommunicationId> communicationId, vm::cptr<SceNpCommunicationPassphrase> passphrase)
|
||||
{
|
||||
ensure(!communicationId->term && strlen(communicationId->data) == 9);
|
||||
ensure(!communicationId->data[9] && strlen(communicationId->data) == 9);
|
||||
memcpy(&this->communicationId, communicationId.get_ptr(), sizeof(SceNpCommunicationId));
|
||||
memcpy(&this->passphrase, passphrase.get_ptr(), sizeof(SceNpCommunicationPassphrase));
|
||||
}
|
||||
@ -33,7 +33,7 @@ bool destroy_score_transaction_context(s32 ctx_id)
|
||||
|
||||
match2_ctx::match2_ctx(vm::cptr<SceNpCommunicationId> communicationId, vm::cptr<SceNpCommunicationPassphrase> passphrase)
|
||||
{
|
||||
ensure(!communicationId->term && strlen(communicationId->data) == 9);
|
||||
ensure(!communicationId->data[9] && strlen(communicationId->data) == 9);
|
||||
memcpy(&this->communicationId, communicationId.get_ptr(), sizeof(SceNpCommunicationId));
|
||||
memcpy(&this->passphrase, passphrase.get_ptr(), sizeof(SceNpCommunicationPassphrase));
|
||||
}
|
||||
@ -56,7 +56,7 @@ std::shared_ptr<match2_ctx> get_match2_context(u16 ctx_id)
|
||||
|
||||
lookup_title_ctx::lookup_title_ctx(vm::cptr<SceNpCommunicationId> communicationId)
|
||||
{
|
||||
ensure(!communicationId->term && strlen(communicationId->data) == 9);
|
||||
ensure(!communicationId->data[9] && strlen(communicationId->data) == 9);
|
||||
memcpy(&this->communicationId, communicationId.get_ptr(), sizeof(SceNpCommunicationId));
|
||||
}
|
||||
s32 create_lookup_title_context(vm::cptr<SceNpCommunicationId> communicationId)
|
||||
|
@ -282,24 +282,21 @@ std::string np_handler::ether_to_string(std::array<u8, 6>& ether)
|
||||
return fmt::format("%02X:%02X:%02X:%02X:%02X:%02X", ether[0], ether[1], ether[2], ether[3], ether[4], ether[5]);
|
||||
}
|
||||
|
||||
void np_handler::string_to_npid(const char* str, SceNpId* npid)
|
||||
void np_handler::string_to_npid(const std::string& str, SceNpId* npid)
|
||||
{
|
||||
memset(npid, 0, sizeof(SceNpId));
|
||||
strncpy(npid->handle.data, str, sizeof(npid->handle.data));
|
||||
npid->handle.term = 0;
|
||||
strcpy_trunc(npid->handle.data, str);
|
||||
// npid->reserved[0] = 1;
|
||||
}
|
||||
|
||||
void np_handler::string_to_online_name(const char* str, SceNpOnlineName* online_name)
|
||||
void np_handler::string_to_online_name(const std::string& str, SceNpOnlineName* online_name)
|
||||
{
|
||||
strncpy(online_name->data, str, sizeof(online_name->data));
|
||||
online_name->term = 0;
|
||||
strcpy_trunc(online_name->data, str);
|
||||
}
|
||||
|
||||
void np_handler::string_to_avatar_url(const char* str, SceNpAvatarUrl* avatar_url)
|
||||
void np_handler::string_to_avatar_url(const std::string& str, SceNpAvatarUrl* avatar_url)
|
||||
{
|
||||
strncpy(avatar_url->data, str, sizeof(avatar_url->data));
|
||||
avatar_url->term = 0;
|
||||
strcpy_trunc(avatar_url->data, str);
|
||||
}
|
||||
|
||||
void np_handler::init_NP(u32 poolsize, vm::ptr<void> poolptr)
|
||||
@ -319,7 +316,7 @@ void np_handler::init_NP(u32 poolsize, vm::ptr<void> poolptr)
|
||||
std::string s_npid = g_cfg_rpcn.get_npid();
|
||||
ensure(!s_npid.empty()); // It should have been generated before this
|
||||
|
||||
np_handler::string_to_npid(s_npid.c_str(), &npid);
|
||||
np_handler::string_to_npid(s_npid, &npid);
|
||||
const auto sigh = g_fxo->get<named_thread<signaling_handler>>();
|
||||
sigh->set_self_sig_info(npid);
|
||||
}
|
||||
@ -354,8 +351,8 @@ void np_handler::init_NP(u32 poolsize, vm::ptr<void> poolptr)
|
||||
return;
|
||||
}
|
||||
|
||||
np_handler::string_to_online_name(rpcn.get_online_name().c_str(), &online_name);
|
||||
np_handler::string_to_avatar_url(rpcn.get_avatar_url().c_str(), &avatar_url);
|
||||
np_handler::string_to_online_name(rpcn.get_online_name(), &online_name);
|
||||
np_handler::string_to_avatar_url(rpcn.get_avatar_url(), &avatar_url);
|
||||
public_ip_addr = rpcn.get_addr_sig();
|
||||
|
||||
break;
|
||||
|
@ -35,9 +35,9 @@ public:
|
||||
static std::string ip_to_string(u32 addr);
|
||||
static std::string ether_to_string(std::array<u8, 6>& ether);
|
||||
// Helpers for setting various structures from string
|
||||
static void string_to_npid(const char* str, SceNpId* npid);
|
||||
static void string_to_online_name(const char* str, SceNpOnlineName* online_name);
|
||||
static void string_to_avatar_url(const char* str, SceNpAvatarUrl* avatar_url);
|
||||
static void string_to_npid(const std::string&, SceNpId* npid);
|
||||
static void string_to_online_name(const std::string&, SceNpOnlineName* online_name);
|
||||
static void string_to_avatar_url(const std::string&, SceNpAvatarUrl* avatar_url);
|
||||
|
||||
// DNS hooking functions
|
||||
void add_dns_spy(u32 sock);
|
||||
|
@ -557,7 +557,7 @@ void signaling_handler::disconnect_sig2_users(u64 room_id)
|
||||
|
||||
u32 signaling_handler::create_sig_infos(const SceNpId* npid)
|
||||
{
|
||||
ensure(npid->handle.term == 0);
|
||||
ensure(npid->handle.data[16] == 0);
|
||||
std::string npid_str(reinterpret_cast<const char*>(npid->handle.data));
|
||||
|
||||
if (npid_to_conn_id.count(npid_str))
|
||||
|
Loading…
x
Reference in New Issue
Block a user