internal/ops: remove some bounds checks

Currently BCE is unable to understand that the accesses in the code are
safe. Added an explicit slice to make the length bounds obvious.

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
This commit is contained in:
Egon Elbre
2020-11-24 14:13:09 +01:00
committed by Elias Naur
parent 918a5da308
commit 21dc27b115
2 changed files with 8 additions and 8 deletions
+6 -8
View File
@@ -24,6 +24,7 @@ func (q Quad) Transform(t f32.Affine2D) Quad {
}
func EncodeQuad(d []byte, q Quad) {
d = d[:24]
bo := binary.LittleEndian
bo.PutUint32(d[0:], math.Float32bits(q.From.X))
bo.PutUint32(d[4:], math.Float32bits(q.From.Y))
@@ -34,6 +35,7 @@ func EncodeQuad(d []byte, q Quad) {
}
func DecodeQuad(d []byte) (q Quad) {
d = d[:24]
bo := binary.LittleEndian
q.From.X = math.Float32frombits(bo.Uint32(d[0:]))
q.From.Y = math.Float32frombits(bo.Uint32(d[4:]))
@@ -44,17 +46,13 @@ func DecodeQuad(d []byte) (q Quad) {
return
}
func DecodeTransform(d []byte) (t f32.Affine2D) {
if opconst.OpType(d[0]) != opconst.TypeTransform {
func DecodeTransform(data []byte) (t f32.Affine2D) {
if opconst.OpType(data[0]) != opconst.TypeTransform {
panic("invalid op")
}
if len(d) < 1+6*4 {
panic("too short buffer")
}
return decodeAffine2D(d[1:])
}
data = data[1:]
data = data[:4*6]
func decodeAffine2D(data []byte) f32.Affine2D {
bo := binary.LittleEndian
a := math.Float32frombits(bo.Uint32(data))
b := math.Float32frombits(bo.Uint32(data[4*1:]))
+2
View File
@@ -143,6 +143,7 @@ func (op *opMacroDef) decode(data []byte) {
panic("invalid op")
}
bo := binary.LittleEndian
data = data[:9]
dataIdx := int(int32(bo.Uint32(data[1:])))
refsIdx := int(int32(bo.Uint32(data[5:])))
*op = opMacroDef{
@@ -157,6 +158,7 @@ func (m *macroOp) decode(data []byte, refs []interface{}) {
if opconst.OpType(data[0]) != opconst.TypeCall {
panic("invalid op")
}
data = data[:9]
bo := binary.LittleEndian
dataIdx := int(int32(bo.Uint32(data[1:])))
refsIdx := int(int32(bo.Uint32(data[5:])))