Skip to content
Closed
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
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
  • Loading branch information
vmuriart committed Feb 23, 2017
commit be28d3c9a4e49656067bb1d1f0700d12924e6fad
2 changes: 1 addition & 1 deletion src/runtime/clrobject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal CLRObject(object ob, IntPtr tp)
{
IntPtr py = Runtime.PyType_GenericAlloc(tp, 0);

var flags = (int)Marshal.ReadIntPtr(tp, TypeOffset.tp_flags);
var flags = (long)Marshal.ReadIntPtr(tp, TypeOffset.tp_flags);
if ((flags & TypeFlags.Subclass) != 0)
{
IntPtr dict = Marshal.ReadIntPtr(py, ObjectOffset.DictOffset(tp));
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/debughelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ internal static void DumpType(IntPtr type)
internal static void DumpInst(IntPtr ob)
{
IntPtr tp = Runtime.PyObject_TYPE(ob);
var sz = (int)Marshal.ReadIntPtr(tp, TypeOffset.tp_basicsize);
var sz = (long)Marshal.ReadIntPtr(tp, TypeOffset.tp_basicsize);

for (var i = 0; i < sz; i += IntPtr.Size)
{
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/managedtype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal static ManagedType GetManagedObject(IntPtr ob)
tp = ob;
}

var flags = (int)Marshal.ReadIntPtr(tp, TypeOffset.tp_flags);
var flags = (long)Marshal.ReadIntPtr(tp, TypeOffset.tp_flags);
if ((flags & TypeFlags.Managed) != 0)
{
IntPtr op = tp == ob
Expand Down Expand Up @@ -63,7 +63,7 @@ internal static bool IsManagedType(IntPtr ob)
tp = ob;
}

var flags = (int)Marshal.ReadIntPtr(tp, TypeOffset.tp_flags);
var flags = (long)Marshal.ReadIntPtr(tp, TypeOffset.tp_flags);
if ((flags & TypeFlags.Managed) != 0)
{
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/metatype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public static void tp_dealloc(IntPtr tp)
{
// Fix this when we dont cheat on the handle for subclasses!

var flags = (int)Marshal.ReadIntPtr(tp, TypeOffset.tp_flags);
var flags = (long)Marshal.ReadIntPtr(tp, TypeOffset.tp_flags);
if ((flags & TypeFlags.Subclass) == 0)
{
IntPtr gc = Marshal.ReadIntPtr(tp, TypeOffset.magic());
Expand Down