From 70c104a18f3d409bc6dde950b50258d3d280d99b Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 23 Jul 2020 16:46:09 +0200 Subject: pkg/compiler: fix crash on fmt[flags] Flags with only 1 value 0 are transformed to ConstType. Fmt did not expect that. Fixes #1965 --- pkg/compiler/testdata/all.txt | 3 +++ pkg/compiler/types.go | 6 ++++++ 2 files changed, 9 insertions(+) (limited to 'pkg/compiler') diff --git a/pkg/compiler/testdata/all.txt b/pkg/compiler/testdata/all.txt index f5f3f1070..b9e144d73 100644 --- a/pkg/compiler/testdata/all.txt +++ b/pkg/compiler/testdata/all.txt @@ -294,7 +294,10 @@ foo_fmt2(a ptr[in, fmt[oct, len[b]]], b ptr[in, array[int8]]) foo_fmt3(a ptr[in, fmt[dec, proc[10, 20]]]) foo_fmt4(a ptr[in, fmt[dec, r0]]) foo_fmt5(a ptr[in, struct$fmt0]) +foo_fmt6(a ptr[in, fmt[dec, flags[flags_with_one_value]]]) struct$fmt0 { f0 fmt[dec, int8] } + +flags_with_one_value = 0 diff --git a/pkg/compiler/types.go b/pkg/compiler/types.go index 122c4a9d4..3c22038f8 100644 --- a/pkg/compiler/types.go +++ b/pkg/compiler/types.go @@ -761,6 +761,12 @@ var typeFmt = &typeDesc{ t.ArgFormat = format t.TypeSize = size t.TypeAlign = 1 + case *prog.ConstType: + // We don't allow fmt[const] directly, but flags with only 1 value + // are transformed to ConstType. + t.ArgFormat = format + t.TypeSize = size + t.TypeAlign = 1 default: panic(fmt.Sprintf("unexpected type: %#v", typ)) } -- cgit mrf-deployment