Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contracts can't specify write-only pointers for --uninitialized-check #8476

Open
BeamRaceMuppet opened this issue Sep 27, 2024 · 0 comments
Open

Comments

@BeamRaceMuppet
Copy link

When using --uninitialized-check with code contracts, there's no way to make the contract say it only writes the pointer and does not read it. Minimal example:

void set42(int *p)
__CPROVER_requires(__CPROVER_w_ok(p, sizeof(int)))
__CPROVER_ensures(*p == 42)
__CPROVER_assigns(*p)
;

int main()
{
    int x;
    set42(&x);
    assert(x == 42);
    return 0;
}

Run like this:

$ goto-cc set42.c -o set42.gb && goto-instrument --replace-call-with-contract set42 --uninitialized-check set42.gb set42.i.gb && cbmc set42.i.gb

Output:

[...]
** Results:
set42.c function main
[main.assertion.1] line 11 assertion x == 42: SUCCESS
[main.uninitialized_local.1] line 11 use of uninitialized local variable main::1::x: FAILURE

[...]

** 1 of 12 failed (2 iterations)
VERIFICATION FAILED

If there is a way to do this, then please consider this bug report a missing documentation bug instead.

CBMC version: 6.3.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant