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:
parent
7a93478a99
commit
de9e8e024b
@ -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) {
|
char* strncpy_P(char* dest, PGM_P src, size_t size) {
|
||||||
|
bool size_known = (size != SIZE_IRRELEVANT);
|
||||||
const char* read = src;
|
const char* read = src;
|
||||||
char* write = dest;
|
char* write = dest;
|
||||||
char ch = '.';
|
char ch = '.';
|
||||||
@ -156,6 +157,14 @@ char* strncpy_P(char* dest, PGM_P src, size_t size) {
|
|||||||
*write++ = ch;
|
*write++ = ch;
|
||||||
size--;
|
size--;
|
||||||
}
|
}
|
||||||
|
if (size_known)
|
||||||
|
{
|
||||||
|
while (size > 0)
|
||||||
|
{
|
||||||
|
*write++ = 0;
|
||||||
|
size--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user