src/file_pnm.c: add Frama-C annotations

This commit is contained in:
Christophe Grenier 2021-04-10 10:53:57 +02:00
parent db677e3b32
commit f429080064

View file

@ -32,41 +32,72 @@
#include "types.h"
#include "filegen.h"
/*@ requires \valid(file_stat); */
static void register_header_check_pnm(file_stat_t *file_stat);
const file_hint_t file_hint_pnm= {
.extension="pnm",
.description="Netpbm (PBM/PGM/PPM)",
.max_filesize=PHOTOREC_MAX_FILE_SIZE,
.recover=1,
.enable_by_default=1,
.register_header_check=&register_header_check_pnm
const file_hint_t file_hint_pnm = {
.extension = "pnm",
.description = "Netpbm (PBM/PGM/PPM)",
.max_filesize = PHOTOREC_MAX_FILE_SIZE,
.recover = 1,
.enable_by_default = 1,
.register_header_check = &register_header_check_pnm
};
/*@
@ 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_pnm, buffer+(..), file_recovery, file_recovery_new);
@ ensures \result!=0 ==> valid_file_recovery(file_recovery_new);
@ assigns *file_recovery_new;
@*/
static int header_check_pbm(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)
{
if(!isprint(buffer[5]) || !isprint(buffer[6]) || !isprint(buffer[7]))
return 0;
reset_file_recovery(file_recovery_new);
file_recovery_new->extension="pbm";
file_recovery_new->extension = "pbm";
return 1;
}
/*@
@ 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_pnm, buffer+(..), file_recovery, file_recovery_new);
@ ensures \result!=0 ==> valid_file_recovery(file_recovery_new);
@ assigns *file_recovery_new;
@*/
static int header_check_pgm(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)
{
if(!isprint(buffer[5]) || !isprint(buffer[6]) || !isprint(buffer[7]))
return 0;
reset_file_recovery(file_recovery_new);
file_recovery_new->extension="pgm";
file_recovery_new->extension = "pgm";
return 1;
}
/*@
@ 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_pnm, buffer+(..), file_recovery, file_recovery_new);
@ ensures \result!=0 ==> valid_file_recovery(file_recovery_new);
@ assigns *file_recovery_new;
@*/
static int header_check_ppm(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)
{
if(!isprint(buffer[5]) || !isprint(buffer[6]) || !isprint(buffer[7]))
return 0;
reset_file_recovery(file_recovery_new);
file_recovery_new->extension="ppm";
file_recovery_new->extension = "ppm";
return 1;
}