Skip to content

Commit 57973bc

Browse files
committed
Check for NULL pointer in Print.write().
Otherwise, trying to print(NULL) or write(NULL) could print a random character. http://code.google.com/p/arduino/issues/detail?id=941
1 parent 4ed0bd2 commit 57973bc

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

cores/arduino/Print.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ class Print
4646
void clearWriteError() { setWriteError(0); }
4747

4848
virtual size_t write(uint8_t) = 0;
49-
size_t write(const char *str) { return write((const uint8_t *)str, strlen(str)); }
49+
size_t write(const char *str) {
50+
if (str == NULL) return 0;
51+
return write((const uint8_t *)str, strlen(str));
52+
}
5053
virtual size_t write(const uint8_t *buffer, size_t size);
5154

5255
size_t print(const __FlashStringHelper *);

0 commit comments

Comments
 (0)