source: CIVL/examples/library/stdlib/calloc1.cvl@ beab7f2

main test-branch
Last change on this file since beab7f2 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

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

  • Property mode set to 100644
File size: 755 bytes
Line 
1/* Commandline execution:
2 * civl verify malloc.cvl
3 * */
4#include <civlc.cvh>
5#include <string.h>
6#include <stdlib.h>
7
8void main() {
9 int i = 1;
10 //calloc in a declaration
11 int *p = (int*)calloc(5, sizeof(int));
12 int *q;
13
14 $assert(p[0]==0);
15 $assert(p[1]==0);
16 $assert(p[2]==0);
17 $assert(p[3]==0);
18 $assert(p[4]==0);
19
20 //calloc in an expression in the block
21 q = (int*)calloc(1, sizeof(int));
22 $assert(*q==0);
23 $free(q);
24
25 //calloc in an expression wrapped by if
26 if (p[0] == 0)
27 q = (int*)calloc(1, sizeof(int));
28 if (p[0] == 0){
29 $assert(*q==0);
30 $free(q);
31 }
32
33 //calloc in an expression wrapped by for
34 for (int n = 0; n < i; n++)
35 q = (int*)calloc(1, sizeof(int));
36 $assert(*q==0);
37 $free(q);
38
39 $free(p);
40}
Note: See TracBrowser for help on using the repository browser.