From: Lukas Jiriste Date: Fri, 8 Sep 2023 10:11:54 +0000 (+0200) Subject: Repaired the function, so it can return "0" and doesn't write outside allocated memory. X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=f56fd060021c191397b4bbb600d5e9f4f1203fee;p=Libft.git Repaired the function, so it can return "0" and doesn't write outside allocated memory. --- diff --git a/ft_itoa_base.c b/ft_itoa_base.c index 7e0b901..45d19ef 100644 --- a/ft_itoa_base.c +++ b/ft_itoa_base.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/05 09:46:11 by ljiriste #+# #+# */ -/* Updated: 2023/09/05 11:46:44 by ljiriste ### ########.fr */ +/* Updated: 2023/09/08 12:09:56 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -73,10 +73,12 @@ char *ft_itoa_base(intmax_t n, const char *base) return (res); if (n < 0) res[0] = '-'; - res[size--] = '\0'; + res[--size] = '\0'; + if (n == 0) + res[0] = base[0]; while (n != 0) { - res[size--] = base[abs_max(n % base_len)]; + res[--size] = base[abs_max(n % base_len)]; n /= base_len; } return (res);