dlaurent42/42sh

[bug] segfault starting shell

Closed this issue · 1 comments

./shell
Screen clears but before the welcome message is printed, there is a segfault

[1]    31900 segmentation fault  ./shell

Only happens every few times. I could not recreate with valgrind - even when turning off the clear screen. I'll try further today to locate it.

==26767== Invalid write of size 1
==26767==    at 0x100026C5D: ft_strcat (ft_strcat.c:26)
==26767==    by 0x10001A253: sh_get_git_branch_name (set_prompt.git.c:21)
==26767==    by 0x10001A1DC: sh_get_git_branch (set_prompt.git.c:82)
==26767==    by 0x100019C61: sh_set_prompt (set_prompt.c:62)
==26767==    by 0x100019B0B: sh_new (new.c:41)
==26767==    by 0x1000010AA: main (shell.c:22)
==26767==  Address 0x101bc5c5d is 0 bytes after a block of size 45 alloc'd
==26767==    at 0x1000F1A46: malloc (in /Users/dhojt/.brew/Cellar/valgrind/3.13.0/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==26767==    by 0x100027BA0: ft_strnew (ft_strnew.c:20)
==26767==    by 0x100027208: ft_strdups (ft_strdups.c:21)
==26767==    by 0x100019DDB: sh_set_prompt_location (set_prompt.c:41)
==26767==    by 0x100019C51: sh_set_prompt (set_prompt.c:61)
==26767==    by 0x100019B0B: sh_new (new.c:41)
==26767==    by 0x1000010AA: main (shell.c:22)
==26767==
==26767== Invalid write of size 1
==26767==    at 0x100026C7D: ft_strcat (ft_strcat.c:29)
==26767==    by 0x10001A253: sh_get_git_branch_name (set_prompt.git.c:21)
==26767==    by 0x10001A1DC: sh_get_git_branch (set_prompt.git.c:82)
==26767==    by 0x100019C61: sh_set_prompt (set_prompt.c:62)
==26767==    by 0x100019B0B: sh_new (new.c:41)
==26767==    by 0x1000010AA: main (shell.c:22)
==26767==  Address 0x101bc5c66 is 9 bytes after a block of size 45 alloc'd
==26767==    at 0x1000F1A46: malloc (in /Users/dhojt/.brew/Cellar/valgrind/3.13.0/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==26767==    by 0x100027BA0: ft_strnew (ft_strnew.c:20)
==26767==    by 0x100027208: ft_strdups (ft_strdups.c:21)
==26767==    by 0x100019DDB: sh_set_prompt_location (set_prompt.c:41)
==26767==    by 0x100019C51: sh_set_prompt (set_prompt.c:61)
==26767==    by 0x100019B0B: sh_new (new.c:41)
==26767==    by 0x1000010AA: main (shell.c:22)
==26767==
==26767== Syscall param open(filename) points to unaddressable byte(s)
==26767==    at 0x10044BA3E: open (in /usr/lib/system/libsystem_kernel.dylib)
==26767==    by 0x10001A27B: sh_get_git_branch_name (set_prompt.git.c:23)
==26767==    by 0x10001A1DC: sh_get_git_branch (set_prompt.git.c:82)
==26767==    by 0x100019C61: sh_set_prompt (set_prompt.c:62)
==26767==    by 0x100019B0B: sh_new (new.c:41)
==26767==    by 0x1000010AA: main (shell.c:22)
==26767==  Address 0x101bc5c5d is 0 bytes after a block of size 45 alloc'd
==26767==    at 0x1000F1A46: malloc (in /Users/dhojt/.brew/Cellar/valgrind/3.13.0/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==26767==    by 0x100027BA0: ft_strnew (ft_strnew.c:20)
==26767==    by 0x100027208: ft_strdups (ft_strdups.c:21)
==26767==    by 0x100019DDB: sh_set_prompt_location (set_prompt.c:41)
==26767==    by 0x100019C51: sh_set_prompt (set_prompt.c:61)
==26767==    by 0x100019B0B: sh_new (new.c:41)
==26767==    by 0x1000010AA: main (shell.c:22)
==26767==
==26767== Invalid read of size 1
==26767==    at 0x100027735: ft_strlens (ft_strlens.c:22)
==26767==    by 0x1000271FC: ft_strdups (ft_strdups.c:21)
==26767==    by 0x100019D6B: sh_set_prompt_location (set_prompt.c:37)
==26767==    by 0x100019D3E: sh_set_prompt (set_prompt.c:70)
==26767==    by 0x100019B0B: sh_new (new.c:41)
==26767==    by 0x1000010AA: main (shell.c:22)
==26767==  Address 0x101bc5c5d is 0 bytes after a block of size 45 alloc'd
==26767==    at 0x1000F1A46: malloc (in /Users/dhojt/.brew/Cellar/valgrind/3.13.0/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==26767==    by 0x100027BA0: ft_strnew (ft_strnew.c:20)
==26767==    by 0x100027208: ft_strdups (ft_strdups.c:21)
==26767==    by 0x100019DDB: sh_set_prompt_location (set_prompt.c:41)
==26767==    by 0x100019C51: sh_set_prompt (set_prompt.c:61)
==26767==    by 0x100019B0B: sh_new (new.c:41)
==26767==    by 0x1000010AA: main (shell.c:22)
==26767==
==26767== Invalid read of size 1
==26767==    at 0x100027054: ft_strcpy (ft_strcpy.c:22)
==26767==    by 0x100027230: ft_strdups (ft_strdups.c:23)
==26767==    by 0x100019D6B: sh_set_prompt_location (set_prompt.c:37)
==26767==    by 0x100019D3E: sh_set_prompt (set_prompt.c:70)
==26767==    by 0x100019B0B: sh_new (new.c:41)
==26767==    by 0x1000010AA: main (shell.c:22)
==26767==  Address 0x101bc5c5d is 0 bytes after a block of size 45 alloc'd
==26767==    at 0x1000F1A46: malloc (in /Users/dhojt/.brew/Cellar/valgrind/3.13.0/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==26767==    by 0x100027BA0: ft_strnew (ft_strnew.c:20)
==26767==    by 0x100027208: ft_strdups (ft_strdups.c:21)
==26767==    by 0x100019DDB: sh_set_prompt_location (set_prompt.c:41)
==26767==    by 0x100019C51: sh_set_prompt (set_prompt.c:61)
==26767==    by 0x100019B0B: sh_new (new.c:41)
==26767==    by 0x1000010AA: main (shell.c:22)
==26767==
==26767== Invalid read of size 1
==26767==    at 0x100027066: ft_strcpy (ft_strcpy.c:24)
==26767==    by 0x100027230: ft_strdups (ft_strdups.c:23)
==26767==    by 0x100019D6B: sh_set_prompt_location (set_prompt.c:37)
==26767==    by 0x100019D3E: sh_set_prompt (set_prompt.c:70)
==26767==    by 0x100019B0B: sh_new (new.c:41)
==26767==    by 0x1000010AA: main (shell.c:22)
==26767==  Address 0x101bc5c5d is 0 bytes after a block of size 45 alloc'd
==26767==    at 0x1000F1A46: malloc (in /Users/dhojt/.brew/Cellar/valgrind/3.13.0/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==26767==    by 0x100027BA0: ft_strnew (ft_strnew.c:20)
==26767==    by 0x100027208: ft_strdups (ft_strdups.c:21)
==26767==    by 0x100019DDB: sh_set_prompt_location (set_prompt.c:41)
==26767==    by 0x100019C51: sh_set_prompt (set_prompt.c:61)
==26767==    by 0x100019B0B: sh_new (new.c:41)
==26767==    by 0x1000010AA: main (shell.c:22)
==26767==