fix(peer) perform bounds check on peer Id when printing String
Brian Tiger Chow committed
Oct 28, 2014 at 00:30 UTC
0aff6873dd46a9f7215a4494352a7ff9e9f7eb3c
1 file changed
+6
-1
peer/peer.go
+6
-1
@@ -116,7 +116,12 @@ type peer struct {
116
117
// String prints out the peer.
118
func (p *peer) String() string {
119
- return "[Peer " + p.id.String()[:12] + "]"
119
+ pid := p.id.String()
120
+ maxRunes := 12
121
+ if len(pid) < maxRunes {
122
+ maxRunes = len(pid)
123
+ }
124
+ return "[Peer " + pid[:maxRunes] + "]"
125
}
126
127
// Key returns the ID as a Key (string) for maps.