View Issue Details

IDProjectCategoryView StatusLast Update
0031118FPCRTLpublic2016-12-15 14:48
ReporterMaciej IzakAssigned ToSven Barth 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product VersionProduct Build 
Target VersionFixed in Version3.1.1 
Summary0031118: [patch] InitializeArray/FinalizeArray crash
DescriptionRelated to latest commit r35125 (*PART 2* of management operators) has small defect. When patch from 0030687 was reworked I made small mistake (usage of type info instead of type data in critical part of RTTIRecordRttiInfoToInitInfo for FULL RTTI.

Patch + new rtti test attached.
TagsNo tags attached.
Fixed in Revision35133
FPCOldBugId
FPCTarget
Attached Files
  • 0001-When-is-used-FULL-RTTI-for-RTTIRecordRttiInfoToInitI.patch (1,533 bytes)
    From fb7c37c761135eb53b013be4ff7f73bd061cc3d2 Mon Sep 17 00:00:00 2001
    From: maciej-izak <hnb.code@gmail.com>
    Date: Thu, 15 Dec 2016 09:35:41 +0100
    Subject: [PATCH] When is used FULL RTTI for RTTIRecordRttiInfoToInitInfo use
     type data instead of type info (fix AV). Usage of
     InitializeArray/FinalizeArray works again. Fix small typo for patch *PART 2*
     (mantis #30687). New test attached.
    
    ---
     rtl/inc/rtti.inc      |  2 +-
     tests/test/trtti11.pp | 21 +++++++++++++++++++++
     2 files changed, 22 insertions(+), 1 deletion(-)
     create mode 100644 tests/test/trtti11.pp
    
    diff --git a/rtl/inc/rtti.inc b/rtl/inc/rtti.inc
    index 7d2c4ef..3a31d3c 100644
    --- a/rtl/inc/rtti.inc
    +++ b/rtl/inc/rtti.inc
    @@ -116,7 +116,7 @@ begin
       { check terminator, maybe we are already in init table }
       if Assigned(PRecordInfoInit(typeInfo)^.Terminator) then
         { point to more optimal initrtti }
    -    result:=PRecordInfoFull(result)^.InitTable;
    +    result:=PRecordInfoFull(typeInfo)^.InitTable;
     {$endif VER3_0}
     end;
     
    diff --git a/tests/test/trtti11.pp b/tests/test/trtti11.pp
    new file mode 100644
    index 0000000..593521e
    --- /dev/null
    +++ b/tests/test/trtti11.pp
    @@ -0,0 +1,21 @@
    +program trtti11;
    +
    +{$MODE DELPHI}
    +
    +type
    +  PFoo = ^TFoo;
    +  TFoo = packed record
    +  public
    +    F: Integer;
    +    S: string;
    +  end;
    +
    +var
    +  PF: PFoo;
    +begin
    +  GetMem(PF, SizeOf(TFoo));
    +  InitializeArray(PF, TypeInfo(TFoo), 1);
    +  PF.S := 'foo';
    +  FinalizeArray(PF, TypeInfo(TFoo), 1);
    +  FreeMem(PF);
    +end. 
    \ No newline at end of file
    -- 
    2.7.1.windows.2
    
    

Activities

Maciej Izak

2016-12-15 09:44

reporter  

0001-When-is-used-FULL-RTTI-for-RTTIRecordRttiInfoToInitI.patch (1,533 bytes)
From fb7c37c761135eb53b013be4ff7f73bd061cc3d2 Mon Sep 17 00:00:00 2001
From: maciej-izak <hnb.code@gmail.com>
Date: Thu, 15 Dec 2016 09:35:41 +0100
Subject: [PATCH] When is used FULL RTTI for RTTIRecordRttiInfoToInitInfo use
 type data instead of type info (fix AV). Usage of
 InitializeArray/FinalizeArray works again. Fix small typo for patch *PART 2*
 (mantis #30687). New test attached.

---
 rtl/inc/rtti.inc      |  2 +-
 tests/test/trtti11.pp | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 tests/test/trtti11.pp

diff --git a/rtl/inc/rtti.inc b/rtl/inc/rtti.inc
index 7d2c4ef..3a31d3c 100644
--- a/rtl/inc/rtti.inc
+++ b/rtl/inc/rtti.inc
@@ -116,7 +116,7 @@ begin
   { check terminator, maybe we are already in init table }
   if Assigned(PRecordInfoInit(typeInfo)^.Terminator) then
     { point to more optimal initrtti }
-    result:=PRecordInfoFull(result)^.InitTable;
+    result:=PRecordInfoFull(typeInfo)^.InitTable;
 {$endif VER3_0}
 end;
 
diff --git a/tests/test/trtti11.pp b/tests/test/trtti11.pp
new file mode 100644
index 0000000..593521e
--- /dev/null
+++ b/tests/test/trtti11.pp
@@ -0,0 +1,21 @@
+program trtti11;
+
+{$MODE DELPHI}
+
+type
+  PFoo = ^TFoo;
+  TFoo = packed record
+  public
+    F: Integer;
+    S: string;
+  end;
+
+var
+  PF: PFoo;
+begin
+  GetMem(PF, SizeOf(TFoo));
+  InitializeArray(PF, TypeInfo(TFoo), 1);
+  PF.S := 'foo';
+  FinalizeArray(PF, TypeInfo(TFoo), 1);
+  FreeMem(PF);
+end. 
\ No newline at end of file
-- 
2.7.1.windows.2

Sven Barth

2016-12-15 14:48

manager   ~0096810

Thanks for the patch. Hadn't noticed that myself despite having wondered whether the usage of "result" was correct or not...

Please test and close if okay.

Issue History

Date Modified Username Field Change
2016-12-15 09:44 Maciej Izak New Issue
2016-12-15 09:44 Maciej Izak File Added: 0001-When-is-used-FULL-RTTI-for-RTTIRecordRttiInfoToInitI.patch
2016-12-15 14:48 Sven Barth Fixed in Revision => 35133
2016-12-15 14:48 Sven Barth Note Added: 0096810
2016-12-15 14:48 Sven Barth Status new => resolved
2016-12-15 14:48 Sven Barth Fixed in Version => 3.1.1
2016-12-15 14:48 Sven Barth Resolution open => fixed
2016-12-15 14:48 Sven Barth Assigned To => Sven Barth