#Struggling with seg fault

44 messages · Page 1 of 1 (latest)

proper stumpBOT
#

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 more information use !howto ask.

austere haven
#

buf in your case is a pointer to 1 byte of memory (sizeof(char) is guaranteed to be always 1).
If SIZE is any bigger than 1 the code might SEGFAULT.

wind idol
#

I really am just confused what I need to set buf to

#

and now I’m confused

austere haven
#

both char buf[SIZE] and char *buf = malloc(SIZE) work

wind idol
#

like initially yea its NULL, but why is it saying invalid read? if its accessing a NULL ptr shouldn;t it return NULL

austere haven
#

Also what is arr?
Also you're not ensuring that arr[strlen(buf) - 5] doesn't access a negative index

austere haven
#

Same question again

#

Go through the code imagining the parameters are NULL

wind idol
# austere haven Same question again

that’s why I tried creating a temp node with dummy attributes when I create my linkedlist and making that the head so that the linked list isn’t null when it gets created

#

no difference

#

so like if we assume it’s not null when it gets created, even if I have the checks for null

#

LL start shouldn’t be null right? Can the invalid read/write come from anywhere else or is it most likely because the linked list is null

austere haven
#

Share the full error message please

wind idol
#

is it ok if i send it in like an hour ish? I just left the house

austere haven
#

Just send it when you can. The error shouldn't change over the next hour

austere haven
#

Could you just send the whole code? You're feeding me snippets the entire time and I really don't feel like pulling everything out of your nose

#

Like everything that is relevant in order for the error to occur.

#

If the error is in insert then why do you send me only create_linked_list?

wind idol
#

sporry i thought it would be easier for u to reference the insert func when i sent it earlier

#

is it ok if i send the code in a private dm?

austere haven
#

no

wind idol
#

ok

rotund mistBOT
#
int *arr[27];

Declare arr as array[27] of pointers to int

wind idol
#

do you have an idea of where the invalid read is coming from?

austere haven
#

line 40

#

You're somehow passing NULL to insert

#

but tbh, I have no real clue. Why don't you just debug it to see how you're trying to access NULL?

wind idol
#

like print stuff? or another way

austere haven
#

gdb

#

debugger

#

You must've debugged before

#

It's essential to programming in any language

wind idol
#

i pretty much only use valgrind and printing stuff to debug

#

heard of gdb just never used it

austere haven
#

get familiar with it

#

Nowadays I spent almost half of my time programming in the debugger

#

Only debugger that sucked so far was Haskell's

#

because of lazy evaluation

#

But C's is kind of nice once you got used to it

wind idol
#

ok will do

#

thx

proper stumpBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.