Closed
Description
package main
import (
"math"
"sync/atomic"
)
type small struct {
small [64]byte
}
type big struct {
big [math.MaxUint16 * 10]byte
}
func main() {
a := atomic.Pointer[small]{}
a.Store(&small{})
b := atomic.Pointer[big](a) // type conversion
big := b.Load()
for i := range big.big {
big.big[i] = 1
}
}
This sample (on my system) produces a segfault:
[mateusz@arch aa ]$ go run main.go
signal: segmentation fault (core dumped)
So we basically done a unsafe type conversion without using the unsafe package.