D
Deephay
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
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