1
0

small fixes

This commit is contained in:
Arpad Ryszka 2026-03-14 23:29:29 +01:00
parent 1708898c2d
commit 52f004dad8
4 changed files with 27 additions and 7 deletions

View File

@ -25,4 +25,4 @@ bench: $(sources)
clean:
go clean
rm .cover
rm -f .cover

View File

@ -2,6 +2,7 @@ package buffer
import (
"errors"
"fmt"
"io"
)
@ -56,6 +57,17 @@ func (c *content) writeTo() {
r: c.w,
}
defer func() {
r := recover()
if r == nil {
return
}
err := fmt.Errorf("panic provided WriterTo: %v", r)
w.w <- syncMessage{err: err}
close(w.w)
}()
var sm syncMessage
_, err := c.wrt.WriteTo(w)
if err != nil {

12
pool.go
View File

@ -1,6 +1,9 @@
package buffer
import "sync"
import (
"errors"
"sync"
)
type noPool struct {
allocSize int
@ -28,7 +31,12 @@ func (noPool) Put([]byte) {
}
func (p *pool) Get() ([]byte, error) {
return p.sp.Get().([]byte), nil
b, ok := p.sp.Get().([]byte)
if !ok {
return nil, errors.New("invalid resource received from pool")
}
return b, nil
}
func (p *pool) Put(b []byte) {

View File

@ -410,17 +410,17 @@ func (r *reader) readUTF8(max int) ([]rune, int, error) {
break
}
r, s := utf8.DecodeRune(b)
if r == utf8.RuneError && s == 1 && len(runes) == 0 {
rn, s := utf8.DecodeRune(b)
if rn == utf8.RuneError && s == 1 && len(runes) == 0 {
n = 1
break
}
if r == utf8.RuneError && s == 1 {
if rn == utf8.RuneError && s == 1 {
break
}
runes = append(runes, r)
runes = append(runes, rn)
n += s
}