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;
|
||||
src = vsrc;
|
||||
while(n-- > 0)
|
||||
*dst++ = *src++;
|
||||
if (src > dst) {
|
||||
while(n-- > 0)
|
||||
*dst++ = *src++;
|
||||
} else {
|
||||
dst += n;
|
||||
src += n;
|
||||
while(n-- > 0)
|
||||
*--dst = *--src;
|
||||
}
|
||||
return vdst;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue