Skip to content

Commit

Permalink
fix dangling reference in parser::Parse
Browse files Browse the repository at this point in the history
  • Loading branch information
jbohanon committed Mar 15, 2024
1 parent 0066e60 commit 933febc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion include/inja/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Parser {

Lexer lexer;
TemplateStorage& template_storage;
std::vector<Template> template_stash;
const FunctionStorage& function_storage;

Token tok, peek_tok;
Expand Down Expand Up @@ -621,7 +622,7 @@ class Parser {
: config(parser_config), lexer(lexer_config), template_storage(template_storage), function_storage(function_storage) {}

Template parse(std::string_view input, std::string_view path) {
auto result = Template(static_cast<std::string>(input));
auto& result = template_stash.emplace_back(Template(static_cast<std::string>(input)));
parse_into(result, path);
return result;
}
Expand Down
3 changes: 2 additions & 1 deletion single_include/inja/inja.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,7 @@ class Parser {

Lexer lexer;
TemplateStorage& template_storage;
std::vector<Template> template_stash;
const FunctionStorage& function_storage;

Token tok, peek_tok;
Expand Down Expand Up @@ -2033,7 +2034,7 @@ class Parser {
: config(parser_config), lexer(lexer_config), template_storage(template_storage), function_storage(function_storage) {}

Template parse(std::string_view input, std::string_view path) {
auto result = Template(static_cast<std::string>(input));
auto& result = template_stash.emplace_back(Template(static_cast<std::string>(input)));
parse_into(result, path);
return result;
}
Expand Down

0 comments on commit 933febc

Please sign in to comment.