sempare / sempare-delphi-template-engine

Sempare Template (scripting) Engine for Delphi allows for flexible dynamic text generation. It can be used for generating email, html, reports, source code, xml, configuration, etc.
Apache License 2.0
144 stars 18 forks source link

Use of custom functions resulted in "Access violation...Read of address 00000000" #60

Closed edwinyzh closed 1 year ago

edwinyzh commented 3 years ago

The code can be found in this github gist.

It's form with its .pas file, just create a new vcl project and add this testing form to the project.

Compile, run and hit 'btnTest', you'll get the "Access violation...Read of address 00000000" error.

Not sure why...

Thanks.

edwinyzh commented 3 years ago

Stack trace captured by madExcept:

exception class : ETemplateEvaluationError exception message : (Line 1, Column 10) Access violation at address 0063A7BD in module 'Prog1'. Read of address 00000000.

main thread ($2c78): 0063a96e +13a Prog1 Sempare.Template.Common 177 +1 RaiseError 0063aa39 +02d Prog1 Sempare.Template.Common 182 +1 RaiseError 00713be6 +106 Prog1 Sempare.Template.Evaluate 781 +5 TEvaluationTemplateVisitor.Visit 77e5012e +00a ntdll.dll KiUserExceptionDispatcher 0076dc4d +031 Prog1 Sempare.Template.Parser 1528 +1 TBinopExpr.Accept 0063a7e6 +086 Prog1 Sempare.Template.Common 138 +1 AcceptVisitor 007106b0 +058 Prog1 Sempare.Template.Evaluate 186 +3 TEvaluationTemplateVisitor.Visit 0076d649 +031 Prog1 Sempare.Template.Parser 1417 +1 TExprList.Accept 00712cd6 +042 Prog1 Sempare.Template.Evaluate 570 +1 TEvaluationTemplateVisitor.ExprListArgs 00713b34 +054 Prog1 Sempare.Template.Evaluate 778 +2 TEvaluationTemplateVisitor.Visit 0076d981 +031 Prog1 Sempare.Template.Parser 1479 +1 TFunctionCallExpr.Accept 0063a7e6 +086 Prog1 Sempare.Template.Common 138 +1 AcceptVisitor 00713f34 +044 Prog1 Sempare.Template.Evaluate 815 +1 TEvaluationTemplateVisitor.Visit 0076eacd +031 Prog1 Sempare.Template.Parser 1830 +1 TEncodeExpr.Accept 0063a7e6 +086 Prog1 Sempare.Template.Common 138 +1 AcceptVisitor 007135b1 +065 Prog1 Sempare.Template.Evaluate 708 +3 TEvaluationTemplateVisitor.Visit 0076de0d +031 Prog1 Sempare.Template.Parser 1565 +1 TPrintStmt.Accept 0076e2ba +05e Prog1 Sempare.Template.Parser 1653 +2 TTemplate.Accept 0063a712 +086 Prog1 Sempare.Template.Common 133 +1 AcceptVisitor 00770c1f +0a7 Prog1 MainFormU 153 +4 Template.Eval 00770b18 +064 Prog1 MainFormU 270 +3 Template.Eval 00770a82 +046 Prog1 MainFormU 279 +1 Template.Eval 007707f5 +06d Prog1 MainFormU 98 +5 TfrmMain.btnTestClick

edwinyzh commented 3 years ago

Oh, the error happened seems to be because full-width comma (a unicode character) took place of the ASCII comma...

darnocian commented 3 years ago

Where was the comma?

edwinyzh commented 3 years ago

Forget about comma, the error happened because full-width quotes (unicode characters) appeared in the function calls in the template code.

darnocian commented 3 years ago

Shall I close this?

darnocian commented 3 years ago

I'll double check the gist to see if I can reproduce

darnocian commented 3 years ago

It seemed to work fine for me.

I just had to change: cTmplStr = '{{ FuncB('/file1.txt') }}'; to cTmplStr = '{{ FuncB("/file1.txt") }}';

but I think that may have been a copy paste conversion issue rather than your code.

edwinyzh commented 3 years ago

Those are not full-width symbols, check this gist.

darnocian commented 3 years ago

Thanks. I think this may be worth reviewing to support with more flexibility... I think there may be an option that doesn't impose too much of an overhead to support this.

edwinyzh commented 3 years ago

Just to clarify, the post is not to request support for these full-width Chinese single/double quotes...

Maybe just emitting more meaningful error message like "Invalid character found at (line number, column number)" is enough.

sempare commented 1 year ago

The following improvement will be released shortly: