0

I'm trying to implement the ringbuffer from this post https://stackoverflow.com/a/827749 and the only code I've added is a main that looks like this.

int main(int argc, char** argv) {
    circular_buffer *my_buff;
    cb_init(my_buff, 16, sizeof(char));

    return (EXIT_SUCCESS);
}

I get a SIGSEV (Segmentation fault) error as soon as I try to run this code though. By the looks of it it happens on the first row in cb_init() where malloc() is called.

Community
  • 1
  • 1
evading
  • 3,032
  • 6
  • 37
  • 57

1 Answers1

3

You need to allocate memory for my_buff

At the moment you're passing an uninitialised pointer into cb_init which is then dereferenced.

But I'm sure you must have realised this because I'm sure you will have tried running the code in a debugger...

Nick
  • 25,026
  • 7
  • 51
  • 83
  • I did try to run it in the Netbeans debugger but I don't really know what to make of all the info. But I totally see what you mean, and it's so obvious when you say it. Thanks! – evading Apr 27 '12 at 13:57