diff --git a/src/string.cpp b/src/string.cpp index 4684adf..dba1c8c 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -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; diff --git a/tests/vsnprintf_test.cpp b/tests/vsnprintf_test.cpp index ad94dae..9a00790 100644 --- a/tests/vsnprintf_test.cpp +++ b/tests/vsnprintf_test.cpp @@ -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) ); diff --git a/tools/bin/linux/bin2c b/tools/bin/linux/bin2c index d825698..5d168b6 100755 Binary files a/tools/bin/linux/bin2c and b/tools/bin/linux/bin2c differ