From 5b5a7106c1cdf2d01420de04985f892002e9dd26 Mon Sep 17 00:00:00 2001 From: Anthony De Meulemeester Date: Thu, 5 Apr 2018 10:35:33 +0200 Subject: [PATCH] Fix append for bytearrays (#64) --- VERSION | 2 +- pkg/vm/tests/for_test.go | 15 +++++++++++++++ pkg/vm/vm.go | 3 +++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 4ef2eb086..d2e2400ee 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.39.0 +0.39.1 diff --git a/pkg/vm/tests/for_test.go b/pkg/vm/tests/for_test.go index 1e17b3d5a..6151d28be 100644 --- a/pkg/vm/tests/for_test.go +++ b/pkg/vm/tests/for_test.go @@ -225,6 +225,21 @@ func TestIfUnaryInvert(t *testing.T) { eval(t, src, big.NewInt(0)) } +func TestAppendByte(t *testing.T) { + src := ` + package foo + func Main() []byte { + arr := []byte{0x00, 0x01, 0x02} + arr = append(arr, 0x03) + arr = append(arr, 0x04) + arr = append(arr, 0x05) + arr = append(arr, 0x06) + return arr + } + ` + eval(t, src, []uint8{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06}) +} + func TestAppendString(t *testing.T) { src := ` package foo diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index fa197a323..87be7f2ef 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -483,6 +483,9 @@ func (v *VM) execute(ctx *Context, op Opcode) { arr := t.Value().([]StackItem) arr = append(arr, itemElem.value) v.estack.PushVal(arr) + case *ByteArrayItem: + newVal := append(t.value, itemElem.value.Value().([]byte)...) + v.estack.PushVal(newVal) default: panic("APPEND: not of underlying type Array") }