Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions core/libs/prx/libc/src/Formatting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,17 @@ int ScanSource(TSource source, const char* format, bool secure, NextPointer next
capped = wanted == 0 || wanted > limit;
width = wanted == 0 ? limit : std::min(wanted, limit);
}
const bool narrowInteger = !suppress && std::strchr("diouxX", conversion) != nullptr && (length.empty() || length == "h" || length == "hh");
std::uint64_t wideInteger = 0;
if (width != 0) directive += std::to_string(width);
directive += HostLength(length, conversion);
directive += narrowInteger ? std::string("ll") : HostLength(length, conversion);
directive += specifier;
directive += "%n";
int consumed = -1;
const int matched = source.Scan(directive.c_str(), suppress, target, &consumed);
const int matched = source.Scan(directive.c_str(), suppress, narrowInteger ? &wideInteger : target, &consumed);
if (consumed < 0 || (!suppress && matched != 1)) return finish(!converted && source.Peek() == EOF ? EOF : assigned);
source.Advance(consumed);
if (narrowInteger) std::memcpy(target, &wideInteger, length == "hh" ? 1 : length == "h" ? 2 : 4);
if (capped && conversion != 'c') {
const int next = source.Peek();
bool overflow = false;
Expand Down
7 changes: 7 additions & 0 deletions core/libs/tests/Formatting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,13 @@ __attribute__((noinline)) static void APS5_VABI RunChecks() {
Require(binary == 0 && binaryEnd == 1 && std::strcmp(binaryRest, "b101") == 0);
Require(ScanList(" -0B11", "%i", &binary) == 1 && binary == 0);
Require(ScanListS("0b1", "%i", &binary) == 1 && binary == 0);
unsigned int hexWrap = 0;
unsigned short shortWrap = 0;
unsigned char byteWrap = 0;
*__error_nid_postfix() = 7;
Require(ScanListS("61439ebdf", "%x", &hexWrap) == 1 && hexWrap == 0x1439ebdfu && *__error_nid_postfix() == 7);
Require(ScanListS("-eb371ade9", "%hx", &shortWrap) == 1 && shortWrap == 0x5217 && *__error_nid_postfix() == 7);
Require(ScanListS("867259ccd", "%hhX", &byteWrap) == 1 && byteWrap == 0xcd && *__error_nid_postfix() == 7);
Require(sscanf_nid_postfix("0x1f", "%i", &binary) == 1 && binary == 31);
#ifdef _WIN32
int scanned = -1;
Expand Down
Loading