1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

pgmspace: zero out memory in strncpy_P (#2633)

strncpy should write 'size' characters, padding with zeroes if src is
shorter than 'size'.
This commit is contained in:
Ivan Grokhotkov 2017-10-13 02:17:06 +08:00
parent 7a93478a99
commit de9e8e024b

View File

@ -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 = '.';
@ -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;
}