alelievr / libft-unit-test

453 stars 88 forks source link

[ft_putnbr_fd] Test feedback seems incorrect or is worded wrongly. #137

Open DanielAJL opened 1 year ago

DanielAJL commented 1 year ago

For the tests I am having an issue with the "our putnbr_fd allocate memory, wtf ???" test result. I am not allocating any memory as far as I can tell. Once I change int to long int for the li_num variable; it fixes both failed cases. I'm not sure if the description of the test result is correct or that the test itself is not correct.

Test results:

image

My ft_putnbr_fd:

void    ft_putnbr_fd(int n, int fd)
{
    int li_num;

    li_num = n;
    if (li_num < 0)
    {
        write(fd, "-", 1);
        li_num *= -1;
    }
    if (li_num >= 10)
    {
        ft_putnbr_fd((li_num / 10), fd);
        ft_putchar_fd(li_num % 10 + '0', fd);
    }
    else
        ft_putchar_fd(li_num + '0', fd);
}
github-actions[bot] commented 1 year ago

Hello! Thanks for contributing to the libft unit test.

Note that this repository is not maintained by the owner anymore, instead there is a bot that will automatically merge any reviewed pull requests. If you feel like it, here are some links that can help you submiting a change in the code base::

lorenzoedoardofrancesco commented 1 year ago

You're overflowing your int when multiplying li_num = -1 and li_num is MIN_INT (-2147483648) It would give you +2147483648, which is MAX_INT + 1 That's the reason of the two errors (signed integer overflow is undefined behavior, which gives you error 2)