On Sun, May 27, 2018 at 9:20 PM Dmitry Timoshkov dmitry@baikal.ru wrote:
Alex Henrie alexhenrie24@gmail.com wrote:
+static inline wchar_t* __cdecl wmemmove(wchar_t *dst, const wchar_t
*src, size_t n)
+{
- size_t i;
- if (dst <= src) return wmemcpy(dst, src, n);
- for (i = 1; i <= n; i++)
dst[n - i] = src[n - i];
- return dst;
+}
The optimization with wmemcpy() looks arbitrary and not safe.
It looks perfectly safe to me. Can you give an example of valid inputs that would cause memory corruption?
Why not simply call memmove(dst, src, n * sizeof(wchar_t)) ?
Shouldn't wmemcpy() implementation also simply call memcpy() in a similar way?
I wasn't sure whether wchar.h on Windows includes string.h. I just tested it and it looks like it does, so we could call functions from string.h instead if that is preferred.
-Alex