mirror of
https://github.com/jackc/pgx.git
synced 2025-05-31 11:42:24 +00:00
Fix pgtype.Inet.AssignTo assigning reference
AssignTo should always assign copy. Added documentation for AssignTo interface.
This commit is contained in:
parent
e5c48b17f2
commit
52b58b88a6
@ -70,13 +70,19 @@ func (src *Inet) AssignTo(dst interface{}) error {
|
||||
case Present:
|
||||
switch v := dst.(type) {
|
||||
case *net.IPNet:
|
||||
*v = *src.IPNet
|
||||
*v = net.IPNet{
|
||||
IP: make(net.IP, len(src.IPNet.IP)),
|
||||
Mask: make(net.IPMask, len(src.IPNet.Mask)),
|
||||
}
|
||||
copy(v.IP, src.IPNet.IP)
|
||||
copy(v.Mask, src.IPNet.Mask)
|
||||
return nil
|
||||
case *net.IP:
|
||||
if oneCount, bitCount := src.IPNet.Mask.Size(); oneCount != bitCount {
|
||||
return fmt.Errorf("cannot assign %v to %T", src, dst)
|
||||
}
|
||||
*v = src.IPNet.IP
|
||||
*v = make(net.IP, len(src.IPNet.IP))
|
||||
copy(*v, src.IPNet.IP)
|
||||
return nil
|
||||
default:
|
||||
if nextDst, retry := GetAssignToDstType(dst); retry {
|
||||
|
@ -89,7 +89,8 @@ type Value interface {
|
||||
// possible, then Get() returns Value.
|
||||
Get() interface{}
|
||||
|
||||
// AssignTo converts and assigns the Value to dst.
|
||||
// AssignTo converts and assigns the Value to dst. It MUST make a deep copy of
|
||||
// any reference types.
|
||||
AssignTo(dst interface{}) error
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user