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 <noreply@anthropic.com>
This commit is contained in:
owner
2026-09-26 13:01:53 -06:00
parent 1a0ebbc849
commit 63209b584f
2 changed files with 4 additions and 4 deletions
@@ -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;
}
+2 -2
View File
@@ -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(