42shpimanmls / 42sh

Shell project at 42
3 stars 0 forks source link

simple tilde expansion (+ move add_quotes to utils) #169

Closed lsimonne closed 7 years ago

lsimonne commented 7 years ago
[ChezLouise@ ~/Documents/42/42sh]$ echo ~
  executing builtin echo
/Users/ChezLouise
  done executing builtin echo, ok
[ChezLouise@ ~/Documents/42/42sh]$ echo ~/test
  executing builtin echo
/Users/ChezLouise/test
  done executing builtin echo, ok
[ChezLouise@ ~/Documents/42/42sh]$ echo "~"
  executing builtin echo
~
  done executing builtin echo, ok
[ChezLouise@ ~/Documents/42/42sh]$ echo '~'
  executing builtin echo
~
  done executing builtin echo, ok
[ChezLouise@ ~/Documents/42/42sh]$ echo \~
  executing builtin echo
~
  done executing builtin echo, ok
[ChezLouise@ ~/Documents/42/42sh]$ echo ~toto
  executing builtin echo
~toto
  done executing builtin echo, ok
[ChezLouise@ ~/Documents/42/42sh]$ echo ~\/test
  executing builtin echo
~/test
  done executing builtin echo, ok
[ChezLouise@ ~/Documents/42/42sh]$ unsetenv HOME
  executing builtin unsetenv
  done executing builtin unsetenv, ok
[ChezLouise@ ~/Users/ChezLouise/Documents/42/42sh]$ echo ~
  executing builtin echo
~
  done executing builtin echo, ok

(the last one is an unspecified behavior, I can print a "HOME not set" error message instead, as you wish!)

M5oul commented 7 years ago
echo \~
==19492== Invalid read of size 1
==19492==    at 0x40BE8B: field_splitting (field_splitting.c:62)
==19492==    by 0x40BDE8: expand_cmd_word (expansion.c:64)
==19492==    by 0x40BCF8: expand_cmd_words (expansion.c:90)
==19492==    by 0x406021: execute_simple_command (execute_pipeline.c:60)
==19492==    by 0x4060F1: execute_pipeline (execute_pipeline.c:91)
==19492==    by 0x407545: execute_and_or_list (execute_command_list.c:36)
==19492==    by 0x407641: execute_command_list (execute_command_list.c:77)
==19492==    by 0x40AD2E: main_loop (main.c:35)
==19492==    by 0x40AC25: main (main.c:61)
==19492==  Address 0x5888313 is 0 bytes after a block of size 3 alloc'd
==19492==    at 0x4C2DB9D: malloc (vg_replace_malloc.c:299)
==19492==    by 0x411CF5: memalloc_or_die (memalloc_or_die.c:7)
==19492==    by 0x41159D: ft_strjoin (ft_strjoin.c:25)
==19492==    by 0x411683: ft_strjoinf (ft_strjoinf.c:19)
==19492==    by 0x40B2B4: strlist_to_str (command_substitution.c:22)
==19492==    by 0x40B301: command_substition (command_substitution.c:154)
==19492==    by 0x40BDBA: expand_cmd_word (expansion.c:60)
==19492==    by 0x40BCF8: expand_cmd_words (expansion.c:90)
==19492==    by 0x406021: execute_simple_command (execute_pipeline.c:60)
==19492==    by 0x4060F1: execute_pipeline (execute_pipeline.c:91)
==19492==    by 0x407545: execute_and_or_list (execute_command_list.c:36)
==19492==    by 0x407641: execute_command_list (execute_command_list.c:77)
==19492== 

Otherwise, it seems all good.