realloc(): invalid next size
- From: Deephay <tudoxxx@xxxxxxxxx>
- Date: Tue, 11 Apr 2006 19:43:58 +0800
Greetings all,
I have a program that used the realloc() function to change the
allocated size of a buffer, the program works with some arguments, but
with some other arguments, it will show me the error message like:
*** glibc detected *** realloc(): invalid next size: 0x0804c3a8 ***
and then I inserted a perror("realloc") to see what happend, it says that:
realloc: Illegal seek
the realloc() is in a loop:
for (m = 0; m < len; m++) {
if (isspace(data[m]) || ispunct(data[m]) ||
isdigit(data[m]))
printf("%c", data[m]);
else {
p = min(strcspn(&data[m], " "),
strcspn(&data[m], "\t"),
strcspn(&data[m], "\r"),
strcspn(&data[m], "\n"));
key = realloc(key, p);
strncpy(key, &data[m], p);
key[p] = '\0';
trans(key, p);
m = m + p - 1;
}
}
and the "key" is already malloced before the loop:
char *key = malloc(1);
Any suggestion could be helpful, thx very much!
Deephay
.
- Follow-Ups:
- Re: realloc(): invalid next size
- From: Michael Wojcik
- Re: realloc(): invalid next size
- From: Richard Bos
- Re: realloc(): invalid next size
- Prev by Date: Re: HP-UX 11.23 Assertion failed: __thread_init == NULL
- Next by Date: Re: Can I integrate .EXE files into a new C program?
- Previous by thread: Problem Taking input:(
- Next by thread: Re: realloc(): invalid next size
- Index(es):
Relevant Pages
|