Skip to content

Commit

Permalink
add check to prevent crash on null strings
Browse files Browse the repository at this point in the history
  • Loading branch information
proddy committed Sep 21, 2021
1 parent 16e390f commit 6ef8ff7
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/uuid-common/src/read_flash_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
namespace uuid {

std::string read_flash_string(const __FlashStringHelper * flash_str) {
if (flash_str == nullptr) {
return std::string(""); // prevent crash
}

std::string str(::strlen_P(reinterpret_cast<PGM_P>(flash_str)), '\0');

::strncpy_P(&str[0], reinterpret_cast<PGM_P>(flash_str), str.capacity() + 1);
Expand Down

0 comments on commit 6ef8ff7

Please sign in to comment.