diff --git a/zapio/writer.go b/zapio/writer.go index 29699c86d..8b2911564 100644 --- a/zapio/writer.go +++ b/zapio/writer.go @@ -23,6 +23,7 @@ package zapio import ( "bytes" "io" + "unsafe" "go.uber.org/zap" "go.uber.org/zap/zapcore" @@ -114,7 +115,10 @@ func (w *Writer) flush(allowEmpty bool) { } func (w *Writer) log(b []byte) { - if ce := w.Log.Check(w.Level, string(b)); ce != nil { + // This is unsafe, but the contract is that a CheckedEntry is no longer + // valid once we call ce.Write, so it promises not to reuse this + // string. + if ce := w.Log.Check(w.Level, *(*string)(unsafe.Pointer(&b))); ce != nil { ce.Write() } }