下面的函数获取文件偏移量从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