Comment on: Programing is not about intelligence or perfection. That works against you!
2 07 Jul 2016 22:38 u/johnP in v/programmingComment on: [Why does my code work] I have created a parser in C and if I do not allocate and immediately free an array it breaks.
Nah, it's fine. I just can't see!
Comment on: [Why does my code work] I have created a parser in C and if I do not allocate and immediately free an array it breaks.
Yeah, didn't see that 'if' there. My fault.
Comment on: [Why does my code work] I have created a parser in C and if I do not allocate and immediately free an array it breaks.
Nope. Sorry about that gentlemen, totally didn't see the 'if' there. My fault. I would still do a check to make sure your allocation routine isn't getting called with a zero.
Comment on: [Why does my code work] I have created a parser in C and if I do not allocate and immediately free an array it breaks.
Of course he's got some kind of memory corruption.
Comment on: [Why does my code work] I have created a parser in C and if I do not allocate and immediately free an array it breaks.
Dude, that stuff doesn't matter. You can't do this:
char* inputBufferSubset = allocCharBuffer(inputBufferLength);
memcpy(inputBufferSubset, &input[i-inputBufferLength], inputBufferLength);
inputBufferLength starts out at 0. You're overwriting memory you're not supposed to.
Comment on: [Why does my code work] I have created a parser in C and if I do not allocate and immediately free an array it breaks.
Doesn't matter what happens later. He's modifying memory that's not been allocated properly.
char* inputBufferSubset = allocCharBuffer(inputBufferLength);
memcpy(inputBufferSubset, &input[i-inputBufferLength], inputBufferLength);
Comment on: [Why does my code work] I have created a parser in C and if I do not allocate and immediately free an array it breaks.
Your problem is here:
char* inputBufferSubset = allocCharBuffer(inputBufferLength);
And inputBufferLength starts out at 0. Anything else that happens in the program is up for grabs because you might be overwriting some data structure used by the allocator or something.
Comment on: [Why does my code work] I have created a parser in C and if I do not allocate and immediately free an array it breaks.
It looks like inputBufferLength is starting out at zero. And then allocCharBuffer(inputBufferLength) gets called which calls malloc with a length of zero. I guess malloc returns the pointer anyway. Yep I just tested it and it does on my system too.
Here's some junk about it: https://bytes.com/topic/c/answers/578467-what-malloc-0-should-returns
Live OpenGL programming with Erlang.
6 0 comments 04 Jun 2016 23:01 u/johnP (self.programming) in v/programmingComment on: Extremely severe bug leaves dizzying number of software and devices vulnerable
It looks like if you're running debian it's already fixed so you just have to update with apt:
You misspelled the word 'fuck'.