#1 2023-02-22 08:40:15

suoke
Member
Registered: 2023-02-09
Posts: 8
Website

Suggest adding "partial:=nil;" here

If it is not set to NIL first, memory error exception will occur when calling this variable under some tests.


mormot.core.mustache
......
procedure TSynMustache.RenderContext(Context: TSynMustacheContext;
  TagStart, TagEnd: integer);
var
  partial: TSynMustache;
begin
//add partial:=nil;
  partial:=nil;
......
  while TagStart <= TagEnd do
......

Offline

#2 2023-02-22 16:03:25

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Suggest adding "partial:=nil;" here

It does not make much sense, because this local variable is only used within the mtPartial state:

        mtPartial:
          begin
            partial := fInternalPartials.GetPartial(Value);

The compiler even complains that this assignment is never used.

Online

#3 2023-02-26 06:33:16

suoke
Member
Registered: 2023-02-09
Posts: 8
Website

Re: Suggest adding "partial:=nil;" here

Modify here in my code

        mtPartial:
          begin
            partial := nil; //add here
            if fInternalPartials <> nil then // if not,will Throw an exception  In the next line of code
              partial := fInternalPartials.GetPartial(Value);
            if (partial = nil) and (Context.fOwner <> self) then
              // recursive call
              partial := Context.fOwner.fInternalPartials.GetPartial(Value);
            if (partial = nil) and (Context.Partials <> nil) then
              partial := Context.Partials.GetPartial(Value);
            if partial <> nil then
              partial.RenderContext(Context, 0, high(partial.fTags));
          end;

Offline

Board footer

Powered by FluxBB