Hack Forums
[C] Void Pointer malloc (AddressSanitizer error) - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C] Void Pointer malloc (AddressSanitizer error) (/showthread.php?tid=5639675)



Void Pointer malloc (AddressSanitizer error) - Left Boy - Jun 5, 2017

Hey,
i currently trying to build a stack using a linked list (in C) but struggeling to implement the push operation



LI* t = malloc(sizeof(LI));
t->data = data;
t->next = s->head;
s->head = t;
[/code]

im getting the following error, can somebody help me?
Code
FAIL: AddressSanitizer error
src/list.c:169:23: runtime error: member access within misaligned address 0x00000001 for type 'struct LI', which requires 4 byte alignment



* - g4143 - Jun 5, 2017

I would get a debugger and find why and where you are getting a address of 0x00000001.


* - Left Boy - Jun 5, 2017

found the error thanks anyways ;))


* - g4143 - Jun 5, 2017

(Jun 5, 2017 06:23 AM)Left Boy Wrote:  found the error thanks anyways ;))

So what was the problem?


* - 0xDEAD10CC - Jun 5, 2017

Code
LI* t = malloc(sizeof(LI));
t->data = data;
t->next = s->head;
s->head = t;

^ You're trying to go backwards. The new node's next pointer shouldn't be anything if you're adding to the end of the linked list. 'head' usually indicates the first node too, not the top node, which is semantically incorrect.

Btw, next time post more of your code.