source:
CIVL/mods/dev.civl.com/examples/contracts/contractsSeq/pointers.c@
cb4d4f4
| Last change on this file since cb4d4f4 was aad342c, checked in by , 3 years ago | |
|---|---|
|
|
| File size: 374 bytes | |
| Line | |
|---|---|
| 1 | #include <stdlib.h> |
| 2 | /*@ requires \valid(x); |
| 3 | @ ensures \result == *x + 1; |
| 4 | @ |
| 5 | */ |
| 6 | int add(int * x) |
| 7 | { |
| 8 | return *x + 1; |
| 9 | } |
| 10 | |
| 11 | /*@ requires \valid(x); |
| 12 | @ requires *x >= 0; |
| 13 | @ ensures *x == \result - 1; |
| 14 | @*/ |
| 15 | int incr(int * x) |
| 16 | { |
| 17 | int * y; |
| 18 | int ret; |
| 19 | |
| 20 | y = (int*)malloc(sizeof(int)); |
| 21 | ret = add(x); |
| 22 | free(y); |
| 23 | return ret; |
| 24 | } |
| 25 | |
| 26 | int main() { |
| 27 | incr((void *)-1); |
| 28 | return 0; |
| 29 | } |
Note:
See TracBrowser
for help on using the repository browser.
