Skip to content

fmt: scan mishandles width for %d #9444

@robpike

Description

@robpike

http://play.golang.org/p/WlMpKiMGIv fails but if the format for the integer is %d rather than %5d, it works fine.

Snippet here reproduced here for clarity:

package main

import "fmt"

func main() {
format := "%6s%5d"
// "ssssssddddd"
line := "some 3"

var str string
var numb int64

n, err := fmt.Sscanf(line, format, &str, &numb)

fmt.Println(n, err)
fmt.Println(str, numb)  

}

The use of widths vs. space-separated tokens confuses. It's possible this is working as intended but if so it needs to be explained. I believe it's a bug.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions