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

_Outptr_result_maybenull_ and variants interpreted incorrectly #1005

Closed
kennykerr opened this issue Jul 22, 2022 · 7 comments · Fixed by #1405 or microsoft/windows-rs#2247
Closed

_Outptr_result_maybenull_ and variants interpreted incorrectly #1005

kennykerr opened this issue Jul 22, 2022 · 7 comments · Fixed by #1405 or microsoft/windows-rs#2247
Assignees
Labels
bug Something isn't working rust Critical for Rust adoption

Comments

@kennykerr
Copy link
Contributor

kennykerr commented Jul 22, 2022

Like a few previous issues, this SAL annotation denotes that the result may be null, not that the parameter itself is optional. For example, ID2D1DeviceContext::GetTarget is described as follows:

unsafe void GetTarget([Optional][Out] ID2D1Image* image);

But this parameter is not in fact optional. There are also plenty of other parameters with these annotations being interpreted incorrectly. These include:

  • _Outptr_result_maybenull_
  • _Outptr_result_buffer_maybenull_
  • _COM_Outptr_result_maybenull_

There may well be others.

@kennykerr kennykerr changed the title _Outptr_result_maybenull_ and _COM_Outptr_result_maybenull_ interpreted incorrectly _Outptr_result_maybenull_ and variants interpreted incorrectly Jul 22, 2022
@kennykerr
Copy link
Contributor Author

From sal.h:

   Nullness:
   --------
   If the parameter can be NULL as a precondition to the function, the
   annotation contains _opt. If the macro does not contain '_opt' the
   parameter cannot be NULL.

   If an out/inout parameter returns a null pointer as a postcondition, this is
   indicated by _Ret_maybenull_ or _result_maybenull_. If the macro is not
   of this form, then the result will not be NULL as a postcondition.
     _Outptr_ - output value is not NULL
     _Outptr_result_maybenull_ - output value might be NULL

@riverar riverar added the bug Something isn't working label Jul 28, 2022
@kennykerr kennykerr added the rust Critical for Rust adoption label Aug 29, 2022
@AArnott
Copy link
Member

AArnott commented Sep 26, 2022

This would help microsoft/CsWin32#130 as well

@kennykerr
Copy link
Contributor Author

XmlLite's IXmlReader is another good example.

@kennykerr
Copy link
Contributor Author

IUriBuilder is another example. Is there anything we can do in the short term to start catching some of these? Even if we just detect _Outptr_result_maybenull_ as not being optional. This is just really hurting the calling experience.

@mikebattista mikebattista assigned mikebattista and unassigned riverar Dec 8, 2022
mikebattista added a commit that referenced this issue Dec 9, 2022
mikebattista added a commit that referenced this issue Dec 11, 2022
* Fixed #1005.

* Added missed API to the baseline.

* Detect _Maybenull_ as [In][Optional].

* Support overloads in winmd diffing tool.
@kennykerr
Copy link
Contributor Author

Thanks! Can you publish another build and I'll take it for a spin.

@mikebattista
Copy link
Collaborator

Yes it's published now.

@kennykerr
Copy link
Contributor Author

Thanks!

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