I am trying to prove a specification for a C loop that initialize two integer arrays to zero but i cannot verify it.
Here is the code:
int first[26];
int second[26];
int c;
/*@
loop assigns first[0..(c-1)];
loop assigns second[0..(c-1)];
loop assigns c;
loop invariant 0 <= c <= 26;
loop invariant \forall integer k; 0 <= k < c ==> second[k] == first[k];
loop invariant \forall integer k; 0 <= k < c ==> first[k] == 0 && second[k] == 0;
loop invariant \valid(first+(0..25)) && \valid(second+(0..25));
loop variant 26-c;
*/
for(c = 0; c < 26; c++)
{
first[c] = 0;
second[c] = 0;
}
I also tried to use the short form
int first[26] = {0}; for zero-initializing but it seems that Frama-C doesn't support that form.
I'm using Frama-C Sodium-20150201 with Alt-Ergo prover and it cannot verify the first three invariants of specification, that are
loop invariant 0 <= c <= 26;
loop invariant \forall integer k; 0 <= k < c ==> second[k] == first[k];
loop invariant \forall integer k; 0 <= k < c ==> first[k] == 0 && second[k] == 0;
0 <= c < 26(0 <= c <= 25). - Kninnugmemset? In that case you could simply usememset(first, 0, 26 * sizeof(int)). - abort