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

Reconsider null SafeHandle handling #755

Closed
AArnott opened this issue Nov 9, 2022 · 2 comments · Fixed by #760
Closed

Reconsider null SafeHandle handling #755

AArnott opened this issue Nov 9, 2022 · 2 comments · Fixed by #760
Assignees
Labels
bug Something isn't working

Comments

@AArnott
Copy link
Member

AArnott commented Nov 9, 2022

Now that I'm looking at that code some more, I'm also wondering why default(winmdroot.Foundation.HANDLE) is used when hMonitor is null, and why the call to DestroyPhysicalMonitor is still made. That would result in a 0 HANDLE, which is an actually valid handle you could get from PHYSICAL_MONITOR.

Originally posted by @User1785604260 in #753 (comment)

We should throw on null SafeHandle if the metadata does not include [Optional] for that parameter.
When it is optional, we should use a handle value that is documented as an invalid handle value the metadata rather than assume default(T) is suitable for a missing handle.

@AArnott AArnott added the bug Something isn't working label Nov 9, 2022
@AArnott AArnott self-assigned this Nov 10, 2022
@AArnott
Copy link
Member Author

AArnott commented Nov 10, 2022

Well, my fix for this may not address this particular feedback related to monitors, because DestroyPhysicalMonitor takes a HANDLE which is generally defined with both 0 and -1 being invalid handle values, so CsWin32 could theoretically emit either one when the SafeHandle is null.

AArnott added a commit that referenced this issue Nov 11, 2022
Also throw when the handle is not optional, but null is provided.

Fixes #755
AArnott added a commit that referenced this issue Nov 11, 2022
Also throw when the handle is not optional, but null is provided.

Fixes #755
AArnott added a commit that referenced this issue Nov 11, 2022
Also throw when the handle is not optional, but null is provided.

Fixes #755
@AArnott
Copy link
Member Author

AArnott commented Nov 30, 2022

@User1785604260 I don't know why a 0 HANDLE would represent something valid, considering HANDLE is documented as using 0 and -1 to represent an invalid handle. I tried in #760 to prefer -1 over 0 where both were 'invalid' to avoid the monitor issue, but doing so led to #810 so I'm going to revert to preferring 0 when it is a documented invalid value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant