You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2013/10/29 01:07:57 UTC
[lucy-commits] [2/3] git commit: refs/heads/master - Fix undefined behavior in
NumberUtils.cfh
Fix undefined behavior in NumberUtils.cfh
Shifting by more bits than the size of the data type is undefined.
Detected by clang's -fsanitize=undefined.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/2104acde
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/2104acde
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/2104acde
Branch: refs/heads/master
Commit: 2104acde591e56b60b4610d2dff3fc5d7e2b1443
Parents: 433935a
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Tue Oct 29 01:00:13 2013 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue Oct 29 01:00:13 2013 +0100
----------------------------------------------------------------------
.../runtime/core/Clownfish/Util/NumberUtils.cfh | 28 ++++++++++----------
1 file changed, 14 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/2104acde/clownfish/runtime/core/Clownfish/Util/NumberUtils.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/Util/NumberUtils.cfh b/clownfish/runtime/core/Clownfish/Util/NumberUtils.cfh
index 7c91df1..b57a104 100644
--- a/clownfish/runtime/core/Clownfish/Util/NumberUtils.cfh
+++ b/clownfish/runtime/core/Clownfish/Util/NumberUtils.cfh
@@ -227,30 +227,30 @@ cfish_NumUtil_encode_bigend_u64(uint64_t value, void *dest_ptr) {
static CFISH_INLINE uint16_t
cfish_NumUtil_decode_bigend_u16(void *source) {
uint8_t *const buf = (uint8_t*)source;
- return (buf[0] << 8) |
- (buf[1]);
+ return ((uint16_t)buf[0] << 8) |
+ ((uint16_t)buf[1]);
}
static CFISH_INLINE uint32_t
cfish_NumUtil_decode_bigend_u32(void *source) {
uint8_t *const buf = (uint8_t*)source;
- return (buf[0] << 24) |
- (buf[1] << 16) |
- (buf[2] << 8) |
- (buf[3]);
+ return ((uint32_t)buf[0] << 24) |
+ ((uint32_t)buf[1] << 16) |
+ ((uint32_t)buf[2] << 8) |
+ ((uint32_t)buf[3]);
}
static CFISH_INLINE uint64_t
cfish_NumUtil_decode_bigend_u64(void *source) {
uint8_t *const buf = (uint8_t*)source;
- uint64_t high_bits = (buf[0] << 24) |
- (buf[1] << 16) |
- (buf[2] << 8) |
- (buf[3]);
- uint32_t low_bits = (buf[4] << 24) |
- (buf[5] << 16) |
- (buf[6] << 8) |
- (buf[7]);
+ uint64_t high_bits = ((uint32_t)buf[0] << 24) |
+ ((uint32_t)buf[1] << 16) |
+ ((uint32_t)buf[2] << 8) |
+ ((uint32_t)buf[3]);
+ uint32_t low_bits = ((uint32_t)buf[4] << 24) |
+ ((uint32_t)buf[5] << 16) |
+ ((uint32_t)buf[6] << 8) |
+ ((uint32_t)buf[7]);
uint64_t retval = high_bits << 32;
retval |= low_bits;
return retval;