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

Don't use signed char for byte buffers #218

Closed
etremel opened this issue Nov 5, 2021 · 2 comments
Closed

Don't use signed char for byte buffers #218

etremel opened this issue Nov 5, 2021 · 2 comments

Comments

@etremel
Copy link
Contributor

etremel commented Nov 5, 2021

Throughout our codebase, we have been using arrays of char (or pointers to char) to represent byte buffers. However, it has long been the consensus in C++ programming that the signed char type should only be used for actual characters, and unsigned char should be used for bytes (see this question for example). Now that uint8_t is widely supported, it makes even less sense to keep using char for bytes, because uint8_t is a lot easier to type than unsigned char and we use the fixed-size data types everywhere else we care about the size of our data in memory (e.g. uint32_t, uint64_t).

Although it will be tedious, we should really take the time to go through and replace all our byte buffers with uint8_t.

@KenBirman
Copy link
Contributor

KenBirman commented Nov 5, 2021 via email

etremel added a commit that referenced this issue Jan 22, 2022
Our codebase has consistently used arrays of char for "byte arrays" when
in fact char is the wrong type to use for raw bytes, as reported in
issue #218. I've replaced every instance I could find of char* or char[]
being used for "array of bytes" with uint8_t* or uint8_t[], while
leaving the char arrays that actually represent strings of characters
(i.e. C-style strings) as char arrays.
@etremel
Copy link
Contributor Author

etremel commented Mar 17, 2022

Fixed by ed8b2ea

@etremel etremel closed this as completed Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants