[PATCH 4/5] include: Add wmemmove to wchar.h
Alex Henrie
alexhenrie24 at gmail.com
Sun May 27 23:17:06 CDT 2018
On Sun, May 27, 2018 at 9:20 PM Dmitry Timoshkov <dmitry at baikal.ru> wrote:
> Alex Henrie <alexhenrie24 at 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
More information about the wine-devel
mailing list