memmove fixed for the size_t len equal to zero

This commit is contained in:
Hugo LAMY
2019-11-28 15:05:47 +01:00
parent b542d8adc0
commit d4ae1c7d34
2 changed files with 57 additions and 22 deletions

View File

@@ -6,7 +6,7 @@
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/25 13:56:25 by hulamy #+# #+# */
/* Updated: 2019/11/25 13:56:29 by hulamy ### ########.fr */
/* Updated: 2019/11/28 14:57:58 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,18 +18,20 @@
void *ft_memmove(void *dst, const void *src, size_t len)
{
int i;
char *source;
char *dest;
size_t i;
char *cpsrc;
char *cpdst;
i = -1;
source = (char *)src;
dest = (char *)dst;
if (source < dest)
while ((int)(--len) >= 0)
dest[len] = source[len];
cpsrc = (char *)src;
cpdst = (char *)dst;
if (dst == src)
return (dst);
if (cpsrc < cpdst)
while (len--)
cpdst[len] = cpsrc[len];
else
while (++i < (int)len)
dest[i] = source[i];
while (++i < len)
cpdst[i] = cpsrc[i];
return (dst);
}