A Classic C Programming Mistake - See if You Can Spot it
size_t *sz_out;
*sz_out = input[sz_in-1] - input[0]+1;
int * output = (int *) malloc( *sz_out );
Nail it? That's right, you have to be specific in the malloc call. If you give it just a number (in this case, sz_out is a number of bytes - size of output) it'll allocate that many bytes - not what you want.
You always use malloc along with the sizeof operator to get the allocation right.
Live and learn.
Comments
Post a Comment