I have a problem with my function.
char *readFnName(char *fnString, int n, int offset, int *size) {
char *fnName;
int nameBuffer, i, j;
i = offset;
j = 0;
nameBuffer = 8;
fnName = (char *)malloc(nameBuffer);
while(*(fnString + i) != '(' && i<n) {
*(fnName + j++) = *(fnString + i++);
if (j>=nameBuffer) {
nameBuffer += 8;
fnName = (char *)realloc(fnName, nameBuffer);
}
}
*(fnName + j++) = '\0';
*size = j;
return fnName;
}
I add this function a string, and this is read it well, but i run this function in a loop, and in the 3rd iteration this line crushed:
fnName = (char *)malloc(nameBuffer);
I get a message in netbeans debugger:
malloc(): memory corruption: 0x08a62218
I use netbeans and lubuntu.