diff --git a/pkg/parse/parse.go b/pkg/parse/parse.go index 4fcbdf4..e9322fa 100644 --- a/pkg/parse/parse.go +++ b/pkg/parse/parse.go @@ -273,7 +273,7 @@ func ReadLog(r io.Reader, w io.Writer, ins *InputSchema, outs *OutputSchema, fil outs.noMessage = ins.NoMessageKey outs.suppressionConfigured = true } - outs.Emit(*toEmit, buf) + outs.Emit(toEmit, buf) } // Copying the buffer to the output writer is handled in defer. @@ -471,9 +471,8 @@ func (s *InputSchema) ReadLine(l *line) error { return retErr } -// Emit emits a formatted line to the provided buffer. The provided line object may not be used -// again until reinitialized. -func (s *OutputSchema) Emit(l line, w *bytes.Buffer) { +// Emit emits a formatted line to the provided buffer. Emit must not mutate line. +func (s *OutputSchema) Emit(l *line, w *bytes.Buffer) { // Is this a line separating unrelated contexts? If so, print a separator and do nothing else. if l.isSeparator { w.WriteString("---\n") diff --git a/pkg/parse/parse_fuzz_test.go b/pkg/parse/parse_fuzz_test.go index 032658e..b693da5 100644 --- a/pkg/parse/parse_fuzz_test.go +++ b/pkg/parse/parse_fuzz_test.go @@ -136,7 +136,7 @@ func FuzzEmit(f *testing.F) { fields: fieldMap, } outbuf := new(bytes.Buffer) - outs.Emit(*l, outbuf) + outs.Emit(l, outbuf) byts := outbuf.Bytes() if len(byts) == 0 { t.Fatal("no output produced") diff --git a/pkg/parse/parse_test.go b/pkg/parse/parse_test.go index cd1ebaf..541ba88 100644 --- a/pkg/parse/parse_test.go +++ b/pkg/parse/parse_test.go @@ -604,7 +604,7 @@ func TestEmit(t *testing.T) { PriorityFields: []string{"baz"}, state: test.state, } - s.Emit(test.line, w) + s.Emit(&test.line, w) if diff := cmp.Diff(w.String(), test.want); diff != "" { t.Errorf("emitted output:\n%v", diff) }