diff options
author | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2019-07-29 11:37:57 +0200 |
---|---|---|
committer | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2019-07-29 11:42:08 +0200 |
commit | 8fb1814263121f5d755d9ac92b1cf1babe7c4601 (patch) | |
tree | f887649334ee4a6b0b0cf4ac4a66374f6f95843d | |
parent | 7665a9daaffffcd26bcda2e9983167d422955422 (diff) | |
download | embedlog-8fb1814263121f5d755d9ac92b1cf1babe7c4601.tar.gz embedlog-8fb1814263121f5d755d9ac92b1cf1babe7c4601.tar.bz2 embedlog-8fb1814263121f5d755d9ac92b1cf1babe7c4601.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.c | 6 |
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 |