From f1926b033fb1792077c2a08f951308faecb87c32 Mon Sep 17 00:00:00 2001 From: Geoffrey Beausire Date: Wed, 20 Apr 2022 15:46:16 +0200 Subject: [PATCH] Divide by 2 randomHex allocations --- pkg/utils/utils.go | 2 +- pkg/utils/utils_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 38d3e9e..ab4f7ee 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -24,7 +24,7 @@ func Contains(s []string, e string) bool { } func RandomHex(n int) string { - bytes := make([]byte, n) + bytes := make([]byte, n/2+n%2) if _, err := rand.Read(bytes); err != nil { PanicOnError(err) } diff --git a/pkg/utils/utils_test.go b/pkg/utils/utils_test.go index 0b3f58c..0930fe2 100644 --- a/pkg/utils/utils_test.go +++ b/pkg/utils/utils_test.go @@ -19,7 +19,7 @@ func TestRandomHexWorks(t *testing.T) { re, _ := regexp.Compile("^[a-f0-9]{77}$") hex := utils.RandomHex(77) if !re.MatchString(hex) { - t.Errorf("RandomHex doesn't work, generated hex: %s", hex) + t.Errorf("RandomHex doesn't work, generated hex: %s (size:%d)", hex, len(hex)) } }