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

Analyzer suggestion: Prefer SafeHandle over IntPtr #42404

Open
Mrnikbobjeff opened this issue Sep 17, 2020 · 4 comments
Open

Analyzer suggestion: Prefer SafeHandle over IntPtr #42404

Mrnikbobjeff opened this issue Sep 17, 2020 · 4 comments
Labels
area-System.Runtime.InteropServices code-analyzer Marks an issue that suggests a Roslyn analyzer
Milestone

Comments

@Mrnikbobjeff
Copy link

Mrnikbobjeff commented Sep 17, 2020

After working on some Interop analyzers I thought about SafeHandle and how known api's could suggest using the corresponding safehandle, such as SafeFileHandle or SafeWaitHandle. This could also more broadly be applied based on the method name, e.g. methods contains alloc/free could offer a warning when an IntPtr is used instead of a custom safehandle.

@Dotnet-GitSync-Bot
Copy link
Collaborator

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Sep 17, 2020
@jkotas jkotas added code-analyzer Marks an issue that suggests a Roslyn analyzer area-System.Runtime.InteropServices labels Sep 17, 2020
@jeffschwMSFT
Copy link
Member

@elinor-fung can you take a look?

@elinor-fung
Copy link
Member

I'd be concerned with false positives with any attempt to use the method name. For known APIs, this seems reasonable, however we have #42550, where marshalling SafeHandle doesn't allow null. We would need to address that issue before adding an analyzer like this.

/cc @AaronRobinsonMSFT @jkoritzinsky

@AaronRobinsonMSFT AaronRobinsonMSFT removed the untriaged New issue has not been triaged by the area owner label Sep 21, 2020
@AaronRobinsonMSFT AaronRobinsonMSFT added this to the 6.0.0 milestone Sep 21, 2020
@AaronRobinsonMSFT
Copy link
Member

@elinor-fung Let's make sure we fold this into #37039.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Runtime.InteropServices code-analyzer Marks an issue that suggests a Roslyn analyzer
Projects
Status: No status
Development

No branches or pull requests

6 participants