Eliminate this = default shortcut when height * width = 0
Merged
MA
1y ago+185+185+012345678901234567890123456789-53-53-01234567890123456789
Closes #1101
Previously, when creating 2D memory structures (Memory2D<T>, ReadOnlyMemory2D<T>, Span2D<T>, ReadOnlySpan2D<T>) with zero height or width, some constructors would take a shortcut by setting this = default. This approach had issues because it didn't properly preserve non-zero dimensions (e.g., a 4×0 or 0×7 structure would become 0×0). Additionally, the OverflowHelper.ComputeInt32Area method could return non-zero values when height=0 due to an invalid formula.
Solution
-
Removed the this = default shortcuts from all 2D memory structure constructors
-
Fixed calculation in
OverflowHelper.ComputeInt32Area: -
Added comprehensive tests to verify empty structures maintain correct dimensions
PR Checklist
- Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
- Based off latest main branch of toolkit
- PR doesn't include merge commits (always rebase on top of our main, if needed)
- Tested code with current supported SDKs
- Tests for the changes have been added (for bug fixes / features) (if applicable)
- Header has been added to all new source files (run build/UpdateHeaders.bat)
- Contains NO breaking changes
- Code follows all style conventions