Commit b42c8294 authored by Rob Pike's avatar Rob Pike

fmt: fix crash for Printf("%.", 3)

Fixes #5311

R=golang-dev, bradfitz, iant
CC=golang-dev
https://golang.org/cl/8961050
parent 5b78cee3
...@@ -497,6 +497,9 @@ var fmttests = []struct { ...@@ -497,6 +497,9 @@ var fmttests = []struct {
// causing +2+0i and +3+0i instead of 2+0i and 3+0i. // causing +2+0i and +3+0i instead of 2+0i and 3+0i.
{"%v", []complex64{1, 2, 3}, "[(1+0i) (2+0i) (3+0i)]"}, {"%v", []complex64{1, 2, 3}, "[(1+0i) (2+0i) (3+0i)]"},
{"%v", []complex128{1, 2, 3}, "[(1+0i) (2+0i) (3+0i)]"}, {"%v", []complex128{1, 2, 3}, "[(1+0i) (2+0i) (3+0i)]"},
// Incomplete format specification caused crash.
{"%.", 3, "%!.(int=3)"},
} }
func TestSprintf(t *testing.T) { func TestSprintf(t *testing.T) {
......
...@@ -1072,7 +1072,7 @@ func (p *pp) doPrintf(format string, a []interface{}) { ...@@ -1072,7 +1072,7 @@ func (p *pp) doPrintf(format string, a []interface{}) {
p.fmt.wid, p.fmt.widPresent, i = parsenum(format, i, end) p.fmt.wid, p.fmt.widPresent, i = parsenum(format, i, end)
} }
// do we have precision? // do we have precision?
if i < end && format[i] == '.' { if i+1 < end && format[i] == '.' {
if format[i+1] == '*' { if format[i+1] == '*' {
p.fmt.prec, p.fmt.precPresent, i, fieldnum = intFromArg(a, end, i+1, fieldnum) p.fmt.prec, p.fmt.precPresent, i, fieldnum = intFromArg(a, end, i+1, fieldnum)
if !p.fmt.precPresent { if !p.fmt.precPresent {
......
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