--- layout: fc_discuss_archives title: Message 118 from Frama-C-discuss on May 2010 ---
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Frama-c-discuss] Small function on buffer doesn't verify



So, after a private discussion about the "const" modifier, here are a 
few conclusions.

The problem is that the C typing is too loose so that even if the user 
annotated a variable with const, it is not statically guaranted that the 
value cannot change: you can take the address of the variable, cast it 
to a non-const pointer, and then change its value. So, even if the C 
norm says it is a mistake to modify a const memory location, the 
compiler does not check it.

So what should be done is:

1) consider const as true constants, as expected

2) generate an additional VC to each assignment, to check whether the 
assigned location is writable.

1) without 2) would be unsound.

To support 2) I think we would need to introduce a distinction between 
two variant of the \valid predicate, one being "valid for reading", the 
other being "valid for both reading and writing". 

Everything would be simpler if it was forbidden to apply the & operator 
on a const. I'm not responsible for the C norm...
Otherwise, "const" could be handled as "final" in Java, and I know how 
to do it.

Hope this helps,

- Claude




Boris Hollas wrote:
> Jessie is unable to verify the following code for reasons that I don't
> understand. I get "?" for postcondition, pointer dereferencing,
> arithmetic overflow. Using #define instead of const doesn't work either
> because it seems that Jessie doesn't read #defines.
>
>
> const int BUFF_SIZE = 4;
>
> /*@ requires \valid(msg+(0..BUFF_SIZE));
>     ensures msg[BUFF_SIZE] == '\0';
> */
> int setFoo(char* msg) {
>   msg[BUFF_SIZE] = '\0';
>   msg[BUFF_SIZE-1] = '\0';
>   return 0;
> }
>
>
>
> _______________________________________________
> Frama-c-discuss mailing list
> Frama-c-discuss at lists.gforge.inria.fr
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/frama-c-discuss
>   


-- 
Claude March?                          | tel: +33 1 72 92 59 69           
INRIA Saclay - ?le-de-France           | mobile: +33 6 33 14 57 93 
Parc Orsay Universit?                  | fax: +33 1 74 85 42 29   
4, rue Jacques Monod - B?timent N      | http://www.lri.fr/~marche/
F-91893 ORSAY Cedex                    |