Skip to content

Allow assume bounds casts for function pointers #865

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

Merged
merged 4 commits into from
Jul 8, 2020

Conversation

kkjeer
Copy link
Contributor

@kkjeer kkjeer commented Jul 2, 2020

Fixes #855

This PR allows _Assume_bounds_casts to be used to convert an unchecked function pointer (including NULL) to a checked function pointer. The unchecked function pointer pointee type must be compatible with the checked function pointer pointee type.

For example, this will be allowed:

void test(int(*f)(int)) {
    ptr<int(int)> safe = _Assume_bounds_cast<ptr<int(int)>>(f);
}

This will not be allowed:

void test(int(*f)(int)) {
    ptr<void(double)> bad = _Assume_bounds_cast<ptr<void(double)>>(f);
}

Testing:

  • Added tests in checkedc/407
  • Passed manual testing on Windows
  • Passed automated testing on Windows/Linux

Copy link
Member

@dtarditi dtarditi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

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.

Assume bounds cast fails for function pointers
2 participants