segmentation fault
-
#define BUFFSIZE 128 #define ALLOCSTEP 512 char *read_till_token(int sock, const char *token) { char *read = NULL; char *temp = NULL; int read_maxsize; int received; char buffer[BUFFSIZE]; read = (char *)malloc(ALLOCSTEP); read_maxsize = ALLOCSTEP; read = ""; while(strstr(read, token) == NULL) //read till we receive token { if(read_maxsize - strlen(read) < BUFFSIZE) //if theres not enough space for the buff then we allocate some more and free the old { read_maxsize += ALLOCSTEP; temp = (char*)malloc(read_maxsize); strcpy(temp, read); //copy old to new free(read); read = temp; temp = NULL; } //now read and fill the buffer if((received = recv(sock, buffer, BUFFSIZE-1, 0)) < 1) { free(read); //free the mem before returning return ""; } buffer[received] = '\0'; } return read; //return the string NOTE: has to be freed }das strcat gibt mir en segmentation fault kA warum genug platz müsste ja da sein ich hab sogar buffer mitm gdb mit hallo\0 gefüllt scheint wohl an dem read zu liegen wobei ich aber doch speicher vorher alloziert habe.
Tritt beim ersten schleifendurchlauf auf also müsste read ja 512 bytes fassen können und buffer is ja null terminiert und nicht größer als 128.Hilfe wär nice^^
-
Ähm zuerst
malloc, dann das Resultat casten und dieses schliesslich verwerfen?read = (char *)malloc(ALLOCSTEP); read_maxsize = ALLOCSTEP; read = ""; // <= was soll das sein??Was soll das denn sein?

MfG
-
ty fixxed
aber wieso empfiehlst mir strtok() seh da keine verwendung für hier :o
mfg tobZel