From 74f013e5c6cb8cf9811e57ce85bda431926cb9df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Wed, 2 Apr 2025 14:15:30 +0200 Subject: [PATCH] fix: do not read ahead in STDIN MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Open Group Base Specifications Issue 8 IEEE Std 1003.1-2024 sh — shell, the standard command language interpreter says: > When the shell is using standard input and it invokes a command that also uses > standard input, the shell shall ensure that the standard input file pointer > points directly after the command it has read when the command begins > execution. It shall not read ahead in such a manner that any characters > intended to be read by the invoked command are consumed by the shell (whether > interpreted by the shell or not) or that characters that are not read by the > invoked command are not seen by the shell. We used the default BUFFER_SIZE for get_next_line of 1024, which caused us to read ahead farther than was allowed by the Open Group Base Specification. Setting BUFFER_SIZE=1 ensures that we don't read too far ahead, since get_next_line will always immediatly stop once a newline is found. This is for me the simplest way to solve this issue. --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 36d2a9e..b91baec 100644 --- a/Makefile +++ b/Makefile @@ -100,6 +100,7 @@ all: $(NAME) $(NAME): $(minishell_objs) $(LIBFT) $(CC) $(CFLAGS) -o $@ $(minishell_objs) $(LINCLUDE) $(LDLIBS) +$(LIBFT): CFLAGS+=-DBUFFER_SIZE=1 $(LIBFT): +$(MAKE) -C $(LIBFTDIR)