Skip to content
← Back to Community
Segmentation Faults and Bus Errors
Profile icon
xxpertHacker

I was casting pointers to integers, and I'm pretty sure that I immediately go "out-of-bounds" when accessing the heap, yet I'm not sure how or why.

Maybe I'm hitting a null pointer?

Does anyone think that they could help me out?

When reading byte by byte, my compare function seems to access one extra index, yet it shouldn't.


An example of the old error is shown on line 26 of main.cpp, it no longer errors, but instead just produces incorrect results.

Voters
Profile icon
xxpertHacker
Comments
hotnewtop
Profile icon
DynamicSquid

your code's too long sorry xD, what's the line in question?

Profile icon
xxpertHacker

@DynamicSquid
Originally, it was actually super short, but it had segfaults everywhere, so I lengthened it to debug it, then it worked, but incorrectly, now I'm shortening it back down and fixing it. compare is the function that is causing the segfault, but I'm also rapidly rewriting everything here.

It's when I cast and dereference.

Around line ~30.

Profile icon
xxpertHacker

@DynamicSquid
Oh shoot, I think I just got it working properly, neat. I'ma check it carefully before walking away though.

Profile icon
DynamicSquid

@xxpertHacker
oh cool! if it does work properly, tell me what you did to fix it

Profile icon
xxpertHacker

@DynamicSquid
If I'm being 100% honest, I just typed stuff and it worked, no clue what I do most of the time, kinda mindless.

Profile icon
DynamicSquid
Profile icon
xxpertHacker

@DynamicSquid
Oh, I tried putting it to use today, but it was giving incorrect results, and since you're among the best known C++ programmers here at Repl, do think you can take an extra look at it?

Profile icon
DynamicSquid

@xxpertHacker
I took another look at it, what are you trying to do here with the strcmp function?

Profile icon
xxpertHacker

@DynamicSquid
strcmp is a specialized wrapper for compare, where compare just compares sequences of bytes, I was going to fix the last bit of strcmp, it's calculating the count incorrectly, but I still believe that compare is incorrect.

strcmp = string compare.

I'm renaming it to streq instead now.