treedrawing: fix bug where rare circumstances could lead to incorrect indent

The problem took me a while to find, but the issue here was that push_buf does
not add a terminating null byte, and I was only asking push_buf to copy the
bytes that contained characters, not the terminating null byte as well.

This, combined with the fact that to remove bytes from the end of the buffer, I
just placed a null byte a the end, caused some combinations of indentation and
dedentations to overwrite the null byte, and not place a null byte after the new
indent, which would still contain data from a previous indentation.
This commit is contained in:
Khaïs COLIN 2025-03-19 12:08:53 +01:00
parent 1486c3b124
commit 76b2b8ec7f
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
2 changed files with 8 additions and 3 deletions

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/18 15:24:50 by khais #+# #+# */ /* Created: 2025/03/18 15:24:50 by khais #+# #+# */
/* Updated: 2025/03/19 12:09:47 by khais ### ########.fr */ /* Updated: 2025/03/19 14:00:35 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -40,7 +40,7 @@ void dedent(t_buffer *leader, bool is_last)
idx = leader->length - length_to_remove; idx = leader->length - length_to_remove;
if (idx >= 0) if (idx >= 0)
{ {
leader->buffer[idx] = '\0'; ft_bzero(leader->buffer + idx, length_to_remove);
leader->length = idx; leader->length = idx;
} }
} }

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/18 12:24:25 by khais #+# #+# */ /* Created: 2025/03/18 12:24:25 by khais #+# #+# */
/* Updated: 2025/03/19 12:10:05 by khais ### ########.fr */ /* Updated: 2025/03/19 13:50:37 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,6 +21,11 @@
# define VERTICAL " │ " # define VERTICAL " │ "
# define SPACE " " # define SPACE " "
/* # define CROSS " |- " */
/* # define CORNER " \\- " */
/* # define VERTICAL " | " */
/* # define SPACE " " */
void indent(t_buffer *indent, bool is_last); void indent(t_buffer *indent, bool is_last);
void dedent(t_buffer *indent, bool is_last); void dedent(t_buffer *indent, bool is_last);