feat(core): make Buffer.IsFreed nil-safe
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
65d3825cad
commit
f19b691112
2 changed files with 12 additions and 0 deletions
|
|
@ -123,6 +123,9 @@ func (b *Buffer) Len() int {
|
|||
// buffer := NewBuffer(4)
|
||||
// if buffer.IsFreed() { ... }
|
||||
func (b *Buffer) IsFreed() bool {
|
||||
if b == nil {
|
||||
return true
|
||||
}
|
||||
return b.freed.Load()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -71,6 +71,15 @@ func TestBufferUseAfterFreePanics(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestBufferIsFreedIsNilSafe(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var nilBuffer *Buffer
|
||||
if !nilBuffer.IsFreed() {
|
||||
t.Fatal("expected nil buffer to report freed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCStringRoundTrip(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue