source:
CIVL/examples/languageFeatures/removedHeapPointer.cvl@
bb03188
| Last change on this file since bb03188 was ea777aa, checked in by , 3 years ago | |
|---|---|
|
|
| File size: 608 bytes | |
| Rev | Line | |
|---|---|---|
| [1641d2d] | 1 | /* This example shows that CIVL reports an error when |
| 2 | * the program tries to dereference a pointer referring | |
| 3 | * to a unit of a heap that is already removed. | |
| 4 | * Command line execution: | |
| 5 | * civl verify removedHeapPointer.cvl | |
| 6 | */ | |
| [e6b02c8] | 7 | #include <civlc.cvh> |
| [1641d2d] | 8 | |
| 9 | int *gp; | |
| 10 | _Bool gStart = $false; | |
| 11 | ||
| 12 | void foo(){ | |
| [a82987f] | 13 | $scope sf = $here; |
| [c19cfd5] | 14 | |
| [a82987f] | 15 | gp = (int *) $malloc(sf, sizeof(int)); |
| [1641d2d] | 16 | gStart = $true; |
| 17 | *gp = 1; | |
| [0b9a80a] | 18 | $free(gp); |
| [1641d2d] | 19 | } |
| 20 | ||
| 21 | void goo(){ | |
| 22 | $when(gStart); | |
| 23 | *gp = 2;// an error is possible when the process f has already returned. | |
| 24 | } | |
| 25 | ||
| 26 | void main(){ | |
| 27 | $proc f = $spawn foo(); | |
| 28 | $proc g = $spawn goo(); | |
| [c19cfd5] | 29 | |
| [0ddb25b] | 30 | $wait(f); |
| 31 | $wait(g); | |
| [1641d2d] | 32 | } |
Note:
See TracBrowser
for help on using the repository browser.
