Hi
I'm sure the solution to the problem I'm having is really simple, but I can't seem to see it. I'm using C, and have a char** which I'm trying to realloc to twice it's original size. I'm using the xrealloc function described in Libc's info page. However, after calling xrealloc(), the size of the array hasn't changed -- I know this because when stepping through with gdb and printing the values of the elements of the array (which is only 3 elements long), when accessing the 4th element I get an <Address 0x?????? out of bounds> before and after the realloc.
The really weird thing here is that the code in question worked fine all of yesterday and today until 5 minutes ago. The only thing I changed was I added a function to remove duplicates from the array, but I know that function works fine, I've tested it.
xreallox():
calling code:
where retn is the array and num_mutations is a pointer to the size of the array.
I know this seems kinda vague, but if anyone has any suggestions/questions I'd be appreciative/happy to answer.
I'm sure the solution to the problem I'm having is really simple, but I can't seem to see it. I'm using C, and have a char** which I'm trying to realloc to twice it's original size. I'm using the xrealloc function described in Libc's info page. However, after calling xrealloc(), the size of the array hasn't changed -- I know this because when stepping through with gdb and printing the values of the elements of the array (which is only 3 elements long), when accessing the 4th element I get an <Address 0x?????? out of bounds> before and after the realloc.
The really weird thing here is that the code in question worked fine all of yesterday and today until 5 minutes ago. The only thing I changed was I added a function to remove duplicates from the array, but I know that function works fine, I've tested it.
xreallox():
Code:
void *
xrealloc (void *ptr, size_t size) {
register void *value = realloc(ptr, size);
if (value == 0)
abort(); /*fatal("virtual memory exhausted");*/
return value;
}
Code:
retn = (char **)xrealloc(retn, 2 * *num_mutations * sizeof(char *));
I know this seems kinda vague, but if anyone has any suggestions/questions I'd be appreciative/happy to answer.
Comment