Skip to content

Commit be28d3c

Browse files
committed
Fix OverflowException on 64bit due to bad cast
Error message was `OverflowException occurred. Arithmetic operation resulted in an overflow.` Link below explains in more detail the issue. This fixes the issue in both 32/64bit. https://www.codeproject.com/Answers/899343/How-to-fix-OverflowException-occurred-Arithmetic-o#answer2 Use keyword `long` instead of `System.Int64` Cast is safe. Thanks @denfromufa for the sources. http://stackoverflow.com/a/18173246/2230844 https://msdn.microsoft.com/en-us/library/x65fb868(v=vs.110).aspx
1 parent d86880a commit be28d3c

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

src/runtime/clrobject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ internal CLRObject(object ob, IntPtr tp)
1111
{
1212
IntPtr py = Runtime.PyType_GenericAlloc(tp, 0);
1313

14-
var flags = (int)Marshal.ReadIntPtr(tp, TypeOffset.tp_flags);
14+
var flags = (long)Marshal.ReadIntPtr(tp, TypeOffset.tp_flags);
1515
if ((flags & TypeFlags.Subclass) != 0)
1616
{
1717
IntPtr dict = Marshal.ReadIntPtr(py, ObjectOffset.DictOffset(tp));

src/runtime/debughelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ internal static void DumpType(IntPtr type)
8989
internal static void DumpInst(IntPtr ob)
9090
{
9191
IntPtr tp = Runtime.PyObject_TYPE(ob);
92-
var sz = (int)Marshal.ReadIntPtr(tp, TypeOffset.tp_basicsize);
92+
var sz = (long)Marshal.ReadIntPtr(tp, TypeOffset.tp_basicsize);
9393

9494
for (var i = 0; i < sz; i += IntPtr.Size)
9595
{

src/runtime/managedtype.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ internal static ManagedType GetManagedObject(IntPtr ob)
2828
tp = ob;
2929
}
3030

31-
var flags = (int)Marshal.ReadIntPtr(tp, TypeOffset.tp_flags);
31+
var flags = (long)Marshal.ReadIntPtr(tp, TypeOffset.tp_flags);
3232
if ((flags & TypeFlags.Managed) != 0)
3333
{
3434
IntPtr op = tp == ob
@@ -63,7 +63,7 @@ internal static bool IsManagedType(IntPtr ob)
6363
tp = ob;
6464
}
6565

66-
var flags = (int)Marshal.ReadIntPtr(tp, TypeOffset.tp_flags);
66+
var flags = (long)Marshal.ReadIntPtr(tp, TypeOffset.tp_flags);
6767
if ((flags & TypeFlags.Managed) != 0)
6868
{
6969
return true;

src/runtime/metatype.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public static void tp_dealloc(IntPtr tp)
247247
{
248248
// Fix this when we dont cheat on the handle for subclasses!
249249

250-
var flags = (int)Marshal.ReadIntPtr(tp, TypeOffset.tp_flags);
250+
var flags = (long)Marshal.ReadIntPtr(tp, TypeOffset.tp_flags);
251251
if ((flags & TypeFlags.Subclass) == 0)
252252
{
253253
IntPtr gc = Marshal.ReadIntPtr(tp, TypeOffset.magic());

0 commit comments

Comments
 (0)