Skip to content

Commit

Permalink
fix(zapring): zap ring call only 64bit func
Browse files Browse the repository at this point in the history
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
  • Loading branch information
sfroment committed Nov 12, 2018
1 parent 528432a commit 1085094
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions core/pkg/zapring/zapring.go
Expand Up @@ -9,6 +9,8 @@ import (
"go.uber.org/zap/zapcore"
)

const PtrSize = 32 << uintptr(^uintptr(0)>>63)

type Ring struct {
zapcore.Core
enc zapcore.Encoder
Expand All @@ -32,11 +34,15 @@ func (r *Ring) Check(entry zapcore.Entry, checked *zapcore.CheckedEntry) *zapcor
}

func (r *Ring) Write(entry zapcore.Entry, fields []zapcore.Field) error {
buff, err := r.enc.EncodeEntry(entry, fields)
if err != nil {
return err
// We need to be sure we're in 64-bit since circular buffer call LoadInt64
// so if you're running in 32-bit the app will crash
if PtrSize == 64 {
buff, err := r.enc.EncodeEntry(entry, fields)
if err != nil {
return err
}
r.buffer.Write(buff.Bytes())
}
r.buffer.Write(buff.Bytes())

return r.Core.Write(entry, fields)
}
Expand Down

0 comments on commit 1085094

Please sign in to comment.