source: CIVL/examples/focus/sv-benchmarks-main-c-array-industry-pattern/c/array-industry-pattern/bug.c

main
Last change on this file was c2b37db, checked in by Alex Wilton <awilton@…>, 8 months ago

Merged focus branch into trunk.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5988 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 1.3 KB
RevLine 
[c2b37db]1/* This file is the version of array_of_struct_ptr_cond_init.c which does
2 * not make the change from S *a[N] to S a[N] (and hence contains the bug).
3 *
4 * Verifiable with mods:
[01c5b2ce]5 * Changed S *a[N] to S a[N] because of CIVL bug: Pointer symbolic info not simplified before dereference. Trying to fix this leads to deeper CIVL bug.
6 */
7typedef unsigned int size_t;
8#include <stdlib.h>
9#include <assert.h>
10#pragma CIVL ACSL
11
12extern int __VERIFIER_nondet_int(void) {
13 int x;
14 $havoc(&x);
15 return x;
16}
17$input int N;
18$assume(0 < N);
19struct _S
20{
21 int *p;
22 int n;
23};
24typedef struct _S S;
25
26S *a[N];
27int user_read()
28{
29 int x = __VERIFIER_nondet_int();
30 return x;
31}
32
33int main()
34{
35 int i;
36
[c2b37db]37 //@ focus I;
[01c5b2ce]38 for(i = 0; i < N; i++)
39 {
40 S *s1 = (S *)malloc(sizeof(S));
41
42 s1 -> n = user_read();
43
44 if(s1 ->n == 1)
45 {
46 s1 -> p = (int *)malloc(sizeof(int));
47 }
48 else
49 {
50 s1 -> p = (void *)0;
51 }
52 a[i] = s1;
53 }
54
55 // Modified
[c2b37db]56 //@ focus I;
[01c5b2ce]57 $assert($forall(int i:0..N-1) (a[i]->n == 1) == (a[i]->p != (void *)0));
58 // Original
59 /*
60 for(i = 0; i < N; i++)
61 {
62 S *s2 = a[i];
63
64 if(s2 ->n == 1)
65 {
66 __VERIFIER_assert(s2 -> p != (void *)0);
67 }
68 }
69 */
70
71 /*
[c2b37db]72 //@ focus I;
[01c5b2ce]73 for(i = 0; i < N; i++)
74 {
75 if (a[i]->n == 1) {
76 free(a[i]->p);
77 }
78 free(a[i]);
79 }
80 */
81 return 0;
82}
Note: See TracBrowser for help on using the repository browser.