aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2019-10-20 11:15:16 -0400
committerJack Lloyd <[email protected]>2019-10-20 11:15:16 -0400
commiteff66225bc9e53d3372e3224c630d98efd75cdb9 (patch)
tree211142c4e9ff17797bd4c5557113162b280bc16f
parent7b3453963dac1a8f45354343b0af26535aea21ae (diff)
parentb7dc5389d37be7ca6270b2645256e417e71572d8 (diff)
Merge GH #2168 Fix Coverity warning in Roughtime
-rw-r--r--src/lib/misc/roughtime/roughtime.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/lib/misc/roughtime/roughtime.cpp b/src/lib/misc/roughtime/roughtime.cpp
index 435308cd0..516ef6078 100644
--- a/src/lib/misc/roughtime/roughtime.cpp
+++ b/src/lib/misc/roughtime/roughtime.cpp
@@ -34,10 +34,16 @@ template<class T, std::size_t N>
struct is_array<std::array<T,N>>:std::true_type{};
template<typename T>
-T from_little_endian(const uint8_t* t, size_t N = sizeof(T))
+T impl_from_little_endian(const uint8_t* t, const size_t i)
{
- static_assert(sizeof(T)<=sizeof(int64_t),"");
- return (N == 0) ? T(0) : (T(static_cast<int64_t>(t[N-1]) << ((N-1)*8)) + from_little_endian<T>(t,N-1));
+ static_assert(sizeof(T) <= sizeof(int64_t), "");
+ return T(static_cast<int64_t>(t[i]) << i * 8) + (i == 0 ? T(0) : impl_from_little_endian<T>(t, i - 1));
+ }
+
+template<typename T>
+T from_little_endian(const uint8_t* t)
+ {
+ return impl_from_little_endian<T>(t, sizeof(T) - 1);
}
template<typename T, enable_if_t<is_array<T>::value>* = nullptr>