Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bkietz opened this issue Sep 3, 2024 · 0 comments
Open

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

bkietz opened this issue Sep 3, 2024 · 0 comments

Comments

@bkietz
Copy link
Contributor

bkietz commented Sep 3, 2024

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.

bkietz added a commit to apache/arrow-nanoarrow that referenced this issue Sep 4, 2024
During encoding, `Field.nullable` was not coerced to 0 or 1 (I was
expecting `flatcc` to do that). However the Go reader recognizes
anything other than `Field.nullable == 1` as a non-nullable field
google/flatbuffers#8389

some typos and better error messages are included
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant