diff options
Diffstat (limited to 'libgo/go/fmt/scan.go')
-rw-r--r-- | libgo/go/fmt/scan.go | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/libgo/go/fmt/scan.go b/libgo/go/fmt/scan.go index e3e0fd0b585..4618ed4a827 100644 --- a/libgo/go/fmt/scan.go +++ b/libgo/go/fmt/scan.go @@ -538,7 +538,7 @@ func (s *ss) okVerb(verb rune, okVerbs, typ string) bool { return true } } - s.errorString("bad verb %" + string(verb) + " for " + typ) + s.errorString("bad verb '%" + string(verb) + "' for " + typ) return false } @@ -813,7 +813,7 @@ func (s *ss) scanComplex(verb rune, n int) complex128 { // convertString returns the string represented by the next input characters. // The format of the input is determined by the verb. func (s *ss) convertString(verb rune) (str string) { - if !s.okVerb(verb, "svqx", "string") { + if !s.okVerb(verb, "svqxX", "string") { return "" } s.skipSpace(false) @@ -821,7 +821,7 @@ func (s *ss) convertString(verb rune) (str string) { switch verb { case 'q': str = s.quotedString() - case 'x': + case 'x', 'X': str = s.hexString() default: str = string(s.token(true, notSpace)) // %s and %v just return the next word @@ -1078,6 +1078,10 @@ func (s *ss) advance(format string) (i int) { for i < len(format) { fmtc, w := utf8.DecodeRuneInString(format[i:]) if fmtc == '%' { + // % at end of string is an error. + if i+w == len(format) { + s.errorString("missing verb: % at end of format string") + } // %% acts like a real percent nextc, _ := utf8.DecodeRuneInString(format[i+w:]) // will not match % if string is empty if nextc != '%' { @@ -1179,7 +1183,7 @@ func (s *ss) doScanf(format string, a []interface{}) (numProcessed int, err erro } if numProcessed >= len(a) { // out of operands - s.errorString("too few operands for format %" + format[i-w:]) + s.errorString("too few operands for format '%" + format[i-w:] + "'") break } arg := a[numProcessed] |