-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-add removed broken-crash test as broken-proof
rems-project/cerberus#602 changed the behaviour of this test
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/example-archive/java_program_verification_challenges/broken/error-proof/00001_aliasing.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Tags: main, pointers, structs, alias, java, malloc | ||
|
||
//#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
// Struct corresponding to the Java class C | ||
typedef struct C { | ||
struct C *a; // Pointer to same struct type to mimic object reference | ||
int i; | ||
} C; | ||
|
||
/* Normal-behavior | ||
* @ requires true; | ||
* @ assignable a, i; | ||
* @ ensures a == NULL && i == 1; | ||
*/ | ||
C* createC() { | ||
C* c = (C*) malloc(sizeof(C)); // Allocate memory for C | ||
c->a = NULL; // Initialize as null | ||
c->i = 1; // Initialize i to 1 | ||
return c; | ||
} | ||
|
||
// Struct corresponding to the Java class Alias | ||
/* typedef struct Alias { */ | ||
/* // No direct fields needed */ | ||
/* } Alias; */ | ||
|
||
/* Normal-behavior | ||
* @ requires true; | ||
* @ assignable nothing; | ||
* @ ensures result == 4; | ||
*/ | ||
int m() { | ||
C* c = createC(); // Similar to 'C c = new C();' | ||
c->a = c; // Alias to itself | ||
c->i = 2; // Change i to 2 | ||
int result = c->i + c->a->i; // Equivalent to 'return c.i + c.a.i;' | ||
free(c); // Clean up allocated memory | ||
return result; | ||
} | ||
|
||
int main() { | ||
/* Alias alias; // Instantiate Alias */ | ||
int result = m(); // Call m and store result | ||
//printf("Result: %d\n", result); // Print the result | ||
return result; | ||
} |