Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Go's GetBool() should check for buf[0] != 0 instead of buf[0] == 1 #8389

@bkietz

Description

@bkietz

Go's GetBool() function checks whether a byte is == 1

// GetBool decodes a little-endian bool from a byte slice.
func GetBool(buf []byte) bool {
	return buf[0] == 1
}

This is inconsistent with rust, C++, PHP, Python and is not what I think of as the usual convention of integer-to-boolean conversion.

Alternatively: it could be made explicit that the only legal values for bytes storing booleans are 0 and 1; currently the internals doc is not explicit and no verifiers I have looked at will reject a boolean of (say) 2.

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