diff options
author | YenForYang <YenForYang@users.noreply.github.com> | 2021-08-26 03:09:45 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-26 10:09:45 +0200 |
commit | c7ce95f778f81d22212a24523dee746b20e91991 (patch) | |
tree | 741a1e3afe9a4c148c8f671ee71474b681eb8fae /bytesconv.go | |
parent | Increase various test timeouts (diff) | |
download | fasthttp-c7ce95f778f81d22212a24523dee746b20e91991.tar.gz fasthttp-c7ce95f778f81d22212a24523dee746b20e91991.tar.bz2 fasthttp-c7ce95f778f81d22212a24523dee746b20e91991.zip |
Fix s2b (#1079)
Ensure `len(b)` <= `cap(b)` at all times. Additionally, use `runtime.KeepAlive()` to prevent `s` from being GC-ed.
Diffstat (limited to 'bytesconv.go')
-rw-r--r-- | bytesconv.go | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/bytesconv.go b/bytesconv.go index 813376e..79896e8 100644 --- a/bytesconv.go +++ b/bytesconv.go @@ -15,6 +15,7 @@ import ( "sync" "time" "unsafe" + "runtime" ) // AppendHTMLEscape appends html-escaped s to dst and returns the extended dst. @@ -345,8 +346,9 @@ func s2b(s string) (b []byte) { /* #nosec G103 */ sh := (*reflect.StringHeader)(unsafe.Pointer(&s)) bh.Data = sh.Data - bh.Len = sh.Len bh.Cap = sh.Len + bh.Len = sh.Len + runtime.KeepAlive(&s) return b } |