aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichał Łyszczek <michal.lyszczek@bofc.pl>2019-07-29 11:37:57 +0200
committerMichał Łyszczek <michal.lyszczek@bofc.pl>2019-07-29 11:43:06 +0200
commit3bfc80ca0420bdc20ad535c43a5ff459d071dc9d (patch)
tree5121d4c53de7f8d37bdee3fe77dc88f410c8b958
parent154bef6416ea294fcf05b4ac06437c5707c5f514 (diff)
downloadembedlog-3bfc80ca0420bdc20ad535c43a5ff459d071dc9d.tar.gz
embedlog-3bfc80ca0420bdc20ad535c43a5ff459d071dc9d.tar.bz2
embedlog-3bfc80ca0420bdc20ad535c43a5ff459d071dc9d.zip
src/el-decode-number.c: fix potential loose of precision on 64bit systems
*out |= (n[i] & 0x7f) << (i * 7); (n[i] & 0x7f) - will be an int value (32bit in most cases) and if (i * 7) is larger than 32, we will shift outside of 32bit and 0 will be written into *out which is not what we want. To prevent this, left operand of << should be first casted to 64bit and then shift should be performed. Marking no_ci since this code is not used in embedlog, and is provided as an example for decoding numbers in binary logs. no_ci Reported-by: pvs-studio Signed-off-by: Michał Łyszczek <michal.lyszczek@bofc.pl>
-rw-r--r--src/el-decode-number.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/el-decode-number.c b/src/el-decode-number.c
index 5a8be82..01d7d51 100644
--- a/src/el-decode-number.c
+++ b/src/el-decode-number.c
@@ -69,7 +69,11 @@ size_t el_decode_number
* - set current number into right position of out
*/
- *out |= (n[i] & 0x7f) << (i * 7);
+#ifdef LLONG_MAX
+ *out |= (unsigned long long)(n[i] & 0x7f) << (i * 7);
+#else
+ *out |= (unsigned long)(n[i] & 0x7f) << (i * 7);
+#endif
/*
* we do this until number lacks of continuation bit, which means