]> sigrok.org Git - pulseview.git/blobdiff - pv/data/logicsegment.cpp
LogicSegment::pow2_ceil(): Fix potentіal integer overflow.
[pulseview.git] / pv / data / logicsegment.cpp
index 3896ff2151efc09989d34211b78399f017473c88..5d6faf8f8fe1a5333f8130cfcb17725db99a07ab 100644 (file)
@@ -25,6 +25,7 @@
 #include <cmath>
 #include <cstdlib>
 #include <cstring>
 #include <cmath>
 #include <cstdlib>
 #include <cstring>
+#include <cstdint>
 
 #include "logic.hpp"
 #include "logicsegment.hpp"
 
 #include "logic.hpp"
 #include "logicsegment.hpp"
@@ -64,7 +65,7 @@ LogicSegment::~LogicSegment()
                free(l.data);
 }
 
                free(l.data);
 }
 
-uint64_t LogicSegment::unpack_sample(const uint8_t *ptr) const
+inline uint64_t LogicSegment::unpack_sample(const uint8_t *ptr) const
 {
 #ifdef HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS
        return *(uint64_t*)ptr;
 {
 #ifdef HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS
        return *(uint64_t*)ptr;
@@ -102,7 +103,7 @@ uint64_t LogicSegment::unpack_sample(const uint8_t *ptr) const
 #endif
 }
 
 #endif
 }
 
-void LogicSegment::pack_sample(uint8_t *ptr, uint64_t value)
+inline void LogicSegment::pack_sample(uint8_t *ptr, uint64_t value)
 {
 #ifdef HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS
        *(uint64_t*)ptr = value;
 {
 #ifdef HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS
        *(uint64_t*)ptr = value;
@@ -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)
 {
 
 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;
 }
 
        return (x + p - 1) / p * p;
 }