Open
Conversation
…gfixes) Here, the sub-expression "(1 << i) is interpreted as shifting a signed integer by the unsigned integer value i, according to the ISO/IEC C standard [11, §6.4.4.1]. But when the size of value is 8 byte, i.e. 64 bits, which is the default case, the expression “unsigned int i = sizeof(value) * 8 - 1” evaluates to “unsigned int i = 63”. Thus, in the first iteration of the loop, the integer value 1 (which has 32 bits) is shifted left by 63 bits which is a shift over- flow. However, no error is provoked when compiling the file with the GCC for user space with the proposed compilation flags. But when adding the compiler flag -fsanitize=shift which adds runtime instrumentation for recognising shift overflows and is used by default for compiling Kernel modules, a runtime error (shift-out-of-bounds) is generated. The solution is here to add the suffix “ULL” to the integer constant 1. [11]: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
…gfixes)
Here, the sub-expression "(1 << i) is interpreted as shifting a signed integer by the unsigned integer value i, according to the ISO/IEC C standard [11, §6.4.4.1]. But when the size of value is 8 byte, i.e. 64 bits, which is the default case, the expression “unsigned int i = sizeof(value) * 8 - 1” evaluates to “unsigned int i = 63”. Thus, in the first iteration of the loop, the integer value 1 (which has 32 bits) is shifted left by 63 bits which is a shift over- flow. However, no error is provoked when compiling the file with the GCC for user space with the proposed compilation flags. But when adding the compiler flag -fsanitize=shift which adds runtime instrumentation for recognising shift overflows and is used by default for compiling Kernel modules, a runtime error (shift-out-of-bounds) is generated. The solution is here to add the suffix “ULL” to the integer constant 1.