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

Make contract of free (for C) conditional on ptr being non-null #1250

Merged
merged 2 commits into from
Sep 30, 2024

Conversation

wandernauta
Copy link
Contributor

In C, passing NULL to free has no effect. This change weakens the precondition on the argument to free so that it only applies if the pointer is non-null, so this program now verifies:

  #include <stdlib.h>
  int main(){
      int* xs = NULL;
      free(xs);
      free(xs);
      free(xs);
  }

Adds test; changes existing test; fixes #1240. As @bobismijnnaam mentioned in that issue, this does introduce a number of branches - the hope there was that this "would not influence verification significantly", but I'm not sure how to check this; the existing examples seem to be okay, but those are quite small.

In C, passing NULL to `free` has no effect. This change weakens the
precondition on the argument to `free` so that it only applies if the
pointer is non-null, so this program now verifies:

      #include <stdlib.h>
      int main(){
          int* xs = NULL;
          free(xs);
          free(xs);
          free(xs);
      }

Adds test; changes existing test; fixes utwente-fmt#1240.
@superaxander superaxander merged commit a2c2b5c into utwente-fmt:dev Sep 30, 2024
13 checks passed
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

Successfully merging this pull request may close these issues.

Null pointer can not be passed to free in C
2 participants