Perform a safe truncation.

The result being truncated will never be wider than 8 bits.


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/e691a222
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/e691a222
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/e691a222

Branch: refs/heads/master
Commit: e691a2223c2e55860804b0e1d65c8fcf2690f597
Parents: 42694aa
Author: Marvin Humphrey <[email protected]>
Authored: Thu Apr 21 17:01:52 2016 -0700
Committer: Marvin Humphrey <[email protected]>
Committed: Thu Apr 21 17:01:52 2016 -0700

----------------------------------------------------------------------
 core/Lucy/Util/NumberUtils.cfh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/e691a222/core/Lucy/Util/NumberUtils.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/NumberUtils.cfh b/core/Lucy/Util/NumberUtils.cfh
index 8dcab45..bbb48d6 100644
--- a/core/Lucy/Util/NumberUtils.cfh
+++ b/core/Lucy/Util/NumberUtils.cfh
@@ -483,7 +483,7 @@ lucy_NumUtil_u2set(void *array, uint32_t tick, uint8_t 
value) {
     unsigned shift    = 2 * (tick & 0x3);
     unsigned mask     = (unsigned)0x3 << shift;
     uint8_t  new_val  = value & 0x3;
-    uint8_t  new_bits = new_val << shift;
+    uint8_t  new_bits = (uint8_t)(new_val << shift);
     ints[(tick >> 2)]  = (ints[(tick >> 2)] & ~mask) | new_bits;
 }
 
@@ -502,7 +502,7 @@ lucy_NumUtil_u4set(void *array, uint32_t tick, uint8_t 
value) {
     unsigned  shift    = 4 * (tick & 0x1);
     unsigned  mask     = (unsigned)0xF << shift;
     uint8_t   new_val  = value & 0xF;
-    uint8_t   new_bits = new_val << shift;
+    uint8_t   new_bits = (uint8_t)(new_val << shift);
     ints[(tick >> 1)]  = (ints[(tick >> 1)] & ~mask) | new_bits;
 }
 

Reply via email to