src/file_pdb.c: add Frama-C annotations

This commit is contained in:
Christophe Grenier 2021-02-27 10:31:31 +01:00
parent c8fd4aa5d5
commit 75d31420bc

View file

@ -31,6 +31,7 @@
#include "types.h"
#include "filegen.h"
/*@ requires \valid(file_stat); */
static void register_header_check_pdb(file_stat_t *file_stat);
const file_hint_t file_hint_pdb= {
@ -42,9 +43,19 @@ const file_hint_t file_hint_pdb= {
.register_header_check=&register_header_check_pdb
};
/*@
@ 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_pdb;
@ ensures \result == DC_CONTINUE || \result == DC_STOP;
@ assigns file_recovery->calculated_file_size;
@*/
static data_check_t data_check_pdb(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
unsigned int i;
/*@ loop assigns i; */
for(i=buffer_size/2; i<buffer_size; i++)
if(buffer[i]==0)
{
@ -55,6 +66,13 @@ static data_check_t data_check_pdb(const unsigned char *buffer, const unsigned i
return DC_CONTINUE;
}
/*@
@ requires \valid(file_recovery);
@ requires valid_file_recovery(file_recovery);
@ requires file_recovery->file_check == &file_check_pdb;
@ ensures valid_file_recovery(file_recovery);
@ assigns file_recovery->file_size;
@*/
static void file_check_pdb(file_recovery_t *file_recovery)
{
unsigned char buffer[512];
@ -72,6 +90,17 @@ static void file_check_pdb(file_recovery_t *file_recovery)
file_recovery->file_size=0;
}
/*@
@ requires buffer_size >= 70;
@ 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_pdb, 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_pdb(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)
{
/* Check date */