From 48deb37cc8e3aee787db4d4a9df3af78150a376a Mon Sep 17 00:00:00 2001 From: ANR2ME Date: Sat, 6 Aug 2022 03:10:59 +0700 Subject: [PATCH 1/3] Fix logging warning issue. --- Core/HLE/sceNp.cpp | 6 +++--- Core/HLE/sceNp2.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Core/HLE/sceNp.cpp b/Core/HLE/sceNp.cpp index 4c71f3db55..dbe4c273ad 100644 --- a/Core/HLE/sceNp.cpp +++ b/Core/HLE/sceNp.cpp @@ -207,8 +207,8 @@ static int sceNpGetAccountRegion(u32 countryCodePtr, u32 regionCodePtr) SceNpCountryCode dummyRegionCode{}; memcpy(dummyRegionCode.data, npRegionCode, sizeof(dummyRegionCode.data)); - INFO_LOG(SCENET, "%s - Country Code: %d", __FUNCTION__, dummyCountryCode.data); - INFO_LOG(SCENET, "%s - Region? Code: %d", __FUNCTION__, dummyRegionCode.data); + INFO_LOG(SCENET, "%s - Country Code: %s", __FUNCTION__, dummyCountryCode.data); + INFO_LOG(SCENET, "%s - Region? Code: %s", __FUNCTION__, dummyRegionCode.data); Memory::WriteStruct(countryCodePtr, &dummyCountryCode); Memory::WriteStruct(regionCodePtr, &dummyRegionCode); @@ -487,7 +487,7 @@ int sceNpAuthGetTicketParam(u32 ticketBufPtr, int ticketLen, int paramNum, u32 b SceNpTicketParamData* ticketParam = (SceNpTicketParamData*)Memory::GetPointer(inbuf); u32 sz = (u32)sizeof(SceNpTicketParamData) + ticketParam->length; Memory::Memcpy(outbuf, inbuf, sz); - DEBUG_LOG(SCENET, "%s - Param #%d: Type = %04x, Length = %u", __FUNCTION__, i, ticketParam->type, static_cast(ticketParam->length)); + DEBUG_LOG(SCENET, "%s - Param #%d: Type = %04hx, Length = %u", __FUNCTION__, i, static_cast(ticketParam->type), static_cast(ticketParam->length)); outbuf += sz; inbuf += sz; if (outbuf - bufferPtr >= PARAM_BUFFER_MAX_SIZE || inbuf - ticketBufPtr >= (u32)ticketLen) diff --git a/Core/HLE/sceNp2.cpp b/Core/HLE/sceNp2.cpp index b0a7565fde..166029bad4 100644 --- a/Core/HLE/sceNp2.cpp +++ b/Core/HLE/sceNp2.cpp @@ -80,7 +80,7 @@ static int sceNpMatching2Term() static int sceNpMatching2CreateContext(u32 communicationIdPtr, u32 passPhrasePtr, u32 ctxIdPtr, int unknown) { - ERROR_LOG(SCENET, "UNIMPL %s(%08x[%s], %08x[%08x], %08x[%d], %d) at %08x", __FUNCTION__, communicationIdPtr, Memory::GetCharPointer(communicationIdPtr), passPhrasePtr, Memory::Read_U32(passPhrasePtr), ctxIdPtr, Memory::Read_U16(ctxIdPtr), unknown, currentMIPS->pc); + ERROR_LOG(SCENET, "UNIMPL %s(%08x[%s], %08x[%08x], %08x[%hu], %i) at %08x", __FUNCTION__, communicationIdPtr, Memory::GetCharPointer(communicationIdPtr), passPhrasePtr, Memory::Read_U32(passPhrasePtr), ctxIdPtr, Memory::Read_U16(ctxIdPtr), unknown, currentMIPS->pc); if (!npMatching2Inited) return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED); From 3b7a33ddd8b6a1f11c785ea9585fff3f11417251 Mon Sep 17 00:00:00 2001 From: ANR2ME Date: Sat, 6 Aug 2022 11:04:07 +0700 Subject: [PATCH 2/3] Prefer using "%04x" over "%04hx". --- Core/HLE/sceNp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/HLE/sceNp.cpp b/Core/HLE/sceNp.cpp index dbe4c273ad..ac0e29a8cf 100644 --- a/Core/HLE/sceNp.cpp +++ b/Core/HLE/sceNp.cpp @@ -487,7 +487,7 @@ int sceNpAuthGetTicketParam(u32 ticketBufPtr, int ticketLen, int paramNum, u32 b SceNpTicketParamData* ticketParam = (SceNpTicketParamData*)Memory::GetPointer(inbuf); u32 sz = (u32)sizeof(SceNpTicketParamData) + ticketParam->length; Memory::Memcpy(outbuf, inbuf, sz); - DEBUG_LOG(SCENET, "%s - Param #%d: Type = %04hx, Length = %u", __FUNCTION__, i, static_cast(ticketParam->type), static_cast(ticketParam->length)); + DEBUG_LOG(SCENET, "%s - Param #%d: Type = %04x, Length = %u", __FUNCTION__, i, static_cast(ticketParam->type), static_cast(ticketParam->length)); outbuf += sz; inbuf += sz; if (outbuf - bufferPtr >= PARAM_BUFFER_MAX_SIZE || inbuf - ticketBufPtr >= (u32)ticketLen) From 0b3fdf0cef738c76d184bd79c8c56d3caf8d92e8 Mon Sep 17 00:00:00 2001 From: ANR2ME Date: Sat, 6 Aug 2022 11:22:38 +0700 Subject: [PATCH 3/3] Use safe_string when printing %s with Memory::GetCharPointer. --- Common/StringUtils.cpp | 4 ++++ Common/StringUtils.h | 2 ++ Core/HLE/sceNp2.cpp | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Common/StringUtils.cpp b/Common/StringUtils.cpp index e3d67c5a78..c4b88c4c3a 100644 --- a/Common/StringUtils.cpp +++ b/Common/StringUtils.cpp @@ -55,6 +55,10 @@ void truncate_cpy(char *dest, size_t destSize, const char *src) { } } +const char* safe_string(const char* s) { + return s ? s : "(null)"; +} + long parseHexLong(std::string s) { long value = 0; diff --git a/Common/StringUtils.h b/Common/StringUtils.h index 696018e35d..989fe8b9fd 100644 --- a/Common/StringUtils.h +++ b/Common/StringUtils.h @@ -84,6 +84,8 @@ inline void truncate_cpy(char(&out)[Count], const char *src) { truncate_cpy(out, Count, src); } +const char* safe_string(const char* s); + long parseHexLong(std::string s); long parseLong(std::string s); std::string StringFromFormat(const char* format, ...); diff --git a/Core/HLE/sceNp2.cpp b/Core/HLE/sceNp2.cpp index 166029bad4..98a50b1fa8 100644 --- a/Core/HLE/sceNp2.cpp +++ b/Core/HLE/sceNp2.cpp @@ -80,7 +80,7 @@ static int sceNpMatching2Term() static int sceNpMatching2CreateContext(u32 communicationIdPtr, u32 passPhrasePtr, u32 ctxIdPtr, int unknown) { - ERROR_LOG(SCENET, "UNIMPL %s(%08x[%s], %08x[%08x], %08x[%hu], %i) at %08x", __FUNCTION__, communicationIdPtr, Memory::GetCharPointer(communicationIdPtr), passPhrasePtr, Memory::Read_U32(passPhrasePtr), ctxIdPtr, Memory::Read_U16(ctxIdPtr), unknown, currentMIPS->pc); + ERROR_LOG(SCENET, "UNIMPL %s(%08x[%s], %08x[%08x], %08x[%hu], %i) at %08x", __FUNCTION__, communicationIdPtr, safe_string(Memory::GetCharPointer(communicationIdPtr)), passPhrasePtr, Memory::Read_U32(passPhrasePtr), ctxIdPtr, Memory::Read_U16(ctxIdPtr), unknown, currentMIPS->pc); if (!npMatching2Inited) return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED);