From 56eead92419a902b8ac6f4ac5c16a1289cf6295a Mon Sep 17 00:00:00 2001 From: Camille Chauvet Date: Wed, 15 Feb 2023 21:31:49 +0100 Subject: [PATCH] fix: empty input segfault --- .infile.c.swp | Bin 12288 -> 0 bytes .heredoc.c.swp => .syntatics.c.swp | Bin 12288 -> 12288 bytes cmds.c | 4 +- infile.c | 4 +- outfile.c | 4 +- syntatics.c | 68 +++++++++++++++++++++-------- t | 0 7 files changed, 57 insertions(+), 23 deletions(-) delete mode 100644 .infile.c.swp rename .heredoc.c.swp => .syntatics.c.swp (83%) delete mode 100644 t diff --git a/.infile.c.swp b/.infile.c.swp deleted file mode 100644 index c2bfbc114ea909bea81034aadb2b06bf28f8c35c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2J#5oJ6vwZK#ia#A1xT=5)1mHHQirN4tvd42sxW}sg`y~R&dnjm364#Hs+0u= zR3tVA1Op3FE7S$4FtL>ZQL%tPY)GAeg{1=n{GG(ElR6n-s(6-uy1Vz@y?6efZ7Isl z^iPeQ<3n+c;X26J($;r9x%WSA4sOH*}Q9toQNBCbo4Dh zVPYVe$Vp2Uv%)kJ(lVqe;(GKXvXTO%z`rZtI!516>*R@~*6$_jh_&;!LzDlWmokt7 zqyQ;E3XlS%04YEUkOHK@u2H}#G_ggjc28x+$0}`8O@#=`mcawC1g5}6FbtAF0~{O%ZQ$EJ#@>T9unt~;CtwcP z;0h3691MXN_|?qVPw)eL1aH6^SOqJ<1rDH#6d(mi0aAbzAO%Q)|3ZNUrr5%9ZHuc$ zrfY;LFa(x9&9f+qZsv=k;#Z`>Rd1F*({KF@HRGD0U!Y_Td_kx2Dx$-DtKa$yiMW-h zkiWMrl&^XUMkTID+rY)ukm?I86dCGPw#v8o?T$N#qpr`}@=&Sz8@wZHu=Q1*`h@~d z&}qEQ`8sit=161Zk&gEHR==&fi|BjvUy*3NA`?X#ZBfTuegmV@M^5mJ6$hHC5Iizf za=m$M6}dZneCZbtC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index 65ee907..2c39eb7 100644 --- a/cmds.c +++ b/cmds.c @@ -6,7 +6,7 @@ /* By: cchauvet ", str[i])) { - if (y > 0) + y = 0; + while (str[i] == str[i + y]) + y++; + if ((y > 2 && (str[i] == '>' || str[i] == '<')) + || (y > 1 && str[i] == '|')) { - ft_eprintf("minishell: Multiple pipes is not supported\n"); + ft_eprintf("minishell: to many %c in a row", str, str[i]); return (1); } - y++; + i = i + y; } i++; } return (0); } -static int ft_pipe_is_alone(const char *str) +int ft_empty_verif(const char *str) { size_t i; - i = ft_strlen(str) - 1; - while (str[i] != '|' && i > 0) - { - if (str[i] != ' ') - return (0); - i--; - } - if (i == 0) - return (0); - ft_eprintf("minishell: Pipe must be followed by a command or redirection\n"); - return (1); + i = 0; + while (str[i] == ' ') + i++; + if (str[i] == '\0') + ft_eprintf("minishell: %s: command not found \n", str); + return (str[i] == '\0'); } int ft_syntatic_verif(const char *str) { - return (ft_quote_verif(str) || ft_multipipe(str) || ft_pipe_is_alone(str)); + return (ft_quote_verif(str) + || ft_pipe_is_alone(str) + || ft_empty_verif(str) + || ft_special_char_dub(str)); } diff --git a/t b/t deleted file mode 100644 index e69de29..0000000