Skip to content

Commit 5cf71b5

Browse files
alexxydpgeorge
authored andcommitted
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 <[email protected]>
1 parent d11ff04 commit 5cf71b5

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

shared/libc/string0.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626

2727
#include <stdint.h>
28-
#include <string.h>
28+
#include <stddef.h>
2929

3030
#define likely(x) __builtin_expect((x), 1)
3131

@@ -64,6 +64,13 @@ void *memcpy(void *dst, const void *src, size_t n) {
6464
return dst;
6565
}
6666

67+
void *__memcpy_chk(void *dest, const void *src, size_t len, size_t slen) {
68+
if (len > slen) {
69+
return NULL;
70+
}
71+
return memcpy(dest, src, len);
72+
}
73+
6774
void *memmove(void *dest, const void *src, size_t n) {
6875
if (src < dest && (uint8_t*)dest < (const uint8_t*)src + n) {
6976
// need to copy backwards

0 commit comments

Comments
 (0)