diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2018-01-24 11:35:22 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-01-24 11:35:22 +0100 |
| commit | ca9c302d807f47a55552d0a20a2dfcdb0fcc6e28 (patch) | |
| tree | 2eb665c4c58d338671dedf8c70d617eebab2e202 /prog | |
| parent | e5b101ddff108ef913e8f7c6085eac52498443a0 (diff) | |
pkg/compiler, prog: fix template parent lens
It's possible that a struct can have 2+ parents,
which is the same template (differs only by arguments).
See the new test case.
Support such case.
Diffstat (limited to 'prog')
| -rw-r--r-- | prog/size.go | 8 | ||||
| -rw-r--r-- | prog/size_test.go | 4 |
2 files changed, 11 insertions, 1 deletions
diff --git a/prog/size.go b/prog/size.go index 36928a8bc..e2451fe15 100644 --- a/prog/size.go +++ b/prog/size.go @@ -5,6 +5,7 @@ package prog import ( "fmt" + "strings" ) func (target *Target) generateSize(arg Arg, lenType *LenType) uint64 { @@ -67,7 +68,12 @@ func (target *Target) assignSizes(args []Arg, parentsMap map[Arg]Arg) { sizeAssigned := false for parent := parentsMap[arg]; parent != nil; parent = parentsMap[parent] { - if typ.Buf == parent.Type().Name() { + parentName := parent.Type().Name() + if pos := strings.IndexByte(parentName, '['); pos != -1 { + // For template parents, strip arguments. + parentName = parentName[:pos] + } + if typ.Buf == parentName { a.Val = parent.Size() if typ.BitSize != 0 { a.Val = a.Val * 8 / typ.BitSize diff --git a/prog/size_test.go b/prog/size_test.go index 8f472491d..2ab28b90b 100644 --- a/prog/size_test.go +++ b/prog/size_test.go @@ -130,6 +130,10 @@ func TestAssignSize(t *testing.T) { "syz_test$length23(&(0x7f0000000000)={0x1, {0x2, 0x0}})", "syz_test$length23(&(0x7f0000000000)={0x1, {0x2, 0x6}})", }, + { + "syz_test$length24(&(0x7f0000000000)={{0x0, {0x0}}, {0x0, {0x0}}})", + "syz_test$length24(&(0x7f0000000000)={{0x0, {0x8}}, {0x0, {0xc}}})", + }, } for i, test := range tests { |
