Skip to content
Merged
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
6 changes: 6 additions & 0 deletions api/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
uint8_t i = 0;
uint8_t innerLoops = 0;

// Special case workaround https://github.com/arduino/ArduinoCore-API/issues/178
if (n64 == 0) {
write('0');
return 1;
}

// prevent crash if called with base == 1
if (base < 2) base = 10;

Expand Down
22 changes: 17 additions & 5 deletions test/src/Print/test_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,24 @@ TEST_CASE ("Print::print(unsigned long long, int = DEC|HEX|OCT|BIN)", "[Print-pr
{
PrintMock mock;

unsigned long long const val = 17;
GIVEN("a value of zero ...")
{
unsigned long long const val = 0;

WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "17"); }
WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "11"); }
WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "21"); }
WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "10001"); }
WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "0"); }
WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "0"); }
WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "0"); }
WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "0"); }
}
GIVEN("a non-zero value ...")
{
unsigned long long const val = 17;

WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "17"); }
WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "11"); }
WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "21"); }
WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "10001"); }
}
}

TEST_CASE ("Print::print(double, int = 2)", "[Print-print-10]")
Expand Down