2011-02-23 12 views
5

मेरे साथ एक त्रुटि है जो getline() पर कॉल करती है, जो मानक टेक्स्ट फ़ाइल से लाइनें पढ़ती है। ये पंक्तियां \r\n में समाप्त होती हैं, क्योंकि यह वही है जिसे स्पेक कहते हैं क्योंकि यह वीसीएआर फाइलों के लिए "इंटरनेट मानक" है।गेटलाइन()

वैसे भी, मैं इस जीबी को ओल्डएसयूएसई 11.3 पर नवीनतम जीसीसी और वालग्रींड संस्करणों के साथ चलाता हूं; त्रुटियाँ नहीं। हालांकि, इस समस्या का कोई प्रासंगिकता के कारणों के लिए, मैं distros बंद वापस करने के लिए 4 ट्रैक (उबंटू आधारित), और अब मैं वेलग्रिंड त्रुटियों की एक मीट्रिक टन हो रही है:

==21536== Conditional jump or move depends on uninitialised value(s) 
==21536== at 0x40164A1: (within /lib/ld-2.11.1.so) 
==21536== by 0x4007C04: (within /lib/ld-2.11.1.so) 
==21536== by 0x4002A2C: (within /lib/ld-2.11.1.so) 
==21536== by 0x4014206: (within /lib/ld-2.11.1.so) 
==21536== by 0x4000C6C: (within /lib/ld-2.11.1.so) 
==21536== by 0x4000856: (within /lib/ld-2.11.1.so) 
==21536== 
==21536== Conditional jump or move depends on uninitialised value(s) 
==21536== at 0x40164AC: (within /lib/ld-2.11.1.so) 
==21536== by 0x4007C04: (within /lib/ld-2.11.1.so) 
==21536== by 0x4002A2C: (within /lib/ld-2.11.1.so) 
==21536== by 0x4014206: (within /lib/ld-2.11.1.so) 
==21536== by 0x4000C6C: (within /lib/ld-2.11.1.so) 
==21536== by 0x4000856: (within /lib/ld-2.11.1.so) 
--21536-- Warning: DWARF2 CFI reader: unhandled DW_OP_ opcode 0x55 
--21536-- Warning: DWARF2 CFI reader: unhandled DW_OP_ opcode 0x55 
--21536-- DWARF2 CFI reader: unhandled CFI instruction 0:10 
--21536-- DWARF2 CFI reader: unhandled CFI instruction 0:10 
--21536-- DWARF2 CFI reader: unhandled CFI instruction 0:10 
--21536-- DWARF2 CFI reader: unhandled CFI instruction 0:10 
--21536-- DWARF2 CFI reader: unhandled CFI instruction 0:10 
--21536-- DWARF2 CFI reader: unhandled CFI instruction 0:10 
--21536-- DWARF2 CFI reader: unhandled CFI instruction 0:10 
==21536== 
==21536== Conditional jump or move depends on uninitialised value(s) 
==21536== at 0x400B217: (within /lib/ld-2.11.1.so) 
==21536== by 0x40031D0: (within /lib/ld-2.11.1.so) 
==21536== by 0x4014206: (within /lib/ld-2.11.1.so) 
==21536== by 0x4000C6C: (within /lib/ld-2.11.1.so) 
==21536== by 0x4000856: (within /lib/ld-2.11.1.so) 
==21536== 
==21536== Conditional jump or move depends on uninitialised value(s) 
==21536== at 0x400AF0F: (within /lib/ld-2.11.1.so) 
==21536== by 0x40031D0: (within /lib/ld-2.11.1.so) 
==21536== by 0x4014206: (within /lib/ld-2.11.1.so) 
==21536== by 0x4000C6C: (within /lib/ld-2.11.1.so) 
==21536== by 0x4000856: (within /lib/ld-2.11.1.so) 
==21536== 
==21536== Conditional jump or move depends on uninitialised value(s) 
==21536== at 0x400B27A: (within /lib/ld-2.11.1.so) 
==21536== by 0x40031D0: (within /lib/ld-2.11.1.so) 
==21536== by 0x4014206: (within /lib/ld-2.11.1.so) 
==21536== by 0x4000C6C: (within /lib/ld-2.11.1.so) 
==21536== by 0x4000856: (within /lib/ld-2.11.1.so) 
==21536== 
==21536== Conditional jump or move depends on uninitialised value(s) 
==21536== at 0x400A5DE: (within /lib/ld-2.11.1.so) 
==21536== by 0x40030FE: (within /lib/ld-2.11.1.so) 
==21536== by 0x4014206: (within /lib/ld-2.11.1.so) 
==21536== by 0x4000C6C: (within /lib/ld-2.11.1.so) 
==21536== by 0x4000856: (within /lib/ld-2.11.1.so) 
==21536== 
==21536== Conditional jump or move depends on uninitialised value(s) 
==21536== at 0x400A5E6: (within /lib/ld-2.11.1.so) 
==21536== by 0x40030FE: (within /lib/ld-2.11.1.so) 
==21536== by 0x4014206: (within /lib/ld-2.11.1.so) 
==21536== by 0x4000C6C: (within /lib/ld-2.11.1.so) 
==21536== by 0x4000856: (within /lib/ld-2.11.1.so) 
==21536== 
==21536== Conditional jump or move depends on uninitialised value(s) 
==21536== at 0x400AF0F: (within /lib/ld-2.11.1.so) 
==21536== by 0x40030FE: (within /lib/ld-2.11.1.so) 
==21536== by 0x4014206: (within /lib/ld-2.11.1.so) 
==21536== by 0x4000C6C: (within /lib/ld-2.11.1.so) 
==21536== by 0x4000856: (within /lib/ld-2.11.1.so) 
==21536== 
==21536== Invalid read of size 8 
==21536== at 0x40B4785: (within /lib/tls/i686/cmov/libc-2.11.1.so) 
==21536== by 0x8049EFB: main (vcutil.c:496) 
==21536== Address 0x419d1b0 is 8 bytes before a block of size 120 alloc'd 
==21536== at 0x4025D2E: malloc (vg_replace_malloc.c:207) 
==21536== by 0x409DF9D: getdelim (in /lib/tls/i686/cmov/libc-2.11.1.so) 
==21536== by 0x408F3A2: getline (in /lib/tls/i686/cmov/libc-2.11.1.so) 
==21536== by 0x804947C: getUnfolded (vcutil.c:299) 
==21536== by 0x8049EFB: main (vcutil.c:496) 
==21536== 
==21536== Conditional jump or move depends on uninitialised value(s) 
==21536== at 0x40B47AD: (within /lib/tls/i686/cmov/libc-2.11.1.so) 
==21536== by 0x8049EFB: main (vcutil.c:496) 
==21536== 
==21536== Conditional jump or move depends on uninitialised value(s) 
==21536== at 0x8049524: getUnfolded (vcutil.c:307) 
==21536== by 0x8049EFB: main (vcutil.c:496) 

मैं विशेष रूप से क्या पता नहीं है

--21536-- Warning: DWARF2 CFI reader: unhandled DW_OP_ opcode 0x55 

का मतलब है। ये नए हैं क्योंकि मैंने distros बदल दिया।

VcStatus getUnfolded (FILE *const vcf, char **const buff) { 

    //int const buffSize = 30; 
    size_t lineSize = 0; 
    int done = 0; //Set to one if the next line checked does not entail unfolding 
    static char* queue = NULL; //A queue to store the next line read in 
    static int lineNum = 0; 
    char* buffer = NULL; //The dynamic memory that will be linked to buf 
    int valid_line = 0; //Set to one if the line contains characters other then whitespace 
    char* temp; //Used to point to the location of \r\n in the buffer 

    VcStatus error; //Initialize VcStatus with appropriate values 
    error.code = OK; 
    error.linefrom = lineNum; 
    error.lineto = 0; 

    //Special case for resetting getUnfolded() 
    if (vcf == NULL){  
     lineNum = 0; 
     if (queue != NULL) queue = NULL; 
     error.linefrom = 0; 
     error.lineto = 0; 
     return error; 
    } 

    //Copies any string contained in queue from last time into buffer 
    if (queue != NULL) { 
     buffer = malloc (strlen (queue)+1); 
     strcpy (buffer, queue); 
     strcpy (queue, ""); 
    } 

    //If the end of file has been reached, last line is returned. 
    if (feof (vcf) != 0) { 
     queue = NULL; 
     lineNum += 1; 
     if (buffer != NULL) { 
      if (strcmp (buffer, "") != 0)*buff = buffer; 
     } 
     else *buff = NULL; 
     return error; 
    } 

    while (done == 0) { 

     //Gets a new line from the vcf file, and returns null if there is no more data to be returned 
     getline (&queue, &lineSize, vcf); 

     if (ferror(vcf) != 0) { 
      error.code = IOERR; 
      return error; 
     } 

     //Sets valid_line to 1 if the line read in contains any characters other then whitespace 
     for (int i = 0; i < strlen (queue); i++){ 
      if (queue[i] != '\r' && queue[i] != '\n' && queue[i] != ' ' && queue[i] != '\t') valid_line = 1; 
     } 

     if (feof (vcf) && valid_line == 0) { 
      queue = NULL; 
      break; 
     }   

     if (valid_line == 1){ 
      //Finds the 'internet standard' newline and replaces it with a null terminator 
      temp = strstr (queue, "\r\n"); 
      if (temp != NULL) strcpy (temp, "\0"); 

      //Sets the buffer equal to contents of queue and resets queue if buffer is empty 
      if (buffer == NULL) { 

       buffer = malloc (strlen (queue)+1); 
       lineNum = lineNum + 1;   
       strcpy (buffer, queue); 
       strcpy (queue, ""); 

      //Checks for leading whitespace to indicate a folded line, and unfolds 
      }else if (queue [0] == ' ' || queue [0] == '\t') { 

       lineNum = lineNum + 1; 
       buffer = realloc (buffer, strlen (buffer)+strlen (queue)+2); 
       strcat (buffer, queue+1); 
       strcpy (queue, ""); 

      //If both conditions above are false, buffer contains the next valid line 
      }else{ 

       error.lineto = lineNum; 
       lineNum += 1; 
       done = 1; 

      } 
     } 
    } 

    *buff = buffer; 

    return error; 

} 

... और डमी समारोह इसे करने के लिए परीक्षण डेटा भेजने के लिए:

int main() { 

    FILE* fp = fopen ("test.vcf", "r"); 

    char * buff; 

    getUnfolded (fp, &buff); 

} 

test.vcf

वैसे भी, संदर्भ के लिए, यहाँ प्रश्न में मेरी समारोह है फ़ाइल वास्तव में एक साधारण पाठ फ़ाइल है वास्तव में

कोई भी मदद अद्भुत होगी।

+0

इस्तेमाल किया है कि गूगल चीज़ के बारे में बहुत अजीब है: पी आप कोई मैं था दिखाने के लिए चला जाता है भाग्य यह समस्या है कि अगर यह पहला परिणाम है। और हाँ, मैंने इस नए होस्ट पर कई बार पुनः संकलित किया है, और स्रोत नहीं बदला है ... test.vcf फ़ाइल उचित ईओएल सीआरएलएफ का उपयोग कर रही है ... यह काफी परेशान समस्या है! – araisbec

+1

यदि मुझे सही तरीके से याद है, तो 'dwarf2 opcode' त्रुटियां शायद आप संकलक के पुराने से अधिक पुराने संस्करण के संस्करण पर जा रहे हैं, और सुरक्षित रूप से अनदेखा किया जा सकता है। आपकी त्रुटि के बारे में: आप 'strlen (queue)' कॉल करते हैं। यदि लाइन 'लाइन आकार' से अधिक लंबी है तो क्या होगा? यदि आप निष्कर्ष पर आते हैं कि कोड ठीक है, तो आप अपने जीवन के साथ एक दमन फ़ाइल उत्पन्न कर सकते हैं। – Borealid

+0

उत्तर के लिए धन्यवाद, यह समझना अच्छा लगता है कि क्यों वाल्ग्रिंड मुझ पर बकवास कर रहा है जो बिल्कुल समझ में नहीं आता है! मुझे यह जानने में दिलचस्पी होगी कि उन त्रुटियों को दबाने के लिए कैसे करें यदि आप जानते हैं कि कैसे? और मेरे पास कोई विचार नहीं है कि उस त्रुटि के आसपास कैसे काम करना है जिसका आप जिक्र कर रहे हैं। मेरी समझ में, उस स्ट्रेल (कतार) लाइन को बुलाया जाता है अगर कतार में आखिरी बार फ़ंक्शन कहा जाता था। मुझे त्रुटियों में "अनियमित वैरिएबल" की तुलना में त्रुटियां मिल रही हैं क्योंकि मेरे चर को सशर्त बयान (हर मामले में) में शुरू किया गया है, और मुझे नहीं पता कि उनसे कैसे छुटकारा पाना है। – araisbec

उत्तर

5

आपके द्वारा उपयोग किए जाने वाले वाल्ग्रिंड का संस्करण पुराना है और इसलिए यह सही आउटपुट को दबा नहीं रहा है। वे त्रुटियां अभी भी संदेह पर हैं, वे सिर्फ दबाए गए हैं क्योंकि वे सिस्टम कोड में हैं।

आप मैन्युअल valgrind के नवीनतम संस्करण स्थापित करने की आवश्यकता

इस मंच पोस्ट मैं

http://ubuntuforums.org/showthread.php?t=1608001