src/file_hdf.c: add some frama-c annotations

This commit is contained in:
Christophe Grenier 2021-02-22 19:13:48 +01:00
parent ae37ef302e
commit 9654ccc1bf

View File

@ -38,6 +38,7 @@
#include "log.h"
#endif
/*@ requires \valid(file_stat); */
static void register_header_check_hdf(file_stat_t *file_stat);
const file_hint_t file_hint_hdf= {
@ -63,6 +64,13 @@ struct dd_struct
uint32_t length;
} __attribute__ ((gcc_struct, __packed__));
/*@
@ requires \valid(file_recovery);
@ requires \valid(file_recovery->handle);
@ requires valid_file_recovery(file_recovery);
@ requires \separated(file_recovery, file_recovery->handle, &errno, &Frama_C_entropy_source, &__fc_heap_status);
@ ensures \valid(file_recovery->handle);
@*/
static void file_check_hdf(file_recovery_t *file_recovery)
{
uint64_t file_size=0;
@ -130,6 +138,17 @@ static void file_check_hdf(file_recovery_t *file_recovery)
file_recovery->file_size = file_size;
}
/*@
@ requires buffer_size >= sizeof(struct ddh_struct);
@ 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_hdf, buffer+(..), file_recovery, file_recovery_new);
@ ensures \result == 0 || \result == 1;
@ ensures \result!=0 ==> valid_file_recovery(file_recovery_new);
@ assigns *file_recovery_new;
@*/
static int header_check_hdf(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)
{
const struct ddh_struct *ddh=(const struct ddh_struct *)&buffer[4];