When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
12 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
And i don't know why i need to use lines[count].str instead of lines[count]->str
You have not given str any pointer value.
!asan
@peak sedge
Memory errors in C and C++ are easy to make and they can be very hard to debug because they can manifest far from their source. Address sanitizer is a runtime checker that identifies memory errors at their source and makes debugging much simpler. Address sanitizer is available for gcc/clang on linux and msvc on windows. To use it simply pass -fsanitize=address to the compiler.
Note: Make sure to turn on debug symbols with
-gfor gcc/clang and-Zifor msvc.
The first few lines tell you the problem, heap-use-after-free, due to performing a READ of size 4, at example.c line 7 (from the first line of the stack trace).
==1==ERROR: AddressSanitizer: heap-use-after-free on address ....
READ of size 4 at 0x602000000010 thread T0
#0 0x40120f in main /app/example.c:7
#1 0x7fda58629d8f (...)
#2 0x7fda58629e3f in __libc_start_main (...)
#3 0x4010b4 in _start (...)
Additional information is also included such as where the allocation was performed and where the allocation was freed.
-> is used to access a member of an object pointed to by a pointer; p->m is the same as (*p).m.
Ok, now is "working", i don't get a segfault, but now i have other problem
while (sup != NULL) {
lines[count].str = (char *)malloc(sizeof(char) * sup->value->len);
memcpy(lines[count].str, sup->value->str, sup->value->len);
count += 1;
sup = sup->next;
}
i'm just looping and printing the values
for (int i; i < lista->len; i++)
printf("%s\n", lines[i].str);
Try debugging.