Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

Void Pointer malloc (AddressSanitizer error)

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
I would get a debugger and find why and where you are getting a address of 0x00000001.
found the error thanks anyways ;))
(Jun 5, 2017 06:23 AM)Left Boy Wrote:  found the error thanks anyways ;))

So what was the problem?
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.
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Release] by arsiumJun 4, 2026 02:17 AM 16 518 Jun 4, 2026 02:17 AM
Last Post: arsium
[C] by Equivalent_Jaguar198Jun 13, 2022 02:20 PM 4 182 Jun 13, 2022 02:20 PM
Last Post: Equivalent_Jaguar198
[C] by xx1ben99xxApr 30, 2020 09:05 PM 22 546 Apr 30, 2020 09:05 PM
Last Post: 0xDEAD10CC