Skip to content

Commit

Permalink
Print::write(string) gracefully handle null pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulStoffregen committed Jan 14, 2023
1 parent 0bdfd22 commit 7243438
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion teensy3/Print.h
Expand Up @@ -56,7 +56,8 @@ class Print
public:
constexpr Print() : write_error(0) {}
virtual size_t write(uint8_t b) = 0;
size_t write(const char *str) { return write((const uint8_t *)str, strlen(str)); }
size_t write(const char *str) { if (str == nullptr) return 0;
return write((const uint8_t *)str, strlen(str)); }
virtual size_t write(const uint8_t *buffer, size_t size);
virtual int availableForWrite(void) { return 0; }
virtual void flush() { }
Expand Down
3 changes: 2 additions & 1 deletion teensy4/Print.h
Expand Up @@ -56,7 +56,8 @@ class Print
public:
constexpr Print() : write_error(0) {}
virtual size_t write(uint8_t b) = 0;
size_t write(const char *str) { return write((const uint8_t *)str, strlen(str)); }
size_t write(const char *str) { if (str == nullptr) return 0;
return write((const uint8_t *)str, strlen(str)); }
virtual size_t write(const uint8_t *buffer, size_t size);
virtual int availableForWrite(void) { return 0; }
virtual void flush() { }
Expand Down

0 comments on commit 7243438

Please sign in to comment.