mirror of https://github.com/vishvananda/netlink
fix. nl.DeserializeRtNexthop return.
Return a full created nl.RtNexthop ptr to avoid the "converted pointer straddles multiple allocations". UT by fasaxc. Co-authored-by: fasaxc Signed-off-by: Javier Garcia <javier.martin.garcia@ibm.com>
This commit is contained in:
parent
836d892b17
commit
c591ada0fb
|
@ -48,7 +48,9 @@ type RtNexthop struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeserializeRtNexthop(b []byte) *RtNexthop {
|
func DeserializeRtNexthop(b []byte) *RtNexthop {
|
||||||
return (*RtNexthop)(unsafe.Pointer(&b[0:unix.SizeofRtNexthop][0]))
|
return &RtNexthop{
|
||||||
|
RtNexthop: *((*unix.RtNexthop)(unsafe.Pointer(&b[0:unix.SizeofRtNexthop][0]))),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *RtNexthop) Len() int {
|
func (msg *RtNexthop) Len() int {
|
||||||
|
|
|
@ -42,3 +42,26 @@ func TestRtMsgDeserializeSerialize(t *testing.T) {
|
||||||
msg := DeserializeRtMsg(orig)
|
msg := DeserializeRtMsg(orig)
|
||||||
testDeserializeSerialize(t, orig, safemsg, msg)
|
testDeserializeSerialize(t, orig, safemsg, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDeserializeRtNexthop(t *testing.T) {
|
||||||
|
buf := make([]byte, unix.SizeofRtNexthop+64)
|
||||||
|
native := NativeEndian()
|
||||||
|
native.PutUint16(buf[0:2], unix.SizeofRtNexthop)
|
||||||
|
buf[2] = 17
|
||||||
|
buf[3] = 1
|
||||||
|
native.PutUint32(buf[4:8], 1234)
|
||||||
|
|
||||||
|
msg := DeserializeRtNexthop(buf)
|
||||||
|
safemsg := &RtNexthop{
|
||||||
|
unix.RtNexthop{
|
||||||
|
Len: unix.SizeofRtNexthop,
|
||||||
|
Flags: 17,
|
||||||
|
Hops: 1,
|
||||||
|
Ifindex: 1234,
|
||||||
|
},
|
||||||
|
nil,
|
||||||
|
}
|
||||||
|
if msg.Len() != safemsg.Len() || msg.Flags != safemsg.Flags || msg.Hops != safemsg.Hops || msg.Ifindex != safemsg.Ifindex {
|
||||||
|
t.Fatal("Deserialization failed.\nIn:", buf, "\nOut:", msg, "\n", msg.Serialize(), "\nExpected:", safemsg, "\n", safemsg.Serialize())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue