File tree Expand file tree Collapse file tree
src/Microsoft.Windows.CsWin32
test/GenerationSandbox.Tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -278,7 +278,7 @@ private IEnumerable<MemberDeclarationSyntax> CreateCommonTypeDefMembers(Identifi
278278 yield return ConstructorDeclaration ( structName . Identifier )
279279 . AddModifiers ( TokenWithSpace ( this . Visibility ) )
280280 . AddParameterListParameters ( Parameter ( valueParameter . Identifier ) . WithType ( IntPtrTypeSyntax . WithTrailingTrivia ( TriviaList ( Space ) ) ) )
281- . WithInitializer ( ConstructorInitializer ( SyntaxKind . ThisConstructorInitializer ) . AddArgumentListArguments ( Argument ( CastExpression ( fieldType , valueParameter ) ) ) )
281+ . WithInitializer ( ConstructorInitializer ( SyntaxKind . ThisConstructorInitializer ) . AddArgumentListArguments ( Argument ( UncheckedExpression ( CastExpression ( fieldType , valueParameter ) ) ) ) )
282282 . WithBody ( Block ( ) ) ;
283283 }
284284
Original file line number Diff line number Diff line change 3838partial struct HRESULT
3939{
4040 public static implicit operator uint ( HRESULT value ) => ( uint ) value . Value ;
41- public static explicit operator HRESULT ( uint value ) => new HRESULT ( ( int ) value ) ;
41+ public static explicit operator HRESULT ( uint value ) => new HRESULT ( unchecked ( ( int ) value ) ) ;
4242
4343 [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
4444 internal bool Succeeded => this . Value >= 0 ;
Original file line number Diff line number Diff line change 2626partial struct NTSTATUS
2727{
2828 public static implicit operator uint ( NTSTATUS value ) => ( uint ) value . Value ;
29- public static explicit operator NTSTATUS ( uint value ) => new NTSTATUS ( ( int ) value ) ;
29+ public static explicit operator NTSTATUS ( uint value ) => new NTSTATUS ( unchecked ( ( int ) value ) ) ;
3030
31- internal Severity SeverityCode => ( Severity ) ( ( ( uint ) this . Value & 0xc0000000 ) >> 30 ) ;
31+ internal Severity SeverityCode => ( Severity ) unchecked ( ( ( uint ) this . Value & 0xc0000000 ) >> 30 ) ;
3232
3333 internal enum Severity
3434 {
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ internal class PInvokeClassMacros
1919 /// <param name="a">The low word.</param>
2020 /// <param name="b">The high word.</param>
2121 /// <returns>A 32-bit unsigned integer.</returns>
22- internal static uint MAKELONG ( ushort a , ushort b ) => ( uint ) ( a | b << 16 ) ;
22+ internal static uint MAKELONG ( ushort a , ushort b ) => unchecked ( ( uint ) ( a | b << 16 ) ) ;
2323
2424 /// <summary>
2525 /// Constructs a <see cref="global::Windows.Win32.Foundation.WPARAM"/> from two 16-bit values.
@@ -57,5 +57,5 @@ internal class PInvokeClassMacros
5757 /// </summary>
5858 /// <param name="value">The 32-bit value.</param>
5959 /// <returns>The high-order word.</returns>
60- internal static ushort HIWORD ( uint value ) => ( ushort ) ( value >> 16 ) ;
60+ internal static ushort HIWORD ( uint value ) => unchecked ( ( ushort ) ( value >> 16 ) ) ;
6161}
Original file line number Diff line number Diff line change @@ -200,6 +200,13 @@ public void HANDLE_OverridesEqualityOperator()
200200 Assert . False ( handle5 == handle8 ) ;
201201 }
202202
203+ [ Fact ]
204+ public void HANDLE_CanCreateFromNegative ( )
205+ {
206+ // unchecked this will throw overflow exception in .NET Core.
207+ var handle = new HANDLE ( new IntPtr ( - 3 ) ) ;
208+ }
209+
203210 [ Fact ]
204211 public void GetWindowText_FriendlyOverload ( )
205212 {
Original file line number Diff line number Diff line change 55 <Compile Remove =" ComRuntimeTests.cs" Condition =" !$([MSBuild]::IsOSPlatform('Windows'))" />
66 </ItemGroup >
77
8+ <PropertyGroup >
9+ <CheckForOverflowUnderflow >true</CheckForOverflowUnderflow >
10+ </PropertyGroup >
11+
812 <ProjectExtensions >
913 <VisualStudio ><UserProperties nativemethods_1json__JsonSchema =" ..\..\src\Microsoft.Windows.CsWin32\settings.schema.json" /></VisualStudio >
1014 </ProjectExtensions >
You can’t perform that action at this time.
0 commit comments