提交 cf844836 编写于 作者: A Alessandro Arzilli 提交者: Derek Parker

proc/variables: bugfix: parsing of maps with zero sized value type (#851)

Buckets of maps with zero sized value types (i.e. map[T]struct{}) have
zero length value arrays.
上级 40b48213
......@@ -220,6 +220,10 @@ func main() {
sliceinf := make([]interface{}, 1)
sliceinf[0] = sliceinf
zsvar := struct{}{}
zsslice := make([]struct{}, 3)
zsvmap := map[string]struct{}{"testkey": struct{}{}}
var amb1 = 1
runtime.Breakpoint()
for amb1 := 0; amb1 < 10; amb1++ {
......@@ -227,5 +231,5 @@ func main() {
}
runtime.Breakpoint()
fmt.Println(i1, i2, i3, p1, amb1, s1, s3, a1, p2, p3, s2, as1, str1, f1, fn1, fn2, nilslice, nilptr, ch1, chnil, m1, mnil, m2, m3, up1, i4, i5, i6, err1, err2, errnil, iface1, iface2, ifacenil, arr1, parr, cpx1, const1, iface3, iface4, recursive1, recursive1.x, iface5, iface2fn1, iface2fn2, bencharr, benchparr, mapinf, mainMenu, b, b2, sd, anonstruct1, anonstruct2, anoniface1, anonfunc, mapanonstruct1, ifacearr, efacearr, ni8, ni16, ni32, pinf, ninf, nan)
fmt.Println(i1, i2, i3, p1, amb1, s1, s3, a1, p2, p3, s2, as1, str1, f1, fn1, fn2, nilslice, nilptr, ch1, chnil, m1, mnil, m2, m3, up1, i4, i5, i6, err1, err2, errnil, iface1, iface2, ifacenil, arr1, parr, cpx1, const1, iface3, iface4, recursive1, recursive1.x, iface5, iface2fn1, iface2fn2, bencharr, benchparr, mapinf, mainMenu, b, b2, sd, anonstruct1, anonstruct2, anoniface1, anonfunc, mapanonstruct1, ifacearr, efacearr, ni8, ni16, ni32, pinf, ninf, nan, zsvmap, zsslice, zsvar)
}
......@@ -1245,7 +1245,12 @@ func (v *Variable) loadMap(recurseLevel int, cfg LoadConfig) {
break
}
key := it.key()
val := it.value()
var val *Variable
if it.values.fieldType.Size() > 0 {
val = it.value()
} else {
val = v.newVariable("", it.values.Addr, it.values.fieldType)
}
key.loadValueInternal(recurseLevel+1, cfg)
val.loadValueInternal(recurseLevel+1, cfg)
if key.Unreadable != nil || val.Unreadable != nil {
......@@ -1425,7 +1430,14 @@ func (it *mapIterator) nextBucket() bool {
return false
}
if it.tophashes.Len != it.keys.Len || it.tophashes.Len != it.values.Len {
if it.tophashes.Len != it.keys.Len {
it.v.Unreadable = mapBucketContentsInconsistentLenErr
return false
}
if it.values.fieldType.Size() > 0 && it.tophashes.Len != it.values.Len {
// if the type of the value is zero-sized (i.e. struct{}) then the values
// array's length is zero.
it.v.Unreadable = mapBucketContentsInconsistentLenErr
return false
}
......
......@@ -691,6 +691,9 @@ func TestEvalExpression(t *testing.T) {
{"ifacearr", false, "[]error len: 2, cap: 2, [*main.astruct {A: 0, B: 0},nil]", "[]error len: 2, cap: 2, [...]", "[]error", nil},
{"efacearr", false, `[]interface {} len: 3, cap: 3, [*main.astruct {A: 0, B: 0},*"test",nil]`, "[]interface {} len: 3, cap: 3, [...]", "[]interface {}", nil},
{"zsslice", false, `[]struct {} len: 3, cap: 3, [{},{},{}]`, `[]struct {} len: 3, cap: 3, [...]`, "[]struct {}", nil},
{"zsvmap", false, `map[string]struct {} ["testkey": {}, ]`, `map[string]struct {} [...]`, "map[string]struct {}", nil},
}
ver, _ := proc.ParseVersionString(runtime.Version())
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册