Note that there are some explanatory texts on larger screens.

plurals
  1. POwhat is wrong with the following code
    text
    copied!<p>The following function gets file offsets from the <strong>rabin_polynomial</strong> structure, opens the <strong>input_file</strong> for md5 fingerprint generation and writes the result to <strong>fpfile</strong></p> <p>My problem is it seems to use the same <strong>chunk_buffer</strong> content some times that it generates similar fingerprints for chunks with different legths.</p> <p>What could be the reason?</p> <p>I have tested the md5 function with other inputs separately and it generates correct digests.</p> <pre><code> 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-&gt;length)); bytes_read=fread (chunk_buffer,1, poly-&gt;length,input_file); if(bytes_read!=poly-&gt;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-&gt;start, poly-&gt;length,fing_print); if(ret_val == 0) { fprintf(stderr, "Could not write rabin polynomials to file."); return -1; } poly=poly-&gt;next_polynomial; free(chunk_buffer); } return 0; } </code></pre> <p>EDIT:</p> <p>I am running this program using visual studio 2010. Could typecasting to <strong>char *</strong> in the <strong>malloc()</strong> line create the problem?</p> <p>The number of bytes read is just as specified in the argument. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload