Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Microsoft.Windows.CsWin32/Generator.TypeDef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ private IEnumerable<MemberDeclarationSyntax> CreateCommonTypeDefMembers(Identifi
yield return ConstructorDeclaration(structName.Identifier)
.AddModifiers(TokenWithSpace(this.Visibility))
.AddParameterListParameters(Parameter(valueParameter.Identifier).WithType(IntPtrTypeSyntax.WithTrailingTrivia(TriviaList(Space))))
.WithInitializer(ConstructorInitializer(SyntaxKind.ThisConstructorInitializer).AddArgumentListArguments(Argument(CastExpression(fieldType, valueParameter))))
.WithInitializer(ConstructorInitializer(SyntaxKind.ThisConstructorInitializer).AddArgumentListArguments(Argument(UncheckedExpression(CastExpression(fieldType, valueParameter)))))
.WithBody(Block());
}

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Windows.CsWin32/templates/HRESULT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
partial struct HRESULT
{
public static implicit operator uint(HRESULT value) => (uint)value.Value;
public static explicit operator HRESULT(uint value) => new HRESULT((int)value);
public static explicit operator HRESULT(uint value) => new HRESULT(unchecked((int)value));

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
internal bool Succeeded => this.Value >= 0;
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Windows.CsWin32/templates/NTSTATUS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
partial struct NTSTATUS
{
public static implicit operator uint(NTSTATUS value) => (uint)value.Value;
public static explicit operator NTSTATUS(uint value) => new NTSTATUS((int)value);
public static explicit operator NTSTATUS(uint value) => new NTSTATUS(unchecked((int)value));

internal Severity SeverityCode => (Severity)(((uint)this.Value & 0xc0000000) >> 30);
internal Severity SeverityCode => (Severity)unchecked(((uint)this.Value & 0xc0000000) >> 30);

internal enum Severity
{
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Windows.CsWin32/templates/PInvokeClassMacros.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal class PInvokeClassMacros
/// <param name="a">The low word.</param>
/// <param name="b">The high word.</param>
/// <returns>A 32-bit unsigned integer.</returns>
internal static uint MAKELONG(ushort a, ushort b) => (uint)(a | b << 16);
internal static uint MAKELONG(ushort a, ushort b) => unchecked((uint)(a | b << 16));

/// <summary>
/// Constructs a <see cref="global::Windows.Win32.Foundation.WPARAM"/> from two 16-bit values.
Expand Down Expand Up @@ -57,5 +57,5 @@ internal class PInvokeClassMacros
/// </summary>
/// <param name="value">The 32-bit value.</param>
/// <returns>The high-order word.</returns>
internal static ushort HIWORD(uint value) => (ushort)(value >> 16);
internal static ushort HIWORD(uint value) => unchecked((ushort)(value >> 16));
}
7 changes: 7 additions & 0 deletions test/GenerationSandbox.Tests/BasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,13 @@ public void HANDLE_OverridesEqualityOperator()
Assert.False(handle5 == handle8);
}

[Fact]
public void HANDLE_CanCreateFromNegative()
{
// unchecked this will throw overflow exception in .NET Core.
var handle = new HANDLE(new IntPtr(-3));
}

[Fact]
public void GetWindowText_FriendlyOverload()
{
Expand Down
4 changes: 4 additions & 0 deletions test/GenerationSandbox.Tests/GenerationSandbox.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<Compile Remove="ComRuntimeTests.cs" Condition="!$([MSBuild]::IsOSPlatform('Windows'))" />
</ItemGroup>

<PropertyGroup>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
</PropertyGroup>

<ProjectExtensions>
<VisualStudio><UserProperties nativemethods_1json__JsonSchema="..\..\src\Microsoft.Windows.CsWin32\settings.schema.json" /></VisualStudio>
</ProjectExtensions>
Expand Down
Loading