Skip to content

Restore NaN-compatible validation for foundation structs - #2559

Open
Sergio Pedri (Sergio0694) wants to merge 3 commits into
staging/3.0from
user/sergiopedri/projection-parameter-validation
Open

Restore NaN-compatible validation for foundation structs#2559
Sergio Pedri (Sergio0694) wants to merge 3 commits into
staging/3.0from
user/sergiopedri/projection-parameter-validation

Conversation

@Sergio0694

Copy link
Copy Markdown
Member

Summary

Restore the original comparison-based validation for Windows.Foundation.Size and Windows.Foundation.Rect in CsWinRT 3.0. NaNs and negative zero are accepted, while values less than zero still throw ArgumentOutOfRangeException.

Motivation

Replacing the original < 0 checks with ArgumentOutOfRangeException.ThrowIfNegative changed behavior because that API checks the floating-point sign bit, rejecting NaNs with the sign bit set (including float.NaN) and negative zero. Restore compatibility without duplicating exception construction at each call site.

Changes

  • src\WinRT.Runtime2\Properties\WindowsRuntimeExceptionExtensions.cs: add an aggressively inlined ThrowIfLessThanZero helper with a non-inlined failure path that delegates to the framework helper, preserving exception details.
  • src\WinRT.Runtime2\Windows.Foundation\Size.cs and src\WinRT.Runtime2\Windows.Foundation\Rect.cs: use the shared helper for constructor width and height validation.
  • src\Tests\UnitTest\FoundationStructTests.cs: add 60 regression cases for Point, Size, and Rect, covering signed quiet and signaling NaNs, signed zeros, subnormal and extreme finite values, infinities, validation ordering, exception parameter names and actual values, coordinate preservation, and alternate Rect constructors.

The runtime fix and regression coverage are kept in separate commits.

Centralize float less-than-zero validation in WindowsRuntimeExceptionExtensions and use it in Size and Rect constructors. Allow NaNs and negative zero while retaining the framework exception details for negative dimensions and keeping the throwing path out of line.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Cover signed quiet and signaling NaNs, signed zeros, subnormal and extreme finite values, infinities, exception parameter names and actual values, validation ordering, and alternate Rect constructors. Use integer bit patterns so source-generated test data preserves floating-point edge cases.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

The x86 floating-point path can quiet signaling NaNs, changing their bit patterns without changing their NaN classification. The previous bitwise assertions incorrectly treated this as a constructor regression.

Share a NaN-aware assertion across Point, Size, and Rect coverage. Retain every signaling-NaN case and exact bit comparisons for non-NaN values, including signed zero. Leave production validation unchanged.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working CsWinRT 3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant