Skip to content

Instantly share code, notes, and snippets.

@DanBUK
Created October 31, 2012 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanBUK/3988945 to your computer and use it in GitHub Desktop.
Save DanBUK/3988945 to your computer and use it in GitHub Desktop.
i don't know what I hate segfaults
typedef struct {
int size;
short *digits;
} IntArray;
typedef struct {
int size;
IntArray **arrays;
} IntArrayOfArray;
/* pretend an IntArray of size:5 digits[1,2,3,4,5], piecePer:3 */
IntArrayOfArray * functionminified (IntArray *input, int piecePer) {
IntArrayOfArray *rtv = (IntArrayOfArray *) malloc(sizeof(IntArrayOfArray));
rtv->size = floor(input->size / piecePer);
rtv->arrays = (IntArray *) malloc(rtv->size * sizeof(IntArray));
rtv->arrays[0]->size = 0; // segfaults
// ..
// ..
return rtv;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment