From: Uwe Hermann Date: Mon, 21 May 2018 14:30:57 +0000 (+0200) Subject: LogicSegment::pow2_ceil(): Fix potentіal integer overflow. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=727083851e431c1a0303347550d5ace9ea6962d1;p=pulseview.git LogicSegment::pow2_ceil(): Fix potentіal integer overflow. Reported by Coverity (CID 50925): Unintentional integer overflow (OVERFLOW_BEFORE_WIDEN) overflow_before_widen: Potentially overflowing expression 1 << power with type int (32 bits, signed) is evaluated using 32-bit arithmetic, and then used in a context that expects an expression of type uint64_t const (64 bits, unsigned). --- diff --git a/pv/data/logicsegment.cpp b/pv/data/logicsegment.cpp index 707f797d..5d6faf8f 100644 --- a/pv/data/logicsegment.cpp +++ b/pv/data/logicsegment.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include "logic.hpp" #include "logicsegment.hpp" @@ -480,7 +481,7 @@ uint64_t LogicSegment::get_subsample(int level, uint64_t offset) const uint64_t LogicSegment::pow2_ceil(uint64_t x, unsigned int power) { - const uint64_t p = 1 << power; + const uint64_t p = UINT64_C(1) << power; return (x + p - 1) / p * p; }