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:
parent
984c601090
commit
c8fb3f112d
@ -31,16 +31,23 @@
|
||||
namespace openvpn {
|
||||
|
||||
// Return the binary prefix of a big-endian data buffer
|
||||
// as a 32 or 64 bit type.
|
||||
|
||||
template <typename T>
|
||||
inline T bin_prefix(const unsigned char *data)
|
||||
// as a 32 bit type.
|
||||
template<typename T>
|
||||
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
|
||||
return T(ntohl(*(uint32_t *)&data[0]));
|
||||
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>
|
||||
|
Loading…
Reference in New Issue
Block a user