Fixed printf width parameter.

This commit is contained in:
Бранимир Караџић
2020-04-29 17:57:54 -07:00
parent 1d1d09a152
commit f1db37eec3
3 changed files with 15 additions and 0 deletions

View File

@@ -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;

View File

@@ -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.