Commit cb9c9738 authored by Rob Pike's avatar Rob Pike

don't crash printing a nil map

R=rsc
DELTA=19  (18 added, 0 deleted, 1 changed)
OCL=32656
CL=32670
parent 9dc22b6d
......@@ -270,3 +270,17 @@ func TestMapPrinter(t *testing.T) {
presentInMap(Sprintf("%v", m1), a, t);
presentInMap(Sprint(m1), a, t);
}
func TestEmptyMap(t *testing.T) {
const emptyMapStr = "map[]";
var m map[string]int;
s := Sprint(m);
if s != emptyMapStr {
t.Errorf("nil map printed as %q not %q", s, emptyMapStr);
}
m = make(map[string]int);
s = Sprint(m);
if s != emptyMapStr {
t.Errorf("empty map printed as %q not %q", s, emptyMapStr);
}
}
......@@ -1008,8 +1008,12 @@ func (v *MapValue) Len() int {
func (v *MapValue) Keys() []Value {
tk := v.Type().(*MapType).Key();
m := *(**byte)(v.addr);
mlen := int32(0);
if m != nil {
mlen = maplen(m)
}
it := mapiterinit(m);
a := make([]Value, maplen(m));
a := make([]Value, mlen);
var i int;
for i = 0; i < len(a); i++ {
k := MakeZero(tk);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment