mirror of
https://github.com/cubefs/cubefs.git
synced 2026-08-02 02:00:56 +00:00
fix(blobstore): include cap check in alloc tests and reject size <= 0
close #3868 Signed-off-by: yanghonggang <yanghonggang_yewu@cmss.chinamobile.com>
This commit is contained in:
parent
ad376ea9a2
commit
d00e08cc2d
@ -47,7 +47,7 @@ func init() {
|
||||
// GetPool returns a sync.Pool that generates bytes slice with the size.
|
||||
// Return nil if no such pool exists.
|
||||
func GetPool(size int) *sync.Pool {
|
||||
if size < 0 || size > maxSize {
|
||||
if size <= 0 || size > maxSize {
|
||||
return nil
|
||||
}
|
||||
bits := msb(size)
|
||||
|
||||
@ -23,13 +23,13 @@ import (
|
||||
func TestUtilBytespool(t *testing.T) {
|
||||
run := func(size int) {
|
||||
buff := bytespool.Alloc(size)
|
||||
if len(buff) != size {
|
||||
if len(buff) != size || cap(buff) != size {
|
||||
t.Fatal(size)
|
||||
}
|
||||
bytespool.Zero(buff)
|
||||
bytespool.Free(buff)
|
||||
bp := bytespool.AllocPointer(size)
|
||||
if len(*bp) != size {
|
||||
if len(*bp) != size || cap(*bp) != size {
|
||||
t.Fatal(size)
|
||||
}
|
||||
bytespool.FreePointer(bp)
|
||||
@ -54,6 +54,7 @@ func TestUtilBytespool(t *testing.T) {
|
||||
for bits := range [27]struct{}{} {
|
||||
run(1 << bits)
|
||||
}
|
||||
bytespool.Free(nil)
|
||||
bytespool.FreePointer(nil)
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user