Skip to content

Commit

Permalink
[]byte is wider than string, so newer versions of -race correctly cal…
Browse files Browse the repository at this point in the history
…l us out for converting to []byte
  • Loading branch information
kungfusheep committed Feb 4, 2021
1 parent cfca0b3 commit 8f3924c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ptrconvert.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func ptrFloat64ToBuf(v unsafe.Pointer, b *Buffer) {
}

func ptrStringToBuf(v unsafe.Pointer, b *Buffer) {
b.Write(*(*[]byte)(v))
b.WriteString(*(*string)(v))
}

func ptrTimeToBuf(v unsafe.Pointer, b *Buffer) {
Expand Down
7 changes: 3 additions & 4 deletions structencoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ func (e *StructEncoder) optInstrStringer() {
if !ok {
return
}
sr := e.String()
w.Write(*(*[]byte)(unsafe.Pointer(&sr)))
w.WriteString(e.String())
}

if e.f.Type.Kind() == reflect.Ptr {
Expand Down Expand Up @@ -151,12 +150,12 @@ func (e *StructEncoder) optInstrEncoder() {

func (e *StructEncoder) optInstrRaw() {
conv := func(v unsafe.Pointer, w *Buffer) {
s := *(*[]byte)(v)
s := *(*string)(v)
if len(s) == 0 {
w.Write(null)
return
}
w.Write(s)
w.WriteString(s)
}

if e.f.Type.Kind() == reflect.Ptr {
Expand Down

0 comments on commit 8f3924c

Please sign in to comment.