Commit ce26522f authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 23d09bcd
This diff is collapsed.
...@@ -338,6 +338,9 @@ type decoder struct { ...@@ -338,6 +338,9 @@ type decoder struct {
// size that will be checked for overflow at current overflow check point // size that will be checked for overflow at current overflow check point
overflowCheckSize size overflowCheckSize size
// whether overflow was already checked for current decodings
overflowChecked bool
commonCoder commonCoder
} }
...@@ -493,7 +496,9 @@ func (d *decoder) genBasic(assignto string, typ *types.Basic, userType types.Typ ...@@ -493,7 +496,9 @@ func (d *decoder) genBasic(assignto string, typ *types.Basic, userType types.Typ
dataptr := fmt.Sprintf("data[%v:]", d.n) dataptr := fmt.Sprintf("data[%v:]", d.n)
decoded := fmt.Sprintf(basic.decode, dataptr) decoded := fmt.Sprintf(basic.decode, dataptr)
d.n += basic.wireSize d.n += basic.wireSize
if !d.overflowChecked {
d.overflowCheckSize.Add(basic.wireSize) d.overflowCheckSize.Add(basic.wireSize)
}
if userType != nil && userType != typ { if userType != nil && userType != typ {
// userType is a named type over some basic, like // userType is a named type over some basic, like
// type ClusterState int32 // type ClusterState int32
...@@ -601,50 +606,34 @@ func (d *decoder) genSlice(assignto string, typ *types.Slice, obj types.Object) ...@@ -601,50 +606,34 @@ func (d *decoder) genSlice(assignto string, typ *types.Slice, obj types.Object)
d.emit("{") d.emit("{")
d.genBasic("l:", types.Typ[types.Uint32], nil) d.genBasic("l:", types.Typ[types.Uint32], nil)
/*
d.emit("data = data[%v:]", d.pos.num)
d.emit("%v += %v", d.var_("nread"), d.pos.num)
d.flushOverflow()
d.pos = size{} // zero
*/
d.resetPos() d.resetPos()
//d.overflowCheckpoint()
//d.pos.AddExpr("l") // FIXME l*sizeof(elem)
/*
elemSize, elemFixed := typeSizeFixed(typ.Elem()) elemSize, elemFixed := typeSizeFixed(typ.Elem())
// if size(item)==const - check l in one go // if size(item)==const - check l in one go
overflowChecked := d.overflowChecked
if elemFixed { if elemFixed {
d.emit("if len(data) < l*%v { goto overflow }", elemSize) d.overflowCheckpoint()
d.overflowCheckSize.AddExpr("l * %v", elemSize)
d.overflowChecked = true
} }
// TODO ^^^ then skip inner overflow checks
*/
d.emit("%v= make(%v, l)", assignto, typeName(typ)) d.emit("%v= make(%v, l)", assignto, typeName(typ))
d.emit("for i := 0; uint32(i) < l; i++ {") d.emit("for i := 0; uint32(i) < l; i++ {")
d.emit("a := &%s[i]", assignto) d.emit("a := &%s[i]", assignto)
/* if !elemFixed {
d.flushOverflow()
d.pos = size{} // zero
*/
d.overflowCheckpoint() d.overflowCheckpoint()
}
d.resetPos() d.resetPos()
codegenType("(*a)", typ.Elem(), obj, d) codegenType("(*a)", typ.Elem(), obj, d)
/*
d.emit("data = data[%v:]", d.pos.num) // FIXME wrt slice of slice ?
d.emit("%v += %v", d.var_("nread"), d.pos.num)
*/
d.resetPos() d.resetPos()
d.emit("}") d.emit("}")
//d.overflowCheckpoint() d.overflowChecked = overflowChecked
//d.resetPos()
//d.emit("%v= string(data[:l])", assignto) //d.emit("%v= string(data[:l])", assignto)
d.emit("}") d.emit("}")
......
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