Skip to content

Commit

Permalink
fix dangling reference in parser::Parse with shared_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
jbohanon committed Mar 15, 2024
1 parent 2c441a3 commit f99b998
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion include/inja/environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class Environment {

Template parse(std::string_view input) {
Parser parser(parser_config, lexer_config, template_storage, function_storage);
return parser.parse(input, input_path);
return *parser.parse(input, input_path);
}

Template parse_template(const std::string& filename) {
Expand Down
6 changes: 3 additions & 3 deletions include/inja/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,9 +621,9 @@ class Parser {
const FunctionStorage& function_storage)
: 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));
parse_into(result, path);
std::shared_ptr<Template> parse(std::string_view input, std::string_view path) {
auto result = std::make_shared<Template>(static_cast<std::string>(input));
parse_into(*result, path);
return result;
}

Expand Down
8 changes: 4 additions & 4 deletions single_include/inja/inja.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2059,9 +2059,9 @@ class Parser {
const FunctionStorage& function_storage)
: 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));
parse_into(result, path);
std::shared_ptr<Template> parse(std::string_view input, std::string_view path) {
auto result = std::make_shared<Template>(static_cast<std::string>(input));
parse_into(*result, path);
return result;
}

Expand Down Expand Up @@ -2834,7 +2834,7 @@ class Environment {

Template parse(std::string_view input) {
Parser parser(parser_config, lexer_config, template_storage, function_storage);
return parser.parse(input, input_path);
return *parser.parse(input, input_path);
}

Template parse_template(const std::string& filename) {
Expand Down

0 comments on commit f99b998

Please sign in to comment.