I want to use Frama-C to analyze a program containing
a read
-like function: given a buffer buf
and its length len
, the function writes exactly len
bytes in buf
(unless there is an error).
I used ACSL to specify it, but the value analysis is giving me weird results.
Here's my specification, plus a main
function for testing:
/*@
assigns \result \from \nothing;
assigns *(buf+(0..len-1)) \from \nothing;
behavior ok:
requires \valid(buf+(0..len-1));
ensures \result == 0;
ensures \initialized(buf+(0..len-1));
behavior error:
ensures \result == -1;
*/
int read(char *buf, int len);
int main() {
char buf[10];
read(buf, 10);
return 0;
}
When running frama-c -val test.c
(I'm using Frama-C Neon), I obtain this result:
[value] Analyzing a complete application starting at main
[value] Computing initial state
[value] Initial state computed
[value] Values of globals at initialization
[value] computing for function read <- main.
Called from test.c:16.
[value] using specification for function read
test.c:6:[value] Function read, behavior ok: precondition got status valid.
test.c:10:[value] Function read, behavior error: this postcondition evaluates to false in this
context. If it is valid, either a precondition was not verified for this
call, or some assigns/from clauses are incomplete (or incorrect).
[value] Done for function read
[value] Recording results for main
[value] done for function main
[value] ====== VALUES COMPUTED ======
[value] Values at end of function main:
NON TERMINATING FUNCTION
I did put assigns
/from
clauses, and there are no preconditions for the error
behavior (so, by default, they are verified).
What is going on here? How can I make the analysis work in this case?