From 2532a37945fa6b648e18c392d426fe37b389244f Mon Sep 17 00:00:00 2001 From: Jack Palevich Date: Thu, 22 Apr 2010 20:32:37 +0800 Subject: [PATCH] Handle zero-length strings in bencode data. Improve error reporting slightly. --- parse.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/parse.go b/parse.go index 7eabbf7..3dcdacc 100644 --- a/parse.go +++ b/parse.go @@ -10,6 +10,7 @@ package bencode import ( "bufio" "bytes" + "fmt" "io" "os" "strconv" @@ -110,7 +111,7 @@ Switch: goto exit } switch { - case c >= '1' && c <= '9': + case c >= '0' && c <= '9': // String err = r.UnreadByte() if err != nil { @@ -193,7 +194,7 @@ Switch: n++ } default: - err = os.NewError("Unexpected character") + err = os.NewError(fmt.Sprintf("Unexpected character: '%v'", c)) } exit: build.Flush()