Commit fc4ba154 authored by Andrew Gerrand's avatar Andrew Gerrand

net: add nil checks to several String methods to avoid panics

Fixes #945.

R=r
CC=golang-dev
https://golang.org/cl/1848049
parent 8b821696
......@@ -30,6 +30,9 @@ type DNSError struct {
}
func (e *DNSError) String() string {
if e == nil {
return "<nil>"
}
s := "lookup " + e.Name
if e.Server != "" {
s += " on " + e.Server
......
......@@ -30,7 +30,12 @@ type IPAddr struct {
// Network returns the address's network name, "ip".
func (a *IPAddr) Network() string { return "ip" }
func (a *IPAddr) String() string { return a.IP.String() }
func (a *IPAddr) String() string {
if a == nil {
return "<nil>"
}
return a.IP.String()
}
func (a *IPAddr) family() int {
if a == nil || len(a.IP) <= 4 {
......
......@@ -129,6 +129,9 @@ type OpError struct {
}
func (e *OpError) String() string {
if e == nil {
return "<nil>"
}
s := e.Op
if e.Net != "" {
s += " " + e.Net
......@@ -164,6 +167,9 @@ type AddrError struct {
}
func (e *AddrError) String() string {
if e == nil {
return "<nil>"
}
s := e.Error
if e.Addr != "" {
s += " " + e.Addr
......
......@@ -30,7 +30,12 @@ type TCPAddr struct {
// Network returns the address's network name, "tcp".
func (a *TCPAddr) Network() string { return "tcp" }
func (a *TCPAddr) String() string { return joinHostPort(a.IP.String(), itoa(a.Port)) }
func (a *TCPAddr) String() string {
if a == nil {
return "<nil>"
}
return joinHostPort(a.IP.String(), itoa(a.Port))
}
func (a *TCPAddr) family() int {
if a == nil || len(a.IP) <= 4 {
......
......@@ -30,7 +30,12 @@ type UDPAddr struct {
// Network returns the address's network name, "udp".
func (a *UDPAddr) Network() string { return "udp" }
func (a *UDPAddr) String() string { return joinHostPort(a.IP.String(), itoa(a.Port)) }
func (a *UDPAddr) String() string {
if a == nil {
return "<nil>"
}
return joinHostPort(a.IP.String(), itoa(a.Port))
}
func (a *UDPAddr) family() int {
if a == nil || len(a.IP) <= 4 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment