Added panic on small buffer for Ping.Marshal.

This commit is contained in:
jdl
2026-06-13 08:43:35 +02:00
parent cbc901496c
commit 98f07457b9

View File

@@ -37,6 +37,8 @@ type Ping struct {
// buf[:Size]. Taking the buffer lets callers reuse one across sends; every // buf[:Size]. Taking the buffer lets callers reuse one across sends; every
// field is written unconditionally so a reused buffer needs no pre-zeroing. // field is written unconditionally so a reused buffer needs no pre-zeroing.
func (p Ping) Marshal(buf []byte) []byte { func (p Ping) Marshal(buf []byte) []byte {
_ = buf[Size-1] // Panic if buffer is too small.
buf[0] = version buf[0] = version
binary.BigEndian.PutUint64(buf[1:9], uint64(p.PingTS)) binary.BigEndian.PutUint64(buf[1:9], uint64(p.PingTS))
if p.SrcV4.IsValid() { if p.SrcV4.IsValid() {