세그멘테이션 폴트인데 ...
글쓴이: facered79 / 작성시간: 화, 2005/06/28 - 4:13오후
일단 오류가 발생하는 위치는 아래의 함수입니다.
void streamFile(const char *filename,char* spec_trap) { xmlTextReaderPtr reader; int ret; const xmlChar *name, *attribute="key" ,*value; char *sensor_type, *event_type, *offset, *grade="grade"; char *sep=NULL; char sep_trap[2]; int node_t; xml_count=0; /* * Pass some special parsing options to activate DTD attribute defaulting, * entities substitution and DTD validation */ sprintf(sep_trap,"%c%c",spec_trap[0],spec_trap[1]); sensor_type = strdup(sep_trap); printf("sensor_type is %s\n",sensor_type); sprintf(sep_trap,"%c%c",spec_trap[2],spec_trap[3]); event_type = strdup(sep_trap); printf("event_type is %s\n",event_type); sprintf(sep_trap,"%c%c",spec_trap[4],spec_trap[5]); offset = strdup(sep_trap); printf("offset_type is %s\n",offset); reader = xmlReaderForFile(filename, NULL, XML_PARSE_DTDATTR | /* default DTD attributes */ XML_PARSE_NOENT | /* substitute entities */ XML_PARSE_DTDVALID); /* validate with the DTD */ if (reader != NULL) { ret = xmlTextReaderRead(reader); while (ret == 1 && xml_count!=4) { printf("xml_count is %d\n",xml_count); //processNode(reader); //name = xmlTextReaderConstName(reader); name = xmlTextReaderConstName(reader); if (name == NULL) name = BAD_CAST "--"; sep=xmlTextReaderGetAttribute(reader,attribute); value = xmlTextReaderConstValue(reader); node_t = xmlTextReaderNodeType(reader); if(sep!=NULL){ if(xml_count==0 && strcmp(sep,sensor_type)==0) { xml_count++; printf("sensor_type is %s\n",sep); } else if(xml_count==1 && strcmp(sep,event_type)==0) { xml_count++; printf("event_type is %s\n",sep); } else if(xml_count==2 && strcmp(sep,offset)==0 && node_t==1){ xml_count++; printf("offset is %s\n",sep); printf("grade is %s \n",xmlTextReaderGetAttribute(reader,grade)); } else ; } if(xml_count==3 && node_t==3) { if (value == NULL) printf("\n"); else { if (xmlStrlen(value) > 40) printf(" %.40s...\n", value); else printf(" %s\n", value); } xml_count++; } ret = xmlTextReaderRead(reader); } } [b]// printf("key is %s %d \n",xmlTextReaderGetAttribute(reader,attribute),xmlTextReaderNodeType(reader));[/b] }
윗 코드의 마지막 부분의 프린트 문까지 실행이 됩니다.
key 값은 NULL 이고요..
아무튼 겉으로 보기에 마지막 프린트 문까지 실행이 된걸로 봐서는 함수 전체가 문제 없이 실행이 되는것 같은데..
함수를 호출하는 부분 이후 문장에 프린트 문의로 테스트를 찍어봐도 프린트문이 찍히질 않네요..
세그맨테이션 폴트는 아마도 함수에서 나오는 부분에서 발생하는듯 합니다..
gdb 를 사용해 봤는데..
syssegv 란 거만 나오는듯 하고요.
어떻게 해결 해야 할까요.. 조언 기다리겠습니다..
Forums:
댓글 달기