下面的函數獲取文件偏移量從rabin_polynomial結構,打開INPUT_FILE爲MD5指紋產生,並把結果寫入fpfile什麼是錯用下面的代碼
我的問題是,它似乎使用相同的chunk_buffer內容某些時候,它會爲具有不同度數的塊生成相似的指紋。
可能是什麼原因?
我已經與其他輸入分別測試了md5函數,並生成了正確的摘要。
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 to file.");
return -1;
}
poly=poly->next_polynomial;
free(chunk_buffer);
}
return 0;
}
編輯:
我在的malloc()線運行使用Visual Studio 2010中可能值映射爲的char *這個程序中創建的問題嗎?
讀取的字節數與參數中指定的數量相同。
你需要檢查某處某處fread的返回值 – perreal 2012-03-09 11:43:25