Fix ulib's memmove to handle overlap when src<dst
This commit is contained in:
parent
8509784d80
commit
f2df0fa547
11
user/ulib.c
11
user/ulib.c
|
@ -103,8 +103,15 @@ memmove(void *vdst, const void *vsrc, int n)
|
||||||
|
|
||||||
dst = vdst;
|
dst = vdst;
|
||||||
src = vsrc;
|
src = vsrc;
|
||||||
while(n-- > 0)
|
if (src > dst) {
|
||||||
*dst++ = *src++;
|
while(n-- > 0)
|
||||||
|
*dst++ = *src++;
|
||||||
|
} else {
|
||||||
|
dst += n;
|
||||||
|
src += n;
|
||||||
|
while(n-- > 0)
|
||||||
|
*--dst = *--src;
|
||||||
|
}
|
||||||
return vdst;
|
return vdst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue