diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-25 20:42:41 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-25 20:42:41 +0200 |
commit | 638d89cbc030f5d187bf29ff2f3c135b3f3bfeca (patch) | |
tree | d7de1ae88e2cd68560a19dae00856841629b77c7 /src/ft_s_lcom.c | |
parent | k (diff) | |
download | 42-minishell-638d89cbc030f5d187bf29ff2f3c135b3f3bfeca.tar.gz 42-minishell-638d89cbc030f5d187bf29ff2f3c135b3f3bfeca.tar.bz2 42-minishell-638d89cbc030f5d187bf29ff2f3c135b3f3bfeca.tar.xz 42-minishell-638d89cbc030f5d187bf29ff2f3c135b3f3bfeca.tar.zst 42-minishell-638d89cbc030f5d187bf29ff2f3c135b3f3bfeca.zip |
Fixed segv on spaces only
Diffstat (limited to 'src/ft_s_lcom.c')
-rw-r--r-- | src/ft_s_lcom.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/ft_s_lcom.c b/src/ft_s_lcom.c index 33ad5da..03b2f67 100644 --- a/src/ft_s_lcom.c +++ b/src/ft_s_lcom.c @@ -27,10 +27,15 @@ static int8_t uint64_t j; i = 0; - if (!((*lcom)->com = (char*)malloc((ft_strlen(words[0]) + 1) * - sizeof(char)))) - return (-1); - ft_strlcpy((*lcom)->com, words[0], ft_strlen(words[0]) + 1); + if (words[0]) + { + if (!((*lcom)->com = (char*)malloc((ft_strlen(words[0]) + 1) * + sizeof(char)))) + return (-1); + ft_strlcpy((*lcom)->com, words[0], ft_strlen(words[0]) + 1); + } + else + return (0); while(words[i]) { /* TODO: cut fd number "msh ~> echo a 2>file" */ |