Fix pgtype.Inet.AssignTo assigning reference
AssignTo should always assign copy. Added documentation for AssignTo interface.
This commit is contained in:
@@ -70,13 +70,19 @@ func (src *Inet) AssignTo(dst interface{}) error {
|
|||||||
case Present:
|
case Present:
|
||||||
switch v := dst.(type) {
|
switch v := dst.(type) {
|
||||||
case *net.IPNet:
|
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
|
return nil
|
||||||
case *net.IP:
|
case *net.IP:
|
||||||
if oneCount, bitCount := src.IPNet.Mask.Size(); oneCount != bitCount {
|
if oneCount, bitCount := src.IPNet.Mask.Size(); oneCount != bitCount {
|
||||||
return fmt.Errorf("cannot assign %v to %T", src, dst)
|
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
|
return nil
|
||||||
default:
|
default:
|
||||||
if nextDst, retry := GetAssignToDstType(dst); retry {
|
if nextDst, retry := GetAssignToDstType(dst); retry {
|
||||||
|
|||||||
@@ -89,7 +89,8 @@ type Value interface {
|
|||||||
// possible, then Get() returns Value.
|
// possible, then Get() returns Value.
|
||||||
Get() interface{}
|
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
|
AssignTo(dst interface{}) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user