Skip to content

all: address memory corruption from GC freeing cabi_realloc allocations too early #351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/environment/big.txt

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions tests/environment/environment_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package environment_test

import (
"flag"
"os"
"testing"
"unsafe"

"tests/generated/wasi/cli/v0.2.0/environment"
)

func TestEnvironment(t *testing.T) {
env := environment.GetEnvironment()
t.Logf("env len: %d", env.Len())
for i, kv := range env.Slice() {
t.Logf("%02d: %s = %s", i, truncate(kv[0], 32), truncate(kv[1], 32))
}
}

var bigArg = flag.String("big", "", "big argument")

func TestArguments(t *testing.T) {
args := environment.GetArguments().Slice()

// t.Errorf("os.Args: %v\nargs: %v", os.Args, args)
t.Errorf("os.Args: %v", unsafe.SliceData(os.Args))
t.Errorf("os.Args[0]: %v", unsafe.StringData(os.Args[0]))
t.Errorf("len(os.Args): %d", len(os.Args))
t.Errorf("os.Args[1]: %s", os.Args[1])

for i, arg := range args {
t.Logf("%02d: %s", i, truncate(arg, 64))
if !testing.Verbose() && arg == "-test.v" {
t.Errorf("testing.Verbose() == false with %s arg", arg)
}
}

for i := 0; i < 1000; i++ {
args2 := environment.GetArguments().Slice()
if want, got := len(args), len(args2); got != want {
t.Errorf("len(args2): %d, expected %d", got, want)
}
}
}

func truncate(s string, n int) string {
if len(s) > n {
s = s[:n] + "…"
}
return s
}
Loading