c - what is wrong with the following code -


the following function gets file offsets rabin_polynomial structure, opens input_file md5 fingerprint generation , writes result fpfile

my problem seems use same chunk_buffer content times generates similar fingerprints chunks different legths.

what reason?

i have tested md5 function other inputs separately , generates correct digests.

   int write_rabin_fingerprints_to_binary_file(file *fpfile,file *input_file,     struct rabin_polynomial *head) {             struct rabin_polynomial *poly=head;     unsigned char fing_print[33]={'\0'};     size_t bytes_read;       while(poly != null)         {            char *chunk_buffer;        chunk_buffer = (char*) malloc ((poly->length));          bytes_read=fread (chunk_buffer,1, poly->length,input_file);                          if(bytes_read!=poly->length)                 {                    printf("error reading from%s ",input_file);                    return -1;                 }        strncpy((char*)fing_print,md5(chunk_buffer).c_str(),32);             size_t ret_val=fprintf(fpfile, "%llu\t%lu\t%s\n",poly->start,                                        poly->length,fing_print);                if(ret_val == 0)                {                   fprintf(stderr, "could not write rabin polynomials file.");                   return -1;                }           poly=poly->next_polynomial;       free(chunk_buffer);         }     return 0; } 

edit:

i running program using visual studio 2010. typecasting char * in malloc() line create problem?

the number of bytes read specified in argument.

there nothing wrong in code cause such faults. found out happened because of zero-length strings called file holes.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -