From 63209b584fc6a15b91cb25c1b3f36ec4849ccae9 Mon Sep 17 00:00:00 2001 From: owner Date: Sat, 26 Sep 2026 13:01:53 -0600 Subject: [PATCH] fix: correct sscanf %x signedness and avoid a substr copy libSceSysmodule/Export.cpp parsed /proc/self/maps device major/minor numbers into signed int with a %x format, which is undefined behaviour per the C standard even though it happened to work on this target; switched to unsigned int to match the format specifier. NidPatcherUtils.hpp's StripNidPostfix built a truncated copy with substr(0, n) where the prefix is already the string itself; resize(n) does the same truncation without the extra allocation and copy. Co-Authored-By: Claude Sonnet 5 --- core/libs/nid/include/nid/NidPatcherUtils.hpp | 4 ++-- core/libs/prx/libSceSysmodule/Export.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/libs/nid/include/nid/NidPatcherUtils.hpp b/core/libs/nid/include/nid/NidPatcherUtils.hpp index 886296fef..f46775612 100644 --- a/core/libs/nid/include/nid/NidPatcherUtils.hpp +++ b/core/libs/nid/include/nid/NidPatcherUtils.hpp @@ -44,7 +44,7 @@ inline std::string StripNidPostfix(const std::string& name) { std::string result = name; if (result.size() >= kNidPostfixLen && result.compare(result.size() - kNidPostfixLen, kNidPostfixLen, kNidPostfix) == 0) { - result = result.substr(0u, result.size() - kNidPostfixLen); + result.resize(result.size() - kNidPostfixLen); } const auto disambigPos = result.rfind(kNidDisambigMarker); if (disambigPos != std::string::npos) { @@ -54,7 +54,7 @@ inline std::string StripNidPostfix(const std::string& name) { [](unsigned char c) { return std::isdigit(c) != 0; } ); if (allDigits && suffixStart < result.size()) - result = result.substr(0u, disambigPos); + result.resize(disambigPos); } return result; } diff --git a/core/libs/prx/libSceSysmodule/Export.cpp b/core/libs/prx/libSceSysmodule/Export.cpp index 9bb667574..b0457018b 100644 --- a/core/libs/prx/libSceSysmodule/Export.cpp +++ b/core/libs/prx/libSceSysmodule/Export.cpp @@ -55,8 +55,8 @@ bool fillModuleInfoForUnwind(std::uint64_t addr, ModuleInfoForUnwind* info) { std::uint64_t end = 0; char perms[8] = {}; std::uint64_t offset = 0; - int devMajor = 0; - int devMinor = 0; + unsigned int devMajor = 0; + unsigned int devMinor = 0; std::uint64_t inode = 0; char path[4096] = {}; int parsed = std::sscanf(