[fpc-devel] Crash in TWriter with read only class property = nil
Martin Frb
lazarus at mfriebe.de
Fri May 21 20:04:39 CEST 2021
If you have a readonly property such as
(tested with 3.2.2 rc)
TMyComponent = class(TComponent)
private
FFoo: TComponent;
published
property ReadOnly: TComponent read FFoo;
end;
and FFoo is nil,
then TWriter will crash.
Is the above scenario forbidden to be implemented (and therefore the
crash a result of breaking some rule)
or should that work (and the crash is a bug)?
From 3.2.2 rc sources:
procedure TWriter.WriteProperty(Instance: TPersistent; PropInfo: Pointer);
begin
// do not stream properties without getter
if not Assigned(PPropInfo(PropInfo)^.GetProc) then
exit;
// properties without setter are only allowed, if they are subcomponents
PropType := PPropInfo(PropInfo)^.PropType;
if not Assigned(PPropInfo(PropInfo)^.SetProc) then begin
if PropType^.Kind<>tkClass then
exit;
ObjValue := TObject(GetObjectProp(Instance, PropInfo));
if not ObjValue.InheritsFrom(TComponent) or //
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
not (csSubComponent in TComponent(ObjValue).ComponentStyle) then
exit;
end;
The marked line calls InheritsFrom on a nil value.
#0 TWRITER.WRITEPROPERTY(TWRITER($0000000000145A60),
TPERSISTENT($000000000013A970), POINTER($0000000100378B08)) at
c:\FPC\fpc_3.2.2\source\rtl\objpas\classes\writer.inc:895
#1 TWRITER.WRITEPROPERTIES(TWRITER($0000000000145A60),
TPERSISTENT($000000000013A970)) at
c:\FPC\fpc_3.2.2\source\rtl\objpas\classes\writer.inc:850
#2 TWRITER.WRITECOMPONENTDATA(TWRITER($0000000000145A60),
TCOMPONENT($000000000013A970)) at
c:\FPC\fpc_3.2.2\source\rtl\objpas\classes\writer.inc:764
#3 TCOMPONENT.WRITESTATE(TCOMPONENT($000000000013A970),
TWRITER($0000000000145A60)) at
c:\FPC\fpc_3.2.2\source\rtl\objpas\classes\compon.inc:454
#4 TWRITER.WRITECOMPONENT(TWRITER($0000000000145A60),
TCOMPONENT($000000000013A970)) at
c:\FPC\fpc_3.2.2\source\rtl\objpas\classes\writer.inc:688
#5 TWRITER.WRITEDESCENDENT(TWRITER($0000000000145A60),
TCOMPONENT($000000000013A970), nil) at
c:\FPC\fpc_3.2.2\source\rtl\objpas\classes\writer.inc:778
#6 TWRITER.WRITEROOTCOMPONENT(TWRITER($0000000000145A60),
TCOMPONENT($000000000013A970)) at
c:\FPC\fpc_3.2.2\source\rtl\objpas\classes\writer.inc:1278
More information about the fpc-devel
mailing list