ft_memmove: add overlap control

This commit is contained in:
Tanguy MAZE 2018-04-08 13:31:10 +02:00
parent ff9d5ebbb5
commit 2608cfbc5a

View File

@ -6,7 +6,7 @@
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */ /* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/06 15:06:49 by tmaze #+# #+# */ /* Created: 2018/04/06 15:06:49 by tmaze #+# #+# */
/* Updated: 2018/04/06 16:50:07 by tmaze ### ########.fr */ /* Updated: 2018/04/08 13:28:55 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,7 +17,14 @@ void *ft_memmove(void *dst, const void *src, size_t len)
size_t i; size_t i;
i = 0; i = 0;
while (++i <= len) if (src < dst)
((char*)dst)[i - 1] = ((char*)src)[i - 1]; {
i = len + 1;
while (--i > 0)
((char*)dst)[i - 1] = ((char*)src)[i - 1];
}
else if (src > dst)
while (++i <= len)
((char*)dst)[i - 1] = ((char*)src)[i - 1];
return (dst); return (dst);
} }