hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 4e174926076493054324e5f46685b27fbafa9ed3
parent c603886fd6f9c88688e679412585a16171082893
Author: Drew DeVault <sir@cmpwn.com>
Date:   Thu,  7 Sep 2023 16:47:39 +0200

shlex::split: fix memory errors

Simply abandoning the memio::dynamic stream causes issues.

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mshlex/split.ha | 10+++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/shlex/split.ha b/shlex/split.ha @@ -14,6 +14,8 @@ export fn split(in: const str) ([]str | syntaxerr) = { let iter = strings::iter(in); let s = memio::dynamic(); + defer io::close(&s)!; + let slice: []str = []; let first = true; let dirty = false; @@ -39,8 +41,9 @@ export fn split(in: const str) ([]str | syntaxerr) = { break; }; if (!first) { - append(slice, memio::string(&s)!); - s = memio::dynamic(); + const item = memio::string(&s)!; + append(slice, strings::dup(item)); + memio::reset(&s); }; dirty = false; case '\\' => @@ -59,7 +62,8 @@ export fn split(in: const str) ([]str | syntaxerr) = { }; if (dirty) { - append(slice, memio::string(&s)!); + const item = memio::string(&s)!; + append(slice, strings::dup(item)); }; return slice;