Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Fixed Access violation with 64 bit compilers and updated ifdefs #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 10 additions & 3 deletions superobject.pas
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@
{$ifend}

{$if defined(VER230) or defined(VER240) or defined(VER250) or
defined(VER260) or defined(VER270) or defined(VER280)}
defined(VER260) or defined(VER270) or defined(VER280) or
defined(VER290) or defined(VER300) or defined(VER310) }
{$define VER210ORGREATER}
{$define VER230ORGREATER}
{$ifend}
Expand Down Expand Up @@ -6143,7 +6144,7 @@ function TSuperRttiContext.FromJson(TypeInfo: PTypeInfo; const obj: ISuperObject

procedure FromDynArray;
var
i: Integer;
i: NativeInt; // Integer; bugfix: see comment on DynArraySetLength
p: Pointer;
pb: PByte;
val: TValue;
Expand All @@ -6155,7 +6156,13 @@ function TSuperRttiContext.FromJson(TypeInfo: PTypeInfo; const obj: ISuperObject
begin
i := obj.AsArray.Length;
p := nil;
DynArraySetLength(p, TypeInfo, 1, @i);
// This is the declaration of DynArraySetLength:
// procedure DynArraySetLength(var a: Pointer; typeInfo: Pointer; dimCnt: NativeInt; lengthVec: PNativeint);
//
// THE LAST ARGUMENT MUST POINT TO A NATIVEINT (32/64 bit integer depending on client architecture) not to a 32 bit integer!
//
// when i was declared as a plain 32 bit integer, it was causing random access violations if compiled for Win64
DynArraySetLength( p, TypeInfo, 1, @i);
pb := p;
typ := GetTypeData(TypeInfo);
if typ.elType <> nil then
Expand Down