Skip to content

Commit f99b998

Browse files
committed
fix dangling reference in parser::Parse with shared_ptr
1 parent 2c441a3 commit f99b998

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

include/inja/environment.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class Environment {
105105

106106
Template parse(std::string_view input) {
107107
Parser parser(parser_config, lexer_config, template_storage, function_storage);
108-
return parser.parse(input, input_path);
108+
return *parser.parse(input, input_path);
109109
}
110110

111111
Template parse_template(const std::string& filename) {

include/inja/parser.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,9 @@ class Parser {
621621
const FunctionStorage& function_storage)
622622
: config(parser_config), lexer(lexer_config), template_storage(template_storage), function_storage(function_storage) {}
623623

624-
Template parse(std::string_view input, std::string_view path) {
625-
auto result = Template(static_cast<std::string>(input));
626-
parse_into(result, path);
624+
std::shared_ptr<Template> parse(std::string_view input, std::string_view path) {
625+
auto result = std::make_shared<Template>(static_cast<std::string>(input));
626+
parse_into(*result, path);
627627
return result;
628628
}
629629

single_include/inja/inja.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -2059,9 +2059,9 @@ class Parser {
20592059
const FunctionStorage& function_storage)
20602060
: config(parser_config), lexer(lexer_config), template_storage(template_storage), function_storage(function_storage) {}
20612061

2062-
Template parse(std::string_view input, std::string_view path) {
2063-
auto result = Template(static_cast<std::string>(input));
2064-
parse_into(result, path);
2062+
std::shared_ptr<Template> parse(std::string_view input, std::string_view path) {
2063+
auto result = std::make_shared<Template>(static_cast<std::string>(input));
2064+
parse_into(*result, path);
20652065
return result;
20662066
}
20672067

@@ -2834,7 +2834,7 @@ class Environment {
28342834

28352835
Template parse(std::string_view input) {
28362836
Parser parser(parser_config, lexer_config, template_storage, function_storage);
2837-
return parser.parse(input, input_path);
2837+
return *parser.parse(input, input_path);
28382838
}
28392839

28402840
Template parse_template(const std::string& filename) {

0 commit comments

Comments
 (0)