세그멘테이션 폴트인데 ...

facered79의 이미지

일단 오류가 발생하는 위치는 아래의 함수입니다.

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 란 거만 나오는듯 하고요.

어떻게 해결 해야 할까요.. 조언 기다리겠습니다..

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.