+ 6

Could you tell how to fix the problem with segmentation fault core damped?

When we run this code in gcc cygwin, up to 2 nodes this program works fine, but when we define 3rd node the gcc compiler show : segmentation fault core damped (I gues this code does not work on sololearn, so it is better to test in desktop or in laptop): https://code.sololearn.com/c7Gn4AAu085q/#c

7th Sep 2019, 10:34 AM
Zhenis Otarbay
Zhenis Otarbay - avatar
18 odpowiedzi
+ 9
I found it in your tree nodes when you allocate memory you set just key and value there is left and right pointers must be set to null use calloc instead of malloc to initilize the memory to zero (and NULL) or set it manually like tmp->left->left=tmp-left-right=NULL; I just changed malloc to calloc in your code and it is done
7th Sep 2019, 12:23 PM
ABADA S
ABADA S - avatar
+ 7
tru to use debugger to see where is the bug at runtime or show me the code
7th Sep 2019, 10:38 AM
ABADA S
ABADA S - avatar
7th Sep 2019, 12:27 PM
ABADA S
ABADA S - avatar
+ 5
That happens when you access memory that is not yours. For example you use a pointer after freeing, you dereference an invalid pointer, you read past array bounds, that sort of thing. Really hard to tell without looking at the code.
7th Sep 2019, 10:37 AM
Schindlabua
Schindlabua - avatar
+ 5
install codeblocks , it is good and helpful also it is easy to install
7th Sep 2019, 10:43 AM
ABADA S
ABADA S - avatar
+ 5
yes it needs but all of that comes together in one package
7th Sep 2019, 10:52 AM
ABADA S
ABADA S - avatar
7th Sep 2019, 11:07 AM
ABADA S
ABADA S - avatar
+ 5
you're welcome 🤩
7th Sep 2019, 12:30 PM
ABADA S
ABADA S - avatar
+ 4
Schindlabua now please see the attached link of the code
7th Sep 2019, 10:40 AM
Zhenis Otarbay
Zhenis Otarbay - avatar
+ 4
ABADA S would you help to install an ide with debugger that can be installed on e disk that is not the main disk c
7th Sep 2019, 10:40 AM
Zhenis Otarbay
Zhenis Otarbay - avatar
+ 4
ABADA S does it need mingw? or gcc or something like this?
7th Sep 2019, 10:51 AM
Zhenis Otarbay
Zhenis Otarbay - avatar
+ 4
ABADA S how much memory does it need and can it be installed in e disk which is not the operational system disk?
7th Sep 2019, 10:54 AM
Zhenis Otarbay
Zhenis Otarbay - avatar
+ 4
ABADA S would you send a link of the code blocks that you are using?)
7th Sep 2019, 11:03 AM
Zhenis Otarbay
Zhenis Otarbay - avatar
+ 4
ABADA S thanks, bro!)
7th Sep 2019, 12:28 PM
Zhenis Otarbay
Zhenis Otarbay - avatar
+ 3
ABADA S would you send your modification please?)
7th Sep 2019, 12:24 PM
Zhenis Otarbay
Zhenis Otarbay - avatar
+ 3
ABADA S By the way therealso trouble in contains_key, it returns 0 ifit contains key and also there is similar trouble with get_value
7th Sep 2019, 12:48 PM
Zhenis Otarbay
Zhenis Otarbay - avatar
+ 3
Examine the core file with gdb using your binary as reference. I can't do it either. On the train myself 😉.
9th Sep 2019, 5:59 AM
Sonic
Sonic - avatar
+ 2
I'm on a train at the moment so I can't check with gcc and gdb, I'm sorry :/ Maybe someone else can step in..
7th Sep 2019, 10:41 AM
Schindlabua
Schindlabua - avatar