mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +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) {
|
||||
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:]))
|
||||
|
||||
@@ -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:])))
|
||||
|
||||
Reference in New Issue
Block a user