Skip to content

Commit 25d81c9

Browse files
Chuck Toddfacchinm
Chuck Todd
authored andcommitted
Print not Aborting on Write() failure
Print::write(const uint8_t *buffer, size_t size) and Print::print(const __FlashStringHelper *ifsh) would continue calling write(char) after a failed write(char) this behavior would render returned count unuseable see arduino/Arduino issue #3614
1 parent cb6b2cf commit 25d81c9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

hardware/arduino/avr/cores/arduino/Print.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1818
1919
Modified 23 November 2006 by David A. Mellis
20+
Modified 03 August 2015 by Chuck Todd
2021
*/
2122

2223
#include <stdlib.h>
@@ -34,7 +35,8 @@ size_t Print::write(const uint8_t *buffer, size_t size)
3435
{
3536
size_t n = 0;
3637
while (size--) {
37-
n += write(*buffer++);
38+
if (write(*buffer++)) n++;
39+
else break;
3840
}
3941
return n;
4042
}
@@ -46,7 +48,8 @@ size_t Print::print(const __FlashStringHelper *ifsh)
4648
while (1) {
4749
unsigned char c = pgm_read_byte(p++);
4850
if (c == 0) break;
49-
n += write(c);
51+
if (write(c)) n++;
52+
else break;
5053
}
5154
return n;
5255
}

0 commit comments

Comments
 (0)