From 6a4ee90cb05f5680b946501e0b00161048c73a04 Mon Sep 17 00:00:00 2001 From: yury Date: Fri, 21 Dec 2007 15:35:32 +0000 Subject: [PATCH] * Inherit recordalignment by objects. Otherwise static instances of child objects are not aligned properly. Mantis #10454. + Test. git-svn-id: trunk@9495 - --- compiler/symdef.pas | 2 ++ tests/webtbs/tw10454.pp | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 tests/webtbs/tw10454.pp diff --git a/compiler/symdef.pas b/compiler/symdef.pas index 68c2b04a34..a6c6d50d95 100644 --- a/compiler/symdef.pas +++ b/compiler/symdef.pas @@ -3907,6 +3907,8 @@ implementation tObjectSymtable(symtable).datasize:= tObjectSymtable(symtable).datasize+ tObjectSymtable(c.symtable).datasize; + { inherit recordalignment } + tObjectSymtable(symtable).recordalignment:=tObjectSymtable(c.symtable).recordalignment; if (oo_has_vmt in objectoptions) and (oo_has_vmt in c.objectoptions) then tObjectSymtable(symtable).datasize:= diff --git a/tests/webtbs/tw10454.pp b/tests/webtbs/tw10454.pp new file mode 100644 index 0000000000..77bdbfdef4 --- /dev/null +++ b/tests/webtbs/tw10454.pp @@ -0,0 +1,22 @@ +{$mode objfpc} + +type + TMyObject = object + Int: longint; + end; + + TMyObject2 = object(TMyObject) + end; + + TMyClass = class + FByte: byte; + Obj: TMyObject2; // instance of this object is not aligned + end; + +var + myclass: TMyClass; +begin + myclass:=TMyClass.Create; + myclass.obj.int:=1; // Crash due to unaligned data access + myclass.Free; +end.