This repository was archived by the owner on Feb 12, 2022. It is now read-only.
Fix some printf formatting codes for size_t/ssize_t. - #17
Open
Smattr wants to merge 1 commit into
Open
Conversation
This commit switches to using "%zu" and "%zd" for printing size_t and ssize_t, respectively. These format codes are more portable than "%u" or "%d". For example, on x86_64 size_ts and ssize_ts are 64-bit values, while ints are 32-bit values. In practice, this does not cause problems in the x86_64 System V ABI because 32-bit values are naturally extended in this scenario, but on other platforms it can cause stack corruption.
Contributor
|
Unfortunately, the "z" length specifier appears to have been added in C99. As this library needs to maintain compatibility with certain C89 compilers, implementing a change like this one would also require adding some additional checks to make sure its supported by the compiler. |
Contributor
Author
|
Interesting, I was not aware of this nuance. If maintaining C89 compatibility is a concern, my inclination would be not to do these changes but to instead cast the affected parameters to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit switches to using "%zu" and "%zd" for printing size_t and ssize_t,
respectively. These format codes are more portable than "%u" or "%d". For
example, on x86_64 size_ts and ssize_ts are 64-bit values, while ints are 32-bit
values. In practice, this does not cause problems in the x86_64 System V ABI
because 32-bit values are naturally extended in this scenario, but on other
platforms it can cause stack corruption.
If you're happy to accept this, I believe I need to sign a CLA, but it's not clear to me where to get this from. Are you able to point me in the right direction? Thanks.Also, I inadvertently picked this up after slapping
__attribute__((format(printf, 3, 4)))on thesignal_logdeclaration. I assumed you don't want GNU-isms like this in the code base so I didn't commit this as well, but please let me know if you'd like me to include that change as well.