Commit f189308f authored by Rob Pike's avatar Rob Pike

fmt: Scan(&int) was mishandling a lone zero.

It took it as an octal base prefix but assumed more digits were coming.
Fixes #2077.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/4764044
parent 8c5c3c50
...@@ -550,10 +550,12 @@ func (s *ss) getBase(verb int) (base int, digits string) { ...@@ -550,10 +550,12 @@ func (s *ss) getBase(verb int) (base int, digits string) {
// scanNumber returns the numerical string with specified digits starting here. // scanNumber returns the numerical string with specified digits starting here.
func (s *ss) scanNumber(digits string, haveDigits bool) string { func (s *ss) scanNumber(digits string, haveDigits bool) string {
if !haveDigits {
s.notEOF() s.notEOF()
if !haveDigits && !s.accept(digits) { if !s.accept(digits) {
s.errorString("expected integer") s.errorString("expected integer")
} }
}
for s.accept(digits) { for s.accept(digits) {
} }
return s.buf.String() return s.buf.String()
......
...@@ -298,6 +298,8 @@ var scanfTests = []ScanfTest{ ...@@ -298,6 +298,8 @@ var scanfTests = []ScanfTest{
// Fixed bugs // Fixed bugs
{"%d\n", "27\n", &intVal, 27}, // ok {"%d\n", "27\n", &intVal, 27}, // ok
{"%d\n", "28 \n", &intVal, 28}, // was: "unexpected newline" {"%d\n", "28 \n", &intVal, 28}, // was: "unexpected newline"
{"%v", "0", &intVal, 0}, // was: "EOF"; 0 was taken as base prefix and not counted.
{"%v", "0", &uintVal, uint(0)}, // was: "EOF"; 0 was taken as base prefix and not counted.
} }
var overflowTests = []ScanTest{ var overflowTests = []ScanTest{
......
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