Skip to content

fmt: Printf("%02x") applied to []byte{} is equivalent to []byte{0} #76740

@adonovan

Description

@adonovan

https://go.dev/play/p/yAGvguDS5Uc

	slice := []byte("hello")
	for i := range slice {
		fmt.Printf("%[1]q\t%02[1]x\n", slice[:len(slice)-1-i])
	}
"hell"	68656c6c
"hel"	68656c
"he"	6865
"h"		68
""		00

The fmt docs don't go into detail on exactly what Printf should do here, but the behavior in the zero case is surprisingly non-monotonic, and seems to me to be a bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions