Skip to content

Allow assume bounds casts for function pointers#865

Merged
kkjeer merged 4 commits intomasterfrom
issue-855-assume-function-pointers
Jul 8, 2020
Merged

Allow assume bounds casts for function pointers#865
kkjeer merged 4 commits intomasterfrom
issue-855-assume-function-pointers

Conversation

@kkjeer
Copy link
Copy Markdown
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
Copy Markdown
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