Skip to content

Commit

Permalink
Fix ulib's memmove to handle overlap when src<dst
Browse files Browse the repository at this point in the history
  • Loading branch information
anishathalye committed Oct 9, 2019
1 parent 8509784 commit f2df0fa
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions user/ulib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit f2df0fa

Please sign in to comment.