Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit267bab1

Browse files
authored
Merge pull request#203 from arduino/fix-178
Fix of empty string printed in case of a 64-bit unsigned integer.
2 parentsb052976 +754aa9b commit267bab1

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

‎api/Print.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
287287
uint8_t i =0;
288288
uint8_t innerLoops =0;
289289

290+
// Special case workaround https://github.com/arduino/ArduinoCore-API/issues/178
291+
if (n64 ==0) {
292+
write('0');
293+
return1;
294+
}
295+
290296
// prevent crash if called with base == 1
291297
if (base <2) base =10;
292298

‎test/src/Print/test_print.cpp‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,24 @@ TEST_CASE ("Print::print(unsigned long long, int = DEC|HEX|OCT|BIN)", "[Print-pr
110110
{
111111
PrintMock mock;
112112

113-
unsignedlonglongconst val =17;
113+
GIVEN("a value of zero ...")
114+
{
115+
unsignedlonglongconst val =0;
114116

115-
WHEN("DEC") { mock.print(val, DEC);REQUIRE(mock._str =="17"); }
116-
WHEN("HEX") { mock.print(val, HEX);REQUIRE(mock._str =="11"); }
117-
WHEN("OCT") { mock.print(val, OCT);REQUIRE(mock._str =="21"); }
118-
WHEN("BIN") { mock.print(val, BIN);REQUIRE(mock._str =="10001"); }
117+
WHEN("DEC") { mock.print(val, DEC);REQUIRE(mock._str =="0"); }
118+
WHEN("HEX") { mock.print(val, HEX);REQUIRE(mock._str =="0"); }
119+
WHEN("OCT") { mock.print(val, OCT);REQUIRE(mock._str =="0"); }
120+
WHEN("BIN") { mock.print(val, BIN);REQUIRE(mock._str =="0"); }
121+
}
122+
GIVEN("a non-zero value ...")
123+
{
124+
unsignedlonglongconst val =17;
125+
126+
WHEN("DEC") { mock.print(val, DEC);REQUIRE(mock._str =="17"); }
127+
WHEN("HEX") { mock.print(val, HEX);REQUIRE(mock._str =="11"); }
128+
WHEN("OCT") { mock.print(val, OCT);REQUIRE(mock._str =="21"); }
129+
WHEN("BIN") { mock.print(val, BIN);REQUIRE(mock._str =="10001"); }
130+
}
119131
}
120132

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp