alelievr / libft-unit-test

455 stars 88 forks source link

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

Closed cassepipe closed 4 years ago

cassepipe commented 4 years ago

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 ?

cassepipe commented 4 years ago

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