Timeline for pset5 Speller -load - Valgrind error - "invalid read of size 8"(segmentation fault)
Current License: CC BY-SA 3.0
5 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Dec 10, 2017 at 6:36 | comment | added | Cliff B | Those two lines of code don't execute at the same time.. The correct word is "before", not "while" creating current_node. The two lines of code do the following: 1. Copy the contents of root to current_node (currently either garbage data if not initialized, or NULL - note that when a pointer is created, there is no default initialization to NULL), and then 2. allocate memory to root (which has no effect on current_node). Now, if those two lines were reversed, there's be an entirely different story here. | |
Dec 10, 2017 at 6:34 | comment | added | Cliff B |
If a pointer to a structure has not had memory allocated to it, none of the structure elements exist, so they cannot be referenced.Any attempt to reference a nonexistent element almost always results in a seg fault. For example, if mynode has been created but no malloc or calloc executed and the address stored in mynode, then two things are true. mynode can be rerferenced to check whether it is NULL or something else (including garbage data), but any attempt to reference mynode->is_end (or any other structure element) will almost certainly generate a seg fault.
|
|
Dec 10, 2017 at 6:20 | comment | added | shaistha | As you could see in my code...@Cliff B in the top...while creating current_node...I set it equal to the root... | |
Dec 10, 2017 at 6:14 | comment | added | shaistha | you are right..that's where the faults been occurring.... yes it is null...I thought...It will check if its null and then point to the new one....so I haven't initialised it ...I.e.,check if empty and theb create a node ..that was my thought | |
Dec 10, 2017 at 3:29 | history | answered | Cliff B | CC BY-SA 3.0 |