mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 18:35:34 +00:00
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:
+6
-8
@@ -24,6 +24,7 @@ func (q Quad) Transform(t f32.Affine2D) Quad {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func EncodeQuad(d []byte, q Quad) {
|
func EncodeQuad(d []byte, q Quad) {
|
||||||
|
d = d[:24]
|
||||||
bo := binary.LittleEndian
|
bo := binary.LittleEndian
|
||||||
bo.PutUint32(d[0:], math.Float32bits(q.From.X))
|
bo.PutUint32(d[0:], math.Float32bits(q.From.X))
|
||||||
bo.PutUint32(d[4:], math.Float32bits(q.From.Y))
|
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) {
|
func DecodeQuad(d []byte) (q Quad) {
|
||||||
|
d = d[:24]
|
||||||
bo := binary.LittleEndian
|
bo := binary.LittleEndian
|
||||||
q.From.X = math.Float32frombits(bo.Uint32(d[0:]))
|
q.From.X = math.Float32frombits(bo.Uint32(d[0:]))
|
||||||
q.From.Y = math.Float32frombits(bo.Uint32(d[4:]))
|
q.From.Y = math.Float32frombits(bo.Uint32(d[4:]))
|
||||||
@@ -44,17 +46,13 @@ func DecodeQuad(d []byte) (q Quad) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func DecodeTransform(d []byte) (t f32.Affine2D) {
|
func DecodeTransform(data []byte) (t f32.Affine2D) {
|
||||||
if opconst.OpType(d[0]) != opconst.TypeTransform {
|
if opconst.OpType(data[0]) != opconst.TypeTransform {
|
||||||
panic("invalid op")
|
panic("invalid op")
|
||||||
}
|
}
|
||||||
if len(d) < 1+6*4 {
|
data = data[1:]
|
||||||
panic("too short buffer")
|
data = data[:4*6]
|
||||||
}
|
|
||||||
return decodeAffine2D(d[1:])
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeAffine2D(data []byte) f32.Affine2D {
|
|
||||||
bo := binary.LittleEndian
|
bo := binary.LittleEndian
|
||||||
a := math.Float32frombits(bo.Uint32(data))
|
a := math.Float32frombits(bo.Uint32(data))
|
||||||
b := math.Float32frombits(bo.Uint32(data[4*1:]))
|
b := math.Float32frombits(bo.Uint32(data[4*1:]))
|
||||||
|
|||||||
@@ -143,6 +143,7 @@ func (op *opMacroDef) decode(data []byte) {
|
|||||||
panic("invalid op")
|
panic("invalid op")
|
||||||
}
|
}
|
||||||
bo := binary.LittleEndian
|
bo := binary.LittleEndian
|
||||||
|
data = data[:9]
|
||||||
dataIdx := int(int32(bo.Uint32(data[1:])))
|
dataIdx := int(int32(bo.Uint32(data[1:])))
|
||||||
refsIdx := int(int32(bo.Uint32(data[5:])))
|
refsIdx := int(int32(bo.Uint32(data[5:])))
|
||||||
*op = opMacroDef{
|
*op = opMacroDef{
|
||||||
@@ -157,6 +158,7 @@ func (m *macroOp) decode(data []byte, refs []interface{}) {
|
|||||||
if opconst.OpType(data[0]) != opconst.TypeCall {
|
if opconst.OpType(data[0]) != opconst.TypeCall {
|
||||||
panic("invalid op")
|
panic("invalid op")
|
||||||
}
|
}
|
||||||
|
data = data[:9]
|
||||||
bo := binary.LittleEndian
|
bo := binary.LittleEndian
|
||||||
dataIdx := int(int32(bo.Uint32(data[1:])))
|
dataIdx := int(int32(bo.Uint32(data[1:])))
|
||||||
refsIdx := int(int32(bo.Uint32(data[5:])))
|
refsIdx := int(int32(bo.Uint32(data[5:])))
|
||||||
|
|||||||
Reference in New Issue
Block a user