| 1 |
package a |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"net" |
| 6 |
) |
| 7 |
|
| 8 |
func direct(host string, port int, portStr string) { |
| 9 |
// Dial, directly called with result of Sprintf. |
| 10 |
net.Dial("tcp", net.JoinHostPort(host, fmt.Sprintf("%d", port))) // want `address format "%s:%d" does not work with IPv6` |
| 11 |
|
| 12 |
net.Dial("tcp", net.JoinHostPort(host, portStr)) // want `address format "%s:%s" does not work with IPv6` |
| 13 |
} |
| 14 |
|
| 15 |
// port is a literal: |
| 16 |
var addr4 = net.JoinHostPort("localhost", "123") // want `address format "%s:%d" does not work with IPv6 \(passed to net.Dial at L39\)` |
| 17 |
|
| 18 |
func indirect(host string, port int) { |
| 19 |
// Dial, addr is immediately preceding. |
| 20 |
{ |
| 21 |
addr1 := net.JoinHostPort(host, fmt.Sprintf("%d", port)) // want `address format "%s:%d" does not work with IPv6.*at L22` |
| 22 |
net.Dial("tcp", addr1) |
| 23 |
} |
| 24 |
|
| 25 |
// DialTimeout, addr is in ancestor block. |
| 26 |
addr2 := net.JoinHostPort(host, fmt.Sprintf("%d", port)) // want `address format "%s:%d" does not work with IPv6.*at L28` |
| 27 |
{ |
| 28 |
net.DialTimeout("tcp", addr2, 0) |
| 29 |
} |
| 30 |
|
| 31 |
// Dialer.Dial, addr is declared with var. |
| 32 |
var dialer net.Dialer |
| 33 |
{ |
| 34 |
var addr3 = net.JoinHostPort(host, fmt.Sprintf("%d", port)) // want `address format "%s:%d" does not work with IPv6.*at L35` |
| 35 |
dialer.Dial("tcp", addr3) |
| 36 |
} |
| 37 |
|
| 38 |
// Dialer.Dial again, addr is declared at package level. |
| 39 |
dialer.Dial("tcp", addr4) |
| 40 |
} |
| 41 |
|
| 42 |
// Regression tests for crashes in well-typed code that nonetheless mis-uses Sprintf: |
| 43 |
// too few arguments, or port is not an integer. |
| 44 |
var ( |
| 45 |
_, _ = net.Dial("tcp", fmt.Sprintf("%s:%d")) |
| 46 |
_, _ = net.Dial("tcp", fmt.Sprintf("%s:%d", "host")) |
| 47 |
_, _ = net.Dial("tcp", net.JoinHostPort("host", fmt.Sprintf("%d", "port"))) // want `address format "%s:%d" does not work with IPv6` |
| 48 |
) |
| 49 |
|
| 50 |
func _() { |
| 51 |
// port is a non-constant literal |
| 52 |
const port = 0x7B |
| 53 |
_, _ = net.Dial("tcp", net.JoinHostPort("localhost", fmt.Sprintf("%d", port))) // want `address format "%s:%d" does not work with IPv6` |
| 54 |
} |