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:41:23 +0200
commit8990bd7207db46b2b4096305cba59db49fbcb04a (patch)
tree877040b3b7e2efc92cff05f40114d2d67c63a0d0
parentfdad6852847545c1cb3ce78e192fa886782ad769 (diff)
downloadembedlog-8990bd7207db46b2b4096305cba59db49fbcb04a.tar.gz
embedlog-8990bd7207db46b2b4096305cba59db49fbcb04a.tar.bz2
embedlog-8990bd7207db46b2b4096305cba59db49fbcb04a.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 7fd4c9a..f57d728 100644
--- a/src/el-decode-number.c
+++ b/src/el-decode-number.c
@@ -62,7 +62,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
* we are done