0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 12:12:15 +02:00

use std::enable_if with sizeof(T) instead if(sizeof(T))

This silences a compiler warning about error=shift-count-overflow
This commit is contained in:
Arne Schwabe 2020-01-09 17:07:47 +01:00 committed by David Sommerseth
parent 984c601090
commit c8fb3f112d
No known key found for this signature in database
GPG Key ID: 86CF944C9671FDF2

View File

@ -31,18 +31,25 @@
namespace openvpn {
// Return the binary prefix of a big-endian data buffer
// as a 32 or 64 bit type.
// as a 32 bit type.
template<typename T>
inline T bin_prefix(const unsigned char *data)
inline typename std::enable_if< 4 == sizeof(T), T>::type
bin_prefix(const unsigned char *data)
{
static_assert(sizeof(T) == 4 || sizeof(T) == 8, "size inconsistency");
if (sizeof(T) == 8)
return (T(ntohl(*(uint32_t *)&data[0])) << 32) | T(ntohl(*(uint32_t *)&data[4]));
else // sizeof(T) == 4
static_assert(sizeof(T) == 4, "size inconsistency");
return T(ntohl(*(uint32_t *)&data[0]));
}
// Return the binary prefix of a big-endian data buffer
// as a 64 bit type.
template<typename T>
inline typename std::enable_if< 8 == sizeof(T), T>::type
bin_prefix(const unsigned char *data)
{
static_assert(sizeof(T) == 8, "size inconsistency");
return (T(ntohl(*(uint32_t *)&data[0])) << 32) | T(ntohl(*(uint32_t *)&data[4]));
}
template <typename T>
inline T bin_prefix(const unsigned char *data, const size_t len)
{