harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 71a624b4b4071d591c532df1dcd422c1a6ad599c
parent 140f0af487e647786bb715e0574bc9285a239955
Author: Bor Grošelj Simić <bor.groseljsimic@telemach.net>
Date:   Mon, 26 Apr 2021 14:50:30 +0200

rt::compile: null-terminate execve arguments

and introduce a test to prevent similar breakage in the future

Signed-off-by: Bor Grošelj Simić <bor.groseljsimic@telemach.net>

Diffstat:
Mrt/compile.ha | 6+++---
Atests/27-rt.ha | 20++++++++++++++++++++
Mtests/configure | 3++-
3 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/rt/compile.ha b/rt/compile.ha @@ -11,14 +11,14 @@ export fn compile(src: const str) int = { close(1); close(2); - const path = "./harec"; + const path = "./harec\0"; const argv: [_]nullable *const char = [ constchar(path), - constchar("-"), + constchar("-\0"), null ]; const envp: [_]nullable *const char = [null]; - execve(path, &argv, &envp); + execve(constchar(path), &argv, &envp); abort(); } else { close(pipefd[0]); diff --git a/tests/27-rt.ha b/tests/27-rt.ha @@ -0,0 +1,20 @@ +// tests for the test runtime itself + +use rt; + +fn compile() void = { + assert(rt::compile(" + fn test() void = { + void; + };" + ) == 0); + assert(rt::compile(" + fn test() void = { + let a: int = [1, 2, 3]; + };" + ) != 0); +}; + +export fn main() void = { + compile(); +}; diff --git a/tests/configure b/tests/configure @@ -29,7 +29,8 @@ tests() { 23-errors \ 24-imports \ 25-promotion \ - 26-gen + 26-gen \ + 27-rt do cat <<EOF tests/$t: libhart.a tests/$t.ha