I am trying to use Frama-C to verify safety properties of C code that includes dynamic memory allocation. The current version of the ACSL specification language (1.8) seems to be able to express a lot about dynamically allocated memory. However, most of that stuff is not yet implemented in Frama-C Neon.
Suppose we take the following snippet of code:
#include <stdlib.h>
/*@ requires \valid(p) && \valid(q) && \separated(p, q);
@ ensures \valid(q);
@*/
void test(char *p, char *q) {
free(p);
}
int main(void) {
char *p = (char *) malloc(10);
char *q = (char *) malloc(10);
test(p, q);
return 0;
}
So, main allocates two blocks of memory, and passes pointers to them to function test. Test frees the block pointed to by p, but not the block pointed to by q. Suppose I want to prove that at the end of test, pointer q is still valid. How would I proceed?
It seems that I have to model the heap on my own: axiomatize a few predicates that talk about the heap, and use them to specify malloc and free, mimicking the non-implemented parts of ACSL. What would be the simplest approach to do that, so that I can verify the example above?