From 7300b43c2baa431c1d8138d76018cc4e41010653 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 5 Mar 2012 12:20:58 -0800 Subject: [PATCH] net: remove more use of fmt Also add a TODO for the broken *dnsMsg String method. R=golang-dev, rsc, borman CC=golang-dev https://golang.org/cl/5720075 --- src/pkg/net/dnsmsg.go | 18 +++++++++--------- src/pkg/net/dnsmsg_test.go | 2 ++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/pkg/net/dnsmsg.go b/src/pkg/net/dnsmsg.go index 97c5062103..4d1c8371ef 100644 --- a/src/pkg/net/dnsmsg.go +++ b/src/pkg/net/dnsmsg.go @@ -24,8 +24,6 @@ package net import ( - "fmt" - "os" "reflect" ) @@ -394,7 +392,7 @@ func packStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok bool) f := val.Type().Field(i) switch fv := val.Field(i); fv.Kind() { default: - fmt.Fprintf(os.Stderr, "net: dns: unknown packing type %v", f.Type) + println("net: dns: unknown packing type", f.Type.String()) return len(msg), false case reflect.Struct: off, ok = packStructValue(fv, msg, off) @@ -418,7 +416,7 @@ func packStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok bool) off += 4 case reflect.Array: if fv.Type().Elem().Kind() != reflect.Uint8 { - fmt.Fprintf(os.Stderr, "net: dns: unknown packing type %v", f.Type) + println("net: dns: unknown packing type", f.Type.String()) return len(msg), false } n := fv.Len() @@ -433,7 +431,7 @@ func packStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok bool) s := fv.String() switch f.Tag { default: - fmt.Fprintf(os.Stderr, "net: dns: unknown string tag %v", f.Tag) + println("net: dns: unknown string tag", string(f.Tag)) return len(msg), false case `net:"domain-name"`: off, ok = packDomainName(s, msg, off) @@ -471,7 +469,7 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok boo f := val.Type().Field(i) switch fv := val.Field(i); fv.Kind() { default: - fmt.Fprintf(os.Stderr, "net: dns: unknown packing type %v", f.Type) + println("net: dns: unknown packing type", f.Type.String()) return len(msg), false case reflect.Struct: off, ok = unpackStructValue(fv, msg, off) @@ -491,7 +489,7 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok boo off += 4 case reflect.Array: if fv.Type().Elem().Kind() != reflect.Uint8 { - fmt.Fprintf(os.Stderr, "net: dns: unknown packing type %v", f.Type) + println("net: dns: unknown packing type", f.Type.String()) return len(msg), false } n := fv.Len() @@ -504,7 +502,7 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok boo var s string switch f.Tag { default: - fmt.Fprintf(os.Stderr, "net: dns: unknown string tag %v", f.Tag) + println("net: dns: unknown string tag", string(f.Tag)) return len(msg), false case `net:"domain-name"`: s, off, ok = unpackDomainName(msg, off) @@ -560,7 +558,9 @@ func printStructValue(val reflect.Value) string { i := fv.Interface().([]byte) s += IP(i).String() } else { - s += fmt.Sprint(fval.Interface()) + // TODO(bradfitz,rsc): this next line panics (the String method of + // *dnsMsg has been broken for awhile). Rewrite, ditch reflect. + //s += fmt.Sprint(fval.Interface()) } } s += "}" diff --git a/src/pkg/net/dnsmsg_test.go b/src/pkg/net/dnsmsg_test.go index 06152a01a2..58f53b7419 100644 --- a/src/pkg/net/dnsmsg_test.go +++ b/src/pkg/net/dnsmsg_test.go @@ -19,6 +19,7 @@ func TestDNSParseSRVReply(t *testing.T) { if !ok { t.Fatalf("unpacking packet failed") } + msg.String() // exercise this code path if g, e := len(msg.answer), 5; g != e { t.Errorf("len(msg.answer) = %d; want %d", g, e) } @@ -50,6 +51,7 @@ func TestDNSParseCorruptSRVReply(t *testing.T) { if !ok { t.Fatalf("unpacking packet failed") } + msg.String() // exercise this code path if g, e := len(msg.answer), 5; g != e { t.Errorf("len(msg.answer) = %d; want %d", g, e) } -- 2.50.0