Skip to content

Commit

Permalink
fix unsafe code
Browse files Browse the repository at this point in the history
  • Loading branch information
peczenyj committed Nov 10, 2023
1 parent 04c3cff commit 1c92c62
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion join.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,21 @@ func (e *joinError) Error() string {
b = append(b, err.Error()...)
}
// At this point, b has at least one byte '\n'.
return unsafe.String(&b[0], len(b))
return b2s(b)
}

Check failure on line 59 in join.go

View workflow job for this annotation

GitHub Actions / lint

method Unwrap() []error should have signature Unwrap() error
func (e *joinError) Unwrap() []error {
return e.errs
}

// b2s converts byte slice to a string without memory allocation.
// See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .
//
// Note it may break if string and/or slice header will change
// in the future go versions.
//
// original code copied from
// https://github.com/valyala/fasthttp/blob/master/b2s_old.go
func b2s(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}

0 comments on commit 1c92c62

Please sign in to comment.