A
Andrew Clark
Hi all,
Wow, has it been a long time since I've been here. Too long.
Anyway, I thing I have found the source of a segfault in my program, but
I can't see anything wrong with this code (used to "push" a value on to
the end of an array):
int push (int **arr, int x)
{
int rc, *p;
static int count = 1 + 1;
*arr = realloc (*arr, sizeof x * count); /* segfault here */
p = *arr;
rc = (p ? 1 : 0);
count = (p ? count + 1 : 1);
if (p)
{
p [count - 2] = x;
p [count - 1] = 0;
}
return rc;
}
Can you?
Wow, has it been a long time since I've been here. Too long.
Anyway, I thing I have found the source of a segfault in my program, but
I can't see anything wrong with this code (used to "push" a value on to
the end of an array):
int push (int **arr, int x)
{
int rc, *p;
static int count = 1 + 1;
*arr = realloc (*arr, sizeof x * count); /* segfault here */
p = *arr;
rc = (p ? 1 : 0);
count = (p ? count + 1 : 1);
if (p)
{
p [count - 2] = x;
p [count - 1] = 0;
}
return rc;
}
Can you?