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

Generated extension methods do not correctly handle optional array parameters #1041

Closed
BasTossings opened this issue Sep 19, 2023 · 1 comment · Fixed by #1043
Closed

Generated extension methods do not correctly handle optional array parameters #1041

BasTossings opened this issue Sep 19, 2023 · 1 comment · Fixed by #1043
Assignees
Labels
bug Something isn't working

Comments

@BasTossings
Copy link

Actual behavior

For example, the generated extension for ID2D1Factory.CreateStrokeStyle is as follows:

internal static unsafe void CreateStrokeStyle(this winmdroot.Graphics.Direct2D.ID2D1Factory @this, in winmdroot.Graphics.Direct2D.D2D1_STROKE_STYLE_PROPERTIES strokeStyleProperties, float[] dashes, out winmdroot.Graphics.Direct2D.ID2D1StrokeStyle strokeStyle)
	{
	fixed (winmdroot.Graphics.Direct2D.D2D1_STROKE_STYLE_PROPERTIES* strokeStylePropertiesLocal = &strokeStyleProperties)
		{
		@this.CreateStrokeStyle(strokeStylePropertiesLocal, dashes, (uint )dashes.Length, out strokeStyle);
		}
	}

The official API documentation states dashes is [in, optional].

when you call CreateStrokeStyle with dashes set to null, you get a NullReferenceException on (uint )dashes.Length.

Expected behavior

The generated extension methods should test for null on optional array parameters.

Repro steps

  1. NativeMethods.txt content:
ID2D1Factory
  1. NativeMethods.json content (if present):
{
  "$schema": "https://aka.ms/CsWin32.schema.json",
  "public": false,
  "allowMarshaling": true
}
  1. Any of your own code that should be shared?

Context

  • CsWin32 version: 0.3.18-beta
  • Win32Metadata version (if explicitly set by project): n/a
  • Target Framework: net7.0
  • LangVersion (if explicitly set by project): n/a
@BasTossings BasTossings added the bug Something isn't working label Sep 19, 2023
@AArnott
Copy link
Member

AArnott commented Sep 20, 2023

Thanks for the excellent report.

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.

2 participants