Browse Source

Fixed overflow exception and added tests

pull/2953/head
ElektroKill 2 years ago
parent
commit
01fd6e97f3
No known key found for this signature in database
GPG Key ID: 7E3C5C084E40E3EC
  1. 22
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/DecimalFields.cs
  2. 6
      ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs

22
ICSharpCode.Decompiler.Tests/TestCases/Correctness/DecimalFields.cs

@ -1,4 +1,4 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy of this // Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software // software and associated documentation files (the "Software"), to deal in the Software
@ -36,7 +36,27 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
Console.WriteLine(field2); Console.WriteLine(field2);
Console.WriteLine(field3); Console.WriteLine(field3);
Console.WriteLine(field4); Console.WriteLine(field4);
Console.WriteLine(IntToDecimal());
Console.WriteLine(UIntToDecimal());
Console.WriteLine(LongToDecimal());
Console.WriteLine(ULongToDecimal());
return 0; return 0;
} }
public static decimal IntToDecimal() {
return (decimal)int.MaxValue;
}
public static decimal UIntToDecimal() {
return (decimal)uint.MaxValue;
}
public static decimal LongToDecimal() {
return (decimal)long.MaxValue;
}
public static decimal ULongToDecimal() {
return (decimal)ulong.MaxValue;
}
} }
} }

6
ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs

@ -433,10 +433,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms
{ {
var paramType = inst.Method.Parameters[0].Type.GetDefinition()?.KnownTypeCode; var paramType = inst.Method.Parameters[0].Type.GetDefinition()?.KnownTypeCode;
result = paramType switch { result = paramType switch {
KnownTypeCode.Int32 => new LdcDecimal(new decimal((int)val)), KnownTypeCode.Int32 => new LdcDecimal(new decimal(unchecked((int)val))),
KnownTypeCode.UInt32 => new LdcDecimal(new decimal((uint)val)), KnownTypeCode.UInt32 => new LdcDecimal(new decimal(unchecked((uint)val))),
KnownTypeCode.Int64 => new LdcDecimal(new decimal(val)), KnownTypeCode.Int64 => new LdcDecimal(new decimal(val)),
KnownTypeCode.UInt64 => new LdcDecimal(new decimal((ulong)val)), KnownTypeCode.UInt64 => new LdcDecimal(new decimal(unchecked((ulong)val))),
_ => null _ => null
}; };
return result is not null; return result is not null;

Loading…
Cancel
Save