mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Fixed printf width parameter.
This commit is contained in:
@@ -730,6 +730,12 @@ namespace bx
|
||||
{
|
||||
int32_t size = 0;
|
||||
int32_t len = (int32_t)strLen(_str, _len);
|
||||
|
||||
if (_param.width > 0)
|
||||
{
|
||||
len = min(_param.width, len);
|
||||
}
|
||||
|
||||
int32_t padding = _param.width > len ? _param.width - len : 0;
|
||||
bool sign = _param.sign && len > 1 && _str[0] != '-';
|
||||
padding = padding > 0 ? padding - sign : 0;
|
||||
|
||||
@@ -97,6 +97,15 @@ TEST_CASE("vsnprintf d/i/o/u/x")
|
||||
REQUIRE(test("000000000000edcb5433", "%020x", -0x1234abcd) );
|
||||
REQUIRE(test("000000000000EDCB5433", "%020X", -0x1234abcd) );
|
||||
|
||||
REQUIRE(test("0xf", "0x%01x", -1) );
|
||||
REQUIRE(test("0xff", "0x%02x", -1) );
|
||||
REQUIRE(test("0xfff", "0x%03x", -1) );
|
||||
REQUIRE(test("0xffff", "0x%04x", -1) );
|
||||
REQUIRE(test("0xfffff", "0x%05x", -1) );
|
||||
REQUIRE(test("0xffffff", "0x%06x", -1) );
|
||||
REQUIRE(test("0xfffffff", "0x%07x", -1) );
|
||||
REQUIRE(test("0xffffffff", "0x%08x", -1) );
|
||||
|
||||
if (BX_ENABLED(BX_ARCH_32BIT) )
|
||||
{
|
||||
REQUIRE(test("2147483647", "%jd", INTMAX_MAX) );
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user