src/file_dv.c: Fix Frama-C warnings

This commit is contained in:
Christophe Grenier 2021-06-07 13:31:12 +02:00
parent 12255e547f
commit 2400e99a06

View file

@ -34,7 +34,7 @@
#include "__fc_builtin.h"
#endif
/*@ requires \valid(file_stat); */
/*@ requires valid_register_header_check(file_stat); */
static void register_header_check_dv(file_stat_t *file_stat);
const file_hint_t file_hint_dv= {
@ -47,14 +47,9 @@ const file_hint_t file_hint_dv= {
};
/*@
@ requires buffer_size > 0;
@ requires (buffer_size&1)==0;
@ requires \valid_read(buffer+(0..buffer_size-1));
@ requires \valid(file_recovery);
@ requires file_recovery->data_check==&data_check_NTSC;
@ requires file_recovery->calculated_file_size <= PHOTOREC_MAX_FILE_SIZE;
@ requires \separated(buffer, file_recovery);
@ ensures \result == DC_CONTINUE || \result == DC_STOP;
@ requires valid_data_check_param(buffer, buffer_size, file_recovery);
@ ensures valid_data_check_result(\result, file_recovery);
@ assigns file_recovery->calculated_file_size;
@*/
static data_check_t data_check_NTSC(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
@ -77,22 +72,20 @@ static data_check_t data_check_NTSC(const unsigned char *buffer, const unsigned
}
/*@
@ requires \valid(fr);
@ requires fr->file_check == &file_check_dv_NTSC;
@ requires valid_file_recovery(fr);
@ ensures valid_file_recovery(fr);
@ requires valid_file_check_param(fr);
@ ensures valid_file_check_result(fr);
@ assigns *fr->handle, errno, Frama_C_entropy_source, fr->file_size;
@*/
static void file_check_dv_NTSC(file_recovery_t *fr)
{
unsigned char buffer_header[512];
unsigned char buffer[120000];
char buffer_header[512];
uint64_t fs=fr->file_size/120000*120000;
if(my_fseek(fr->handle, 0, SEEK_SET) < 0 ||
fread(&buffer_header, sizeof(buffer_header), 1, fr->handle) != 1)
return ;
#if defined(__FRAMAC__)
Frama_C_make_unknown((char *)&buffer_header, sizeof(buffer_header));
Frama_C_make_unknown(&buffer_header, sizeof(buffer_header));
#endif
if(fs > 0)
fs-=120000;
@ -100,12 +93,17 @@ static void file_check_dv_NTSC(file_recovery_t *fr)
fs-=120000;
/*@ loop assigns fs, *fr->handle, errno, Frama_C_entropy_source, fr->file_size; */
while(fs < fr->file_size &&
my_fseek(fr->handle, fs, SEEK_SET) >= 0 &&
fread(&buffer, sizeof(buffer), 1, fr->handle) == 1)
my_fseek(fr->handle, fs, SEEK_SET) >= 0)
{
char buffer[120000];
unsigned int i;
if(fread(&buffer, sizeof(buffer), 1, fr->handle) != 1)
{
fr->file_size=fs;
return;
}
#if defined(__FRAMAC__)
Frama_C_make_unknown((char *)&buffer, sizeof(buffer));
Frama_C_make_unknown(&buffer, sizeof(buffer));
#endif
/*@ loop assigns i, fr->file_size; */
for(i=1; i<sizeof(buffer); i+=0x50)
@ -120,14 +118,9 @@ static void file_check_dv_NTSC(file_recovery_t *fr)
}
/*@
@ requires buffer_size > 0;
@ requires (buffer_size&1)==0;
@ requires \valid_read(buffer+(0..buffer_size-1));
@ requires \valid(file_recovery);
@ requires file_recovery->data_check==&data_check_PAL;
@ requires file_recovery->calculated_file_size <= PHOTOREC_MAX_FILE_SIZE;
@ requires \separated(buffer, file_recovery);
@ ensures \result == DC_CONTINUE || \result == DC_STOP;
@ requires valid_data_check_param(buffer, buffer_size, file_recovery);
@ ensures valid_data_check_result(\result, file_recovery);
@ assigns file_recovery->calculated_file_size;
@*/
static data_check_t data_check_PAL(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
@ -150,22 +143,20 @@ static data_check_t data_check_PAL(const unsigned char *buffer, const unsigned i
}
/*@
@ requires \valid(fr);
@ requires fr->file_check == &file_check_dv_PAL;
@ requires valid_file_recovery(fr);
@ ensures valid_file_recovery(fr);
@ requires valid_file_check_param(fr);
@ ensures valid_file_check_result(fr);
@ assigns *fr->handle, errno, Frama_C_entropy_source, fr->file_size;
@*/
static void file_check_dv_PAL(file_recovery_t *fr)
{
unsigned char buffer_header[512];
unsigned char buffer[144000];
char buffer_header[512];
uint64_t fs=fr->file_size/144000*144000;
if(my_fseek(fr->handle, 0, SEEK_SET) < 0 ||
fread(&buffer_header, sizeof(buffer_header), 1, fr->handle) != 1)
return ;
#if defined(__FRAMAC__)
Frama_C_make_unknown((char *)&buffer_header, sizeof(buffer_header));
Frama_C_make_unknown(&buffer_header, sizeof(buffer_header));
#endif
if(fs > 0)
fs-=144000;
@ -173,12 +164,17 @@ static void file_check_dv_PAL(file_recovery_t *fr)
fs-=144000;
/*@ loop assigns fs, *fr->handle, errno, Frama_C_entropy_source, fr->file_size; */
while(fs < fr->file_size &&
my_fseek(fr->handle, fs, SEEK_SET) >= 0 &&
fread(&buffer, sizeof(buffer), 1, fr->handle) == 1)
my_fseek(fr->handle, fs, SEEK_SET) >= 0)
{
unsigned int i;
char buffer[144000];
if(fread(&buffer, sizeof(buffer), 1, fr->handle) != 1)
{
fr->file_size=fs;
return;
}
#if defined(__FRAMAC__)
Frama_C_make_unknown((char *)&buffer, sizeof(buffer));
Frama_C_make_unknown(&buffer, sizeof(buffer));
#endif
/*@ loop assigns i, fr->file_size; */
for(i=1; i<sizeof(buffer); i+=0x50)
@ -195,13 +191,9 @@ static void file_check_dv_PAL(file_recovery_t *fr)
/*@
@ requires buffer_size >= 8;
@ requires \valid_read(buffer+(0..buffer_size-1));
@ requires valid_file_recovery(file_recovery);
@ requires \valid(file_recovery_new);
@ requires file_recovery_new->blocksize > 0;
@ requires separation: \separated(&file_hint_dv, buffer+(..), file_recovery, file_recovery_new);
@ ensures \result == 0 || \result == 1;
@ ensures \result!=0 ==> valid_file_recovery(file_recovery_new);
@ requires valid_header_check_param(buffer, buffer_size, safe_header_only, file_recovery, file_recovery_new);
@ ensures valid_header_check_result(\result, file_recovery_new);
@*/
static int header_check_dv(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{