Advertisement
teknoraver

memcpy overlap warn

Jun 25th, 2021
1,567
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 0.40 KB | None | 0 0
  1. diff --git a/lib/string.c b/lib/string.c
  2. index 546d59711a12..5fa442145935 100644
  3. --- a/lib/string.c
  4. +++ b/lib/string.c
  5. @@ -883,6 +883,9 @@ void *memcpy(void *dest, const void *src, size_t count)
  6.     char *tmp = dest;
  7.     const char *s = src;
  8.  
  9. +   if (WARN(dest > src && dest - src < count, "Unsafe memcpy!!!"))
  10. +       return memmove(dest, src, count);
  11. +
  12.     while (count--)
  13.         *tmp++ = *s++;
  14.     return dest;
  15.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement