alelievr/libft-unit-test

ft_calloc : Two versions of the same, only one fails, why ?

cassepipe opened this issue · 1 comments

The following code passes the tests for ft_calloc ...

static void *ft_memalloc(size_t size)
{
	void	*data;

	data = malloc(size);
	if (data)
		ft_bzero(data, size);
	return (data);
}

void	*ft_calloc(size_t count, size_t size)
{
	return (ft_memalloc(count * size));
}

But this one fails with "your calloc does not work with empty string " :

void	*ft_calloc(size_t count, size_t size)
{
	void	*data;

	data = malloc(count * size);
	if (data)
		ft_bzero(data, size);
	return (data);
}

What am I missing ? Is this a bug ?

In the second code block, should be ft_bzero(data, count * size);