diff options
author | Alexey 'alexxy' Shvetsov <alexxyum@gmail.com> | 2020-05-15 23:26:08 +0300 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2021-11-17 13:58:07 +1100 |
commit | 5cf71b55960651fc506df0ac41490f12dd1d63fd (patch) | |
tree | 9633dddfe48446c66c53a94e6c1ab9e1e0ef146a /shared/libc/string0.c | |
parent | d11ff0499fe52cfc9443aa6c0cb1620fd3dd1e70 (diff) |
shared/libc/string0: Don't include string.h, and provide __memcpy_chk.
Some toolchains will have string.h defining various macros which can lead
to compile errors for string function implementations. Not including
string.h fixes this.
An implementation of __memcpy_chk is provided for toolchains that enable
_FORTIFY_SOURCE.
Fixes issue #6046.
Signed-off-by: Alexey 'alexxy' Shvetsov <alexxyum@gmail.com>
Diffstat (limited to 'shared/libc/string0.c')
-rw-r--r-- | shared/libc/string0.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/shared/libc/string0.c b/shared/libc/string0.c index 19ad14d0f..a3b268e44 100644 --- a/shared/libc/string0.c +++ b/shared/libc/string0.c @@ -25,7 +25,7 @@ */ #include <stdint.h> -#include <string.h> +#include <stddef.h> #define likely(x) __builtin_expect((x), 1) @@ -64,6 +64,13 @@ void *memcpy(void *dst, const void *src, size_t n) { return dst; } +void *__memcpy_chk(void *dest, const void *src, size_t len, size_t slen) { + if (len > slen) { + return NULL; + } + return memcpy(dest, src, len); +} + void *memmove(void *dest, const void *src, size_t n) { if (src < dest && (uint8_t*)dest < (const uint8_t*)src + n) { // need to copy backwards |