src/file_x4a.c: fix Frama-C warnings

This commit is contained in:
Christophe Grenier 2021-07-28 21:42:22 +02:00
parent 40ee6a99f8
commit 6ebcf591e1

View file

@ -32,7 +32,7 @@
#include "filegen.h" #include "filegen.h"
#include "common.h" #include "common.h"
/*@ requires \valid(file_stat); */ /*@ requires valid_register_header_check(file_stat); */
static void register_header_check_ysfc100(file_stat_t *file_stat); static void register_header_check_ysfc100(file_stat_t *file_stat);
const file_hint_t file_hint_x4a = { const file_hint_t file_hint_x4a = {
@ -51,22 +51,18 @@ struct x4a_catalog
} __attribute__((gcc_struct, __packed__)); } __attribute__((gcc_struct, __packed__));
/*@ /*@
@ requires \valid(fr);
@ requires valid_file_recovery(fr);
@ requires \separated(fr, fr->handle, fr->extension, &errno, &Frama_C_entropy_source);
@ requires fr->file_check == &file_check_x4a; @ requires fr->file_check == &file_check_x4a;
@ ensures \valid(fr->handle); @ requires valid_file_check_param(fr);
@ ensures valid_file_check_result(fr);
@ assigns *fr->handle, errno, fr->file_size; @ assigns *fr->handle, errno, fr->file_size;
@ assigns Frama_C_entropy_source; @ assigns Frama_C_entropy_source;
@*/ @*/
static void file_check_x4a(file_recovery_t *fr) static void file_check_x4a(file_recovery_t *fr)
{ {
unsigned char buffer[0x200]; char buffer[0x200];
unsigned int i; unsigned int i;
unsigned int fs = 0x80; unsigned int fs = 0x80;
fr->file_size = 0; fr->file_size = 0;
fr->offset_error = 0;
fr->offset_ok = 0;
if(my_fseek(fr->handle, 0, SEEK_SET) < 0 || fread(&buffer, sizeof(buffer), 1, fr->handle) != 1) if(my_fseek(fr->handle, 0, SEEK_SET) < 0 || fread(&buffer, sizeof(buffer), 1, fr->handle) != 1)
return; return;
#ifdef __FRAMAC__ #ifdef __FRAMAC__
@ -83,8 +79,6 @@ static void file_check_x4a(file_recovery_t *fr)
if(tmp > fs) if(tmp > fs)
fs = tmp; fs = tmp;
} }
if(my_fseek(fr->handle, 0, SEEK_SET) < 0 || fread(&buffer, 8, 1, fr->handle) != 1)
return;
{ {
const struct x4a_catalog *p = (const struct x4a_catalog *)buffer; const struct x4a_catalog *p = (const struct x4a_catalog *)buffer;
fr->file_size = (uint64_t)fs + be32(p->size); fr->file_size = (uint64_t)fs + be32(p->size);
@ -93,12 +87,9 @@ static void file_check_x4a(file_recovery_t *fr)
/*@ /*@
@ requires buffer_size >= 0x34; @ requires buffer_size >= 0x34;
@ 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_x4a, buffer+(..), file_recovery, file_recovery_new); @ requires separation: \separated(&file_hint_x4a, buffer+(..), file_recovery, file_recovery_new);
@ 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);
@ assigns *file_recovery_new; @ assigns *file_recovery_new;
@*/ @*/
static int header_check_ysfc100(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) static int header_check_ysfc100(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)