Skip to content

Commit

Permalink
attempt to cleanup some bogus windows warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
bradh352 committed Jun 19, 2024
1 parent 19241cb commit 5fe9305
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 16 deletions.
8 changes: 6 additions & 2 deletions cmake/EnableWarnings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ if (MSVC)
/w14242 # 'identifier': conversion from 'type1' to 'type2', possible loss of data
/w14254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data
/w14263 # 'function': member function does not override any base class virtual member function
/w14265 # 'classname': class has virtual functions, but destructor is not virtual instances of this class may not
# be destructed correctly
/w14265 # 'classname': class has virtual functions, but destructor is not virtual instances of this class may
# not be destructed correctly
/w14287 # 'operator': unsigned/negative constant mismatch
/we4289 # nonstandard extension used: 'variable': loop control variable declared in the for-loop is used outside
# the for-loop scope
Expand All @@ -262,6 +262,10 @@ if (MSVC)
/w14928 # illegal copy-initialization; more than one user-defined conversion has been implicitly applied

# Disable some warnings
/wd4201 # nonstandard extension used: nameless struct/union. Used in some windows headers, e.g. IO_STATUS_BLOCK,
# disable.
/wd4206 # nonstandard extension used: translation unit is empty. All files in c-ares are compiled even if not
# used, so we need to ignore this.

# Turn some warnings into errors
/we4013 # Treat "function undefined, assuming extern returning int" warning as an error. https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4013
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ares__addrinfo_localhost.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static ares_status_t
!defined(__WATCOMC__)
PMIB_UNICASTIPADDRESS_TABLE table;
unsigned int i;
ares_status_t status;
ares_status_t status = ARES_ENOTFOUND;

*nodes = NULL;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/ares__buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ static ares_status_t ares__buf_parse_dns_binstr_int(
ares_bool_t allow_multiple, ares_bool_t validate_printable)
{
unsigned char len;
ares_status_t status;
ares_status_t status = ARES_EBADRESP;
ares__buf_t *binbuf = NULL;
size_t orig_len = ares__buf_len(buf);

Expand Down
19 changes: 10 additions & 9 deletions src/lib/ares_event_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,22 +391,23 @@ static const ares_event_sys_t *ares_event_fetch_sys(ares_evsys_t evsys)

/* case ARES_EVSYS_DEFAULT: */
default:
break;
}

/* default */
#if defined(USE_WINSOCK)
return &ares_evsys_win32;
return &ares_evsys_win32;
#elif defined(HAVE_KQUEUE)
return &ares_evsys_kqueue;
return &ares_evsys_kqueue;
#elif defined(HAVE_EPOLL)
return &ares_evsys_epoll;
return &ares_evsys_epoll;
#elif defined(HAVE_POLL)
return &ares_evsys_poll;
return &ares_evsys_poll;
#elif defined(HAVE_PIPE)
return &ares_evsys_select;
return &ares_evsys_select;
#else
break;
#endif
}

return NULL;
#endif
}

ares_status_t ares_event_thread_init(ares_channel_t *channel)
Expand Down
18 changes: 16 additions & 2 deletions src/lib/ares_math.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,23 @@ static ares_int64_t ares__round_up_pow2_u64(ares_int64_t n)
return n;
}

ares_bool ares__is_64bit(void)
{
#ifdef _MSC_VER
# pragma warning( push )
# pragma warning( disable : 4127 )
#endif

return (sizeof(size_t) == 4)?ARES_FALSE:ARES_TRUE;

#ifdef _MSC_VER
# pragma warning( pop )
#endif
}

size_t ares__round_up_pow2(size_t n)
{
if (sizeof(size_t) > 4) {
if (ares__is_64bit()) {
return (size_t)ares__round_up_pow2_u64((ares_int64_t)n);
}

Expand All @@ -79,7 +93,7 @@ size_t ares__log2(size_t n)
56, 45, 25, 31, 35, 16, 9, 12, 44, 24, 15, 8, 23, 7, 6, 5
};

if (sizeof(size_t) == 4) {
if (!ares__is_64bit()) {
return tab32[(n * 0x077CB531) >> 27];
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/ares_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ ares_bool_t ares__subnet_match(const struct ares_addr *addr,
unsigned char netmask);
ares_bool_t ares__addr_is_linklocal(const struct ares_addr *addr);

ares_bool_t ares__is_64bit(void);
size_t ares__round_up_pow2(size_t n);
size_t ares__log2(size_t n);
size_t ares__pow(size_t x, size_t y);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ares_rand.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ typedef struct ares_rand_rc4 {
static unsigned int ares_u32_from_ptr(void *addr)
{
/* LCOV_EXCL_START: FallbackCode */
if (sizeof(void *) == 8) {
if (ares__is_64bit()) {
return (unsigned int)((((ares_uint64_t)addr >> 32) & 0xFFFFFFFF) |
((ares_uint64_t)addr & 0xFFFFFFFF));
}
Expand Down

0 comments on commit 5fe9305

Please sign in to comment.