Skip to content

Commit

Permalink
fixed old unsafe string
Browse files Browse the repository at this point in the history
  • Loading branch information
Ice3man543 committed Jul 1, 2024
1 parent bdced34 commit 9fa2c40
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions reflect/reflectutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,15 @@ func sizeOf(v reflect.Value, cache map[uintptr]bool) int {

case reflect.String:
s := v.String()
hdr := (*reflect.StringHeader)(unsafe.Pointer(&s))
if cache[hdr.Data] {
ptrData := unsafe.StringData(s)
if ptrData == nil {
return 0
}
stringPtr := uintptr(*ptrData)
if cache[stringPtr] {
return int(v.Type().Size())
}
cache[hdr.Data] = true
cache[stringPtr] = true
return len(s) + int(v.Type().Size())

case reflect.Ptr:
Expand Down

0 comments on commit 9fa2c40

Please sign in to comment.