Skip to content

Commit

Permalink
pgmspace: zero out memory in strncpy_P (#2633)
Browse files Browse the repository at this point in the history
strncpy should write 'size' characters, padding with zeroes if src is
shorter than 'size'.
  • Loading branch information
igrr committed Oct 12, 2017
1 parent 7a93478 commit de9e8e0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cores/esp8266/pgmspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ void* memmem_P(const void* buf, size_t bufSize, PGM_VOID_P findP, size_t findPSi


char* strncpy_P(char* dest, PGM_P src, size_t size) {
bool size_known = (size != SIZE_IRRELEVANT);
const char* read = src;
char* write = dest;
char ch = '.';
Expand All @@ -156,6 +157,14 @@ char* strncpy_P(char* dest, PGM_P src, size_t size) {
*write++ = ch;
size--;
}
if (size_known)
{
while (size > 0)
{
*write++ = 0;
size--;
}
}

return dest;
}
Expand Down

0 comments on commit de9e8e0

Please sign in to comment.