From 5cf71b55960651fc506df0ac41490f12dd1d63fd Mon Sep 17 00:00:00 2001 From: Alexey 'alexxy' Shvetsov Date: Fri, 15 May 2020 23:26:08 +0300 Subject: [PATCH] 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 --- shared/libc/string0.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/shared/libc/string0.c b/shared/libc/string0.c index 19ad14d0f7..a3b268e441 100644 --- a/shared/libc/string0.c +++ b/shared/libc/string0.c @@ -25,7 +25,7 @@ */ #include -#include +#include #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