[PATCH] parse: Fix double free on slicing commands
Export this patch
Fixes: https://todo.sr.ht/~sircmpwn/rc/34
Signed-off-by: Max Schillinger <max@mxsr.de>
---
parse/value.ha | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/parse/value.ha b/parse/value.ha
index eaca0bc..0abf33d 100644
--- a/parse/value.ha
+++ b/parse/value.ha
@@ -162,8 +162,8 @@ fn parse_access_range(p: *parser, access: *ast::access) (void | error) = {
// or a dash
if (arg == "-") {
// p.e. $var(- 4) or $var(- $end)
- access.index = alloc("1": ast::string: ast::value);
- access.end = alloc("0": ast::string: ast::value);
+ access.index = alloc(strings::dup("1"): ast::string: ast::value);
+ access.end = alloc(strings::dup("0"): ast::string: ast::value);
had_dash = true;
} else if (strings::contains(arg, '-')) {
// p.e. $var(2-4) or $var(2-) or $var(-4)
@@ -213,7 +213,7 @@ fn parse_access_range(p: *parser, access: *ast::access) (void | error) = {
if (peek(p, ltok::RPAREN)? is lex::token) {
if (access.end == null) {
- access.end = alloc("0": ast::string: ast::value);
+ access.end = alloc(strings::dup("0"): ast::string: ast::value);
};
} else {
const (end, _) = parse_value(p, true)?;
--
2.43.0