Fix 64 bit variants. Note undefined behavior
This commit is contained in:
@@ -25,6 +25,10 @@ uc_phi_64(uint64_t N);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
// Note: the nextpow2 functions have undefined behavior if
|
||||
// x > 2^(n-1) for n of the 32 or 64 bit variants
|
||||
|
||||
#if HAVE_BUILTIN_CLZ
|
||||
|
||||
static inline uint32_t
|
||||
@@ -39,7 +43,7 @@ static inline uint64_t
|
||||
uc_nextpow2_64(uint64_t x)
|
||||
{
|
||||
if (x <= 1) return 1;
|
||||
return 1u << (64 - __builtin_clzll(x - 1));
|
||||
return (uint64_t)1 << (64 - __builtin_clzll(x - 1));
|
||||
return x;
|
||||
}
|
||||
#else
|
||||
@@ -61,7 +65,7 @@ uc_nextpow2(uint32_t x)
|
||||
}
|
||||
|
||||
static inline uint64_t
|
||||
uc_nextpow2(uint64_t x)
|
||||
uc_nextpow2_64(uint64_t x)
|
||||
{
|
||||
if (x == 0) {
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user