Commit ce9da214 authored by Rob Pike's avatar Rob Pike

fmt: fix end-of-array error in parsenum.

Fixes #821.

R=rsc
CC=golang-dev
https://golang.org/cl/1434041
parent ebb1c8b9
...@@ -265,6 +265,7 @@ var fmttests = []fmtTest{ ...@@ -265,6 +265,7 @@ var fmttests = []fmtTest{
fmtTest{"no args", "hello", "no args?(extra string=hello)"}, fmtTest{"no args", "hello", "no args?(extra string=hello)"},
fmtTest{"%s", nil, "%s(<nil>)"}, fmtTest{"%s", nil, "%s(<nil>)"},
fmtTest{"%T", nil, "<nil>"}, fmtTest{"%T", nil, "<nil>"},
fmtTest{"%-1", 100, "%1(int=100)"},
} }
func TestSprintf(t *testing.T) { func TestSprintf(t *testing.T) {
......
...@@ -511,19 +511,15 @@ func getComplex128(a interface{}) (val complex128, ok bool) { ...@@ -511,19 +511,15 @@ func getComplex128(a interface{}) (val complex128, ok bool) {
} }
// Convert ASCII to integer. n is 0 (and got is false) if no number present. // Convert ASCII to integer. n is 0 (and got is false) if no number present.
func parsenum(s string, start, end int) (num int, isnum bool, newi int) {
func parsenum(s string, start, end int) (n int, got bool, newi int) {
if start >= end { if start >= end {
return 0, false, end return 0, false, end
} }
isnum := false for newi = start; newi < end && '0' <= s[newi] && s[newi] <= '9'; newi++ {
num := 0 num = num*10 + int(s[newi]-'0')
for '0' <= s[start] && s[start] <= '9' {
num = num*10 + int(s[start]-'0')
start++
isnum = true isnum = true
} }
return num, isnum, start return
} }
type uintptrGetter interface { type uintptrGetter interface {
......
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