ares__round_up_pow2() work around bogus warning

On 32bit systems, a codeblock that would intentionally never
be executed was emitting a warning.  Rework the code to
prevent the warning.  More code, no behavior difference, but
keeps people from complaining about the warning...

Fixes Bug: #645
Fix By: Brad House (@bradh352)
pull/651/head
Brad House 1 year ago
parent d27eebfbdf
commit d7700636b8
  1. 28
      src/lib/ares_math.c

@ -30,7 +30,7 @@
/* Uses public domain code snippets from
* http://graphics.stanford.edu/~seander/bithacks.html */
size_t ares__round_up_pow2(size_t n)
static unsigned int ares__round_up_pow2_u32(unsigned int n)
{
/* NOTE: if already a power of 2, will return itself, not the next */
n--;
@ -39,13 +39,33 @@ size_t ares__round_up_pow2(size_t n)
n |= n >> 4;
n |= n >> 8;
n |= n >> 16;
if (sizeof(size_t) > 4) {
n |= n >> 32;
}
n++;
return n;
}
static ares_int64_t ares__round_up_pow2_u64(ares_int64_t n)
{
/* NOTE: if already a power of 2, will return itself, not the next */
n--;
n |= n >> 1;
n |= n >> 2;
n |= n >> 4;
n |= n >> 8;
n |= n >> 16;
n |= n >> 32;
n++;
return n;
}
size_t ares__round_up_pow2(size_t n)
{
if (sizeof(size_t) > 4) {
return (size_t)ares__round_up_pow2_u64((ares_int64_t)n);
}
return (size_t)ares__round_up_pow2_u32((unsigned int)n);
}
size_t ares__log2(size_t n)
{
static const unsigned char tab32[32] = { 0, 1, 28, 2, 29, 14, 24, 3,

Loading…
Cancel
Save