From 4ea320c784b6f6cc4c91eafc2d73724289606bfc Mon Sep 17 00:00:00 2001 From: PhatPhuckDave <> Date: Mon, 22 Jul 2024 23:13:34 +0200 Subject: [PATCH] Make bufpool use uint I mean we can't have a pool of negative size? --- pdu/bufpool.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pdu/bufpool.go b/pdu/bufpool.go index 6ce6f74..eb0602f 100644 --- a/pdu/bufpool.go +++ b/pdu/bufpool.go @@ -5,17 +5,17 @@ import ( ) type BufferPoolManager struct { - pools map[int]*sync.Pool + pools map[uint]*sync.Pool mu sync.Mutex } func NewBufferPoolManager() *BufferPoolManager { return &BufferPoolManager{ - pools: make(map[int]*sync.Pool), + pools: make(map[uint]*sync.Pool), } } -func (bpm *BufferPoolManager) GetBuffer(size int) *([]uint8) { +func (bpm *BufferPoolManager) GetBuffer(size uint) *([]uint8) { bpm.mu.Lock() pool, exists := bpm.pools[size] if !exists { @@ -32,7 +32,7 @@ func (bpm *BufferPoolManager) GetBuffer(size int) *([]uint8) { } func (bpm *BufferPoolManager) PutBuffer(buf *([]uint8)) { - size := len(*buf) + size := uint(len(*buf)) bpm.mu.Lock() pool, exists := bpm.pools[size] if !exists { @@ -41,7 +41,6 @@ func (bpm *BufferPoolManager) PutBuffer(buf *([]uint8)) { } bpm.mu.Unlock() - // Reset buffer (optional) for i := range *buf { (*buf)[i] = 0 }