2012-11-28 2 views
0

나는 또 다른 세그 폴트로 돌아왔다. 나는 정복 할 수없는 것처럼 보였다.생산자/소비자 모델의 SegFault

정확히 무엇인지 알아 냈습니다. char * 문자열 줄이있는 것입니다. 나는이 파일을 사용하여 학교 과제물을 얻기 위해 바이트를 분해합니다.

모든 도움을 주실 수 있습니다!

void* consumer(void *temp) 
{ 
int* stuff = reinterpret_cast<int*>(temp); 
int x = *stuff; 
char* string[]; 
stringstream stream1; 
stringstream stream2; 
int temp1=0; 
int temp2=0; 
int sent1=0; 
int sent2=0; 
ofstream fout; 

strcpy(string,request); //SEGFAULT(11) ON THIS LINE, WHEN CALLING "string" 
strcat(string,"Byte Range: "); 
... 

전체 코드는 여기에서 찾을 수 있습니다. https://www.dropbox.com/sh/dt90ot3z4v5nruy/1H9a5Cyb5A mgetweb.h 및 mgetweb.cpp

답변

1

아직 문자열 포인터에 대해 new 메모리가 없으므로 액세스 할 때 정의되지 않은 동작입니다.

// char* string[]; I guess that's not what you intent to do, declaring an array of pointers? 

char* string = new char[BIG_ENOUGH_SIZE]; 
strcpy(string, request); 
+0

항상 멍청합니다. 감사 –