diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f3c77ba..cd77df63 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -564,7 +564,7 @@ SET (RECVFROM_TYPE_ARG5 "struct sockaddr *") SET (RECV_TYPE_ARG4 int) SET (GETNAMEINFO_TYPE_ARG1 "struct sockaddr *") SET (GETNAMEINFO_TYPE_ARG7 int) -SET (SEND_TYPE_ARG2 "void *") +SET (SEND_TYPE_ARG2 "const void *") SET (SEND_TYPE_ARG4 int) ################################################################################ diff --git a/Makefile.dj b/Makefile.dj index 49f8ad0d..bc91d2e8 100644 --- a/Makefile.dj +++ b/Makefile.dj @@ -21,9 +21,12 @@ OBJ_DIR = djgpp CFLAGS = -g -O2 -I./include -I./src/lib \ -I$(WATT32_ROOT)/inc \ + -std=c90 \ -Wall \ -Wextra \ + -Waggregate-return \ -Wcast-align \ + -Wcast-qual \ -Wconversion \ -Wdeclaration-after-statement \ -Wdouble-promotion \ @@ -40,6 +43,7 @@ CFLAGS = -g -O2 -I./include -I./src/lib \ -Wno-coverage-mismatch \ -Wold-style-definition \ -Wpacked \ + -Wpedantic \ -Wpointer-arith \ -Wshadow \ -Wsign-conversion \ @@ -47,12 +51,14 @@ CFLAGS = -g -O2 -I./include -I./src/lib \ -Wstrict-prototypes \ -Wtrampolines \ -Wundef \ + -Wunreachable-code \ -Wunused \ -Wvariadic-macros \ -Wvla \ -Wwrite-strings \ -Werror=implicit-int \ -Werror=implicit-function-declaration \ + -Wno-long-long \ -DWATT32 -DHAVE_CONFIG_H \ -D_REENTRANT \ -DCARES_NO_DEPRECATED \ diff --git a/cmake/EnableWarnings.cmake b/cmake/EnableWarnings.cmake index 2edeef8d..24b5ee46 100644 --- a/cmake/EnableWarnings.cmake +++ b/cmake/EnableWarnings.cmake @@ -305,7 +305,9 @@ else () -Wextra # Enable additional warnings not covered by Wall and Wextra. + -Waggregate-return -Wcast-align + -Wcast-qual -Wconversion -Wdeclaration-after-statement -Wdouble-promotion @@ -323,6 +325,7 @@ else () -Wno-coverage-mismatch -Wold-style-definition -Wpacked + -Wpedantic -Wpointer-arith -Wredundant-decls -Wshadow @@ -331,6 +334,7 @@ else () -Wstrict-prototypes -Wtrampolines -Wundef + -Wunreachable-code -Wunused -Wvariadic-macros -Wvla @@ -349,6 +353,8 @@ else () # Some clang versions might warn if an argument like "-I/path/to/headers" is unused, # silence these. -Qunused-arguments + + -Wno-long-long ) # C++ flags: diff --git a/configure.ac b/configure.ac index 14eee048..43be1026 100644 --- a/configure.ac +++ b/configure.ac @@ -245,42 +245,8 @@ AC_SUBST(CARES_SYMBOL_HIDING_CFLAG) if test "$enable_warnings" = "yes"; then - AX_APPEND_COMPILE_FLAGS([-Wall \ - -Wextra \ - -Wcast-align \ - -Wconversion \ - -Wdeclaration-after-statement \ - -Wdouble-promotion \ - -Wfloat-equal \ - -Wformat-security \ - -Winit-self \ - -Wjump-misses-init \ - -Wlogical-op \ - -Wmissing-braces \ - -Wmissing-declarations \ - -Wmissing-format-attribute \ - -Wmissing-include-dirs \ - -Wmissing-prototypes \ - -Wnested-externs \ - -Wno-coverage-mismatch \ - -Wold-style-definition \ - -Wpacked \ - -Wpointer-arith \ - -Wredundant-decls \ - -Wshadow \ - -Wsign-conversion \ - -Wstrict-overflow \ - -Wstrict-prototypes \ - -Wtrampolines \ - -Wundef \ - -Wunused \ - -Wvariadic-macros \ - -Wvla \ - -Wwrite-strings \ - -Werror=implicit-int \ - -Werror=implicit-function-declaration \ - -Werror=partial-availability \ - ], [AM_CFLAGS], [-Werror]) + AX_APPEND_COMPILE_FLAGS([-std=c90 -Wall -Wextra -Waggregate-return -Wcast-align -Wcast-qual -Wconversion -Wdeclaration-after-statement -Wdouble-promotion -Wfloat-equal -Wformat-security -Winit-self -Wjump-misses-init -Wlogical-op -Wmissing-braces -Wmissing-declarations -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-prototypes -Wnested-externs -Wno-coverage-mismatch -Wold-style-definition -Wpacked -Wpedantic -Wpointer-arith -Wredundant-decls -Wshadow -Wsign-conversion -Wstrict-overflow -Wstrict-prototypes -Wtrampolines -Wundef -Wunreachable-code -Wunused -Wvariadic-macros -Wvla -Wwrite-strings -Werror=implicit-int -Werror=implicit-function-declaration -Werror=partial-availability -Wno-long-long ], + [AM_CFLAGS], [-Werror]) fi if test "$ax_cv_c_compiler_vendor" = "intel"; then @@ -663,7 +629,7 @@ recvfrom_type_arg5="struct sockaddr *" recv_type_arg4=int getnameinfo_type_arg1="struct sockaddr *" getnameinfo_type_arg7=int -send_type_arg2="void *" +send_type_arg2="const void *" send_type_arg4=int AC_DEFINE_UNQUOTED([RECVFROM_TYPE_RETV], [ ${recvfrom_type_retv} ], [ recvfrom() return value ]) diff --git a/include/ares_dns_record.h b/include/ares_dns_record.h index 5533929f..1084a52e 100644 --- a/include/ares_dns_record.h +++ b/include/ares_dns_record.h @@ -94,7 +94,7 @@ typedef enum { ARES_OPCODE_IQUERY = 1, /*!< Inverse query. Obsolete. */ ARES_OPCODE_STATUS = 2, /*!< Name server status query */ ARES_OPCODE_NOTIFY = 4, /*!< Zone change notification (RFC 1996) */ - ARES_OPCODE_UPDATE = 5, /*!< Zone update message (RFC2136) */ + ARES_OPCODE_UPDATE = 5 /*!< Zone update message (RFC2136) */ } ares_dns_opcode_t; /*! DNS Header flags */ @@ -108,7 +108,7 @@ typedef enum { ARES_FLAG_AD = 1 << 5, /*!< RFC 2065. Authentic Data bit indicates in a * response that the data included has been verified by * the server providing it */ - ARES_FLAG_CD = 1 << 6, /*!< RFC 2065. Checking Disabled bit indicates in a + ARES_FLAG_CD = 1 << 6 /*!< RFC 2065. Checking Disabled bit indicates in a * query that non-verified data is acceptable to the * resolver sending the query. */ } ares_dns_flags_t; @@ -152,7 +152,7 @@ typedef enum { ARES_RCODE_BADNAME = 20, /*!< RFC 2930. Duplicate Key Name */ ARES_RCODE_BADALG = 21, /*!< RFC 2930. Algorithm not supported */ ARES_RCODE_BADTRUNC = 22, /*!< RFC 8945. Bad Truncation */ - ARES_RCODE_BADCOOKIE = 23, /*!< RVC 7973. Bad/missing Server Cookie */ + ARES_RCODE_BADCOOKIE = 23 /*!< RVC 7973. Bad/missing Server Cookie */ } ares_dns_rcode_t; /*! Data types used */ @@ -169,7 +169,7 @@ typedef enum { * printable. Guaranteed to have a NULL * terminator for convenience (not included in * length) */ - ARES_DATATYPE_OPT = 10, /*!< Array of options. 16bit identifier, BIN + ARES_DATATYPE_OPT = 10 /*!< Array of options. 16bit identifier, BIN * data. */ } ares_dns_datatype_t; @@ -292,7 +292,7 @@ typedef enum { /*! RAW Record. RR Type. Datatype: U16 */ ARES_RR_RAW_RR_TYPE = (ARES_REC_TYPE_RAW_RR * 100) + 1, /*! RAW Record. RR Data. Datatype: BIN */ - ARES_RR_RAW_RR_DATA = (ARES_REC_TYPE_RAW_RR * 100) + 2, + ARES_RR_RAW_RR_DATA = (ARES_REC_TYPE_RAW_RR * 100) + 2 } ares_dns_rr_key_t; /*! TLSA Record ARES_RR_TLSA_CERT_USAGE known values */ @@ -372,7 +372,7 @@ typedef enum { /*! RFC 8145. Signaling Trust Anchor Knowledge in DNSSEC */ ARES_OPT_PARAM_EDNS_KEY_TAG = 14, /*! RFC 8914. Extended ERROR code and message */ - ARES_OPT_PARAM_EXTENDED_DNS_ERROR = 15, + ARES_OPT_PARAM_EXTENDED_DNS_ERROR = 15 } ares_opt_param_t; /*! Data type for option records for keys like ARES_RR_OPT_OPTIONS and diff --git a/src/lib/ares__addrinfo2hostent.c b/src/lib/ares__addrinfo2hostent.c index b441e975..81037006 100644 --- a/src/lib/ares__addrinfo2hostent.c +++ b/src/lib/ares__addrinfo2hostent.c @@ -165,13 +165,13 @@ ares_status_t ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family, if (family == AF_INET6) { memcpy( (*host)->h_addr_list[i], - &(CARES_INADDR_CAST(struct sockaddr_in6 *, next->ai_addr)->sin6_addr), + &(CARES_INADDR_CAST(const struct sockaddr_in6 *, next->ai_addr)->sin6_addr), (size_t)(*host)->h_length); } if (family == AF_INET) { memcpy( (*host)->h_addr_list[i], - &(CARES_INADDR_CAST(struct sockaddr_in *, next->ai_addr)->sin_addr), + &(CARES_INADDR_CAST(const struct sockaddr_in *, next->ai_addr)->sin_addr), (size_t)(*host)->h_length); } ++i; @@ -256,7 +256,7 @@ ares_status_t ares__addrinfo2addrttl(const struct ares_addrinfo *ai, int family, memcpy( &addr6ttls[*naddrttls].ip6addr, - &(CARES_INADDR_CAST(struct sockaddr_in6 *, next->ai_addr)->sin6_addr), + &(CARES_INADDR_CAST(const struct sockaddr_in6 *, next->ai_addr)->sin6_addr), sizeof(struct ares_in6_addr)); } else { if (next->ai_ttl > cname_ttl) { @@ -266,7 +266,7 @@ ares_status_t ares__addrinfo2addrttl(const struct ares_addrinfo *ai, int family, } memcpy( &addrttls[*naddrttls].ipaddr, - &(CARES_INADDR_CAST(struct sockaddr_in *, next->ai_addr)->sin_addr), + &(CARES_INADDR_CAST(const struct sockaddr_in *, next->ai_addr)->sin_addr), sizeof(struct in_addr)); } (*naddrttls)++; diff --git a/src/lib/ares_event_configchg.c b/src/lib/ares_event_configchg.c index dfb71690..b505fa24 100644 --- a/src/lib/ares_event_configchg.c +++ b/src/lib/ares_event_configchg.c @@ -473,7 +473,7 @@ ares_status_t ares_event_configchg_init(ares_event_configchg_t **configchg, continue; } - pdns_configuration_notify_key = + pdns_configuration_notify_key = (const char *(*)(void)) dlsym(handle, "dns_configuration_notify_key"); if (pdns_configuration_notify_key != NULL) { break; diff --git a/src/lib/ares_gethostbyname.c b/src/lib/ares_gethostbyname.c index 33de0278..0670b2ab 100644 --- a/src/lib/ares_gethostbyname.c +++ b/src/lib/ares_gethostbyname.c @@ -102,13 +102,17 @@ static void ares_gethostbyname_callback(void *arg, int status, int timeouts, void ares_gethostbyname(ares_channel_t *channel, const char *name, int family, ares_host_callback callback, void *arg) { - const struct ares_addrinfo_hints hints = { ARES_AI_CANONNAME, family, 0, 0 }; - struct host_query *ghbn_arg; + struct ares_addrinfo_hints hints; + struct host_query *ghbn_arg; if (!callback) { return; } + memset(&hints, 0, sizeof(hints)); + hints.ai_flags = ARES_AI_CANONNAME; + hints.ai_family = family; + ghbn_arg = ares_malloc(sizeof(*ghbn_arg)); if (!ghbn_arg) { callback(arg, ARES_ENOMEM, 0, NULL); diff --git a/src/lib/ares_getnameinfo.c b/src/lib/ares_getnameinfo.c index dc79ac68..aae58242 100644 --- a/src/lib/ares_getnameinfo.c +++ b/src/lib/ares_getnameinfo.c @@ -100,11 +100,11 @@ static void ares_getnameinfo_int(ares_channel_t *channel, /* Validate socket address family and length */ if (sa && sa->sa_family == AF_INET && salen >= (ares_socklen_t)sizeof(struct sockaddr_in)) { - addr = CARES_INADDR_CAST(struct sockaddr_in *, sa); + addr = CARES_INADDR_CAST(const struct sockaddr_in *, sa); port = addr->sin_port; } else if (sa && sa->sa_family == AF_INET6 && salen >= (ares_socklen_t)sizeof(struct sockaddr_in6)) { - addr6 = CARES_INADDR_CAST(struct sockaddr_in6 *, sa); + addr6 = CARES_INADDR_CAST(const struct sockaddr_in6 *, sa); port = addr6->sin6_port; } else { callback(arg, ARES_ENOTIMP, 0, NULL, NULL); diff --git a/src/lib/ares_private.h b/src/lib/ares_private.h index 6966bc8d..6a5ef0f3 100644 --- a/src/lib/ares_private.h +++ b/src/lib/ares_private.h @@ -41,7 +41,7 @@ * warning: cast from 'const struct sockaddr *' to 'const struct sockaddr_in6 *' * increases required alignment from 1 to 4 [-Wcast-align] */ -#define CARES_INADDR_CAST(type, var) ((type)((void *)var)) +#define CARES_INADDR_CAST(type, var) ((type)((const void *)var)) #if defined(USE_WINSOCK) diff --git a/src/lib/ares_process.c b/src/lib/ares_process.c index 530d2f1a..6ace7dbb 100644 --- a/src/lib/ares_process.c +++ b/src/lib/ares_process.c @@ -1222,14 +1222,14 @@ static ares_bool_t same_address(const struct sockaddr *sa, switch (aa->family) { case AF_INET: addr1 = &aa->addr.addr4; - addr2 = &(CARES_INADDR_CAST(struct sockaddr_in *, sa))->sin_addr; + addr2 = &(CARES_INADDR_CAST(const struct sockaddr_in *, sa))->sin_addr; if (memcmp(addr1, addr2, sizeof(aa->addr.addr4)) == 0) { return ARES_TRUE; /* match */ } break; case AF_INET6: addr1 = &aa->addr.addr6; - addr2 = &(CARES_INADDR_CAST(struct sockaddr_in6 *, sa))->sin6_addr; + addr2 = &(CARES_INADDR_CAST(const struct sockaddr_in6 *, sa))->sin6_addr; if (memcmp(addr1, addr2, sizeof(aa->addr.addr6)) == 0) { return ARES_TRUE; /* match */ } diff --git a/src/lib/ares_rand.c b/src/lib/ares_rand.c index e2e6687e..f37ca1b4 100644 --- a/src/lib/ares_rand.c +++ b/src/lib/ares_rand.c @@ -43,7 +43,7 @@ typedef enum { ARES_RAND_OS = 1 << 0, /* OS-provided such as RtlGenRandom or arc4random */ ARES_RAND_FILE = 1 << 1, /* OS file-backed random number generator */ - ARES_RAND_RC4 = 1 << 2, /* Internal RC4 based PRNG */ + ARES_RAND_RC4 = 1 << 2 /* Internal RC4 based PRNG */ } ares_rand_backend; #define ARES_RC4_KEY_LEN 32 /* 256 bits */ diff --git a/src/lib/ares_sysconfig_mac.c b/src/lib/ares_sysconfig_mac.c index e2d34d7c..a93250e7 100644 --- a/src/lib/ares_sysconfig_mac.c +++ b/src/lib/ares_sysconfig_mac.c @@ -45,6 +45,11 @@ * private header extracted from: * https://opensource.apple.com/source/configd/configd-1109.140.1/dnsinfo/dnsinfo.h */ + +/* The apple header uses anonymous unions which came with C11 */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wc11-extensions" + # include "ares_setup.h" # include # include @@ -110,10 +115,10 @@ static ares_status_t dnsinfo_init(dnsinfo_t **dnsinfo_out) continue; } - dnsinfo->dns_configuration_copy = + dnsinfo->dns_configuration_copy = (dns_config_t *(*)(void)) dlsym(dnsinfo->handle, "dns_configuration_copy"); - dnsinfo->dns_configuration_free = + dnsinfo->dns_configuration_free = (void (*)(dns_config_t *)) dlsym(dnsinfo->handle, "dns_configuration_free"); if (dnsinfo->dns_configuration_copy != NULL && @@ -365,6 +370,7 @@ done: } return status; } +#pragma GCC diagnostic pop #endif diff --git a/src/tools/adig.c b/src/tools/adig.c index e0d5c915..62b6f23e 100644 --- a/src/tools/adig.c +++ b/src/tools/adig.c @@ -113,12 +113,16 @@ static void free_config(adig_config_t *config) static void print_help(void) { + /* Split due to maximum c89 string literal of 509 bytes */ printf("adig version %s\n\n", ares_version(NULL)); printf( "usage: adig [-h] [-d] [-f flag] [[-s server] ...] [-T|U port] [-c class]\n" - " [-t type] name ...\n\n" - " -h : Display this help and exit.\n" - " -d : Print some extra debugging output.\n" + " [-t type] name ...\n\n"); + printf( + " -h : Display this help and exit.\n"); + printf( + " -d : Print some extra debugging output.\n"); + printf( " -f flag : Add a behavior control flag. Possible values are\n" " igntc - do not retry a truncated query as TCP, just\n" " return the truncated answer\n" @@ -127,21 +131,26 @@ static void print_help(void) " norecurse - don't query upstream servers recursively\n" " primary - use the first server\n" " stayopen - don't close the communication sockets\n" - " usevc - use TCP only\n" + " usevc - use TCP only\n"); + printf( " -s server : Connect to the specified DNS server, instead of the\n" " system's default one(s). Servers are tried in round-robin,\n" - " if the previous one failed.\n" - " -T port : Connect to the specified TCP port of DNS server.\n" - " -U port : Connect to the specified UDP port of DNS server.\n" + " if the previous one failed.\n"); + printf( + " -T port : Connect to the specified TCP port of DNS server.\n"); + printf( + " -U port : Connect to the specified UDP port of DNS server.\n"); + printf( " -c class : Set the query class. Possible values for class are:\n" - " ANY, CHAOS, HS and IN (default)\n" + " ANY, CHAOS, HS and IN (default)\n"); + printf( " -t type : Query records of the specified type. Possible values for\n" " type are:\n" " A (default), AAAA, ANY, CNAME, HINFO, MX, NAPTR, NS, PTR,\n" " SOA, SRV, TXT, TLSA, URI, CAA, SVCB, HTTPS\n\n"); } -static ares_bool_t read_cmdline(int argc, const char **argv, +static ares_bool_t read_cmdline(int argc, const char * const * argv, adig_config_t *config) { ares_getopt_state_t state; @@ -897,7 +906,7 @@ int main(int argc, char **argv) memset(&config, 0, sizeof(config)); config.qclass = ARES_CLASS_IN; config.qtype = ARES_REC_TYPE_A; - if (!read_cmdline(argc, (const char **)argv, &config)) { + if (!read_cmdline(argc, (const char * const *)argv, &config)) { printf("\n** ERROR: %s\n\n", config.error); print_help(); rv = 1; diff --git a/src/tools/ahost.c b/src/tools/ahost.c index 8d74d5d8..10ce14d4 100644 --- a/src/tools/ahost.c +++ b/src/tools/ahost.c @@ -95,7 +95,7 @@ int main(int argc, char **argv) return 1; } - ares_getopt_init(&state, argc, (const char **)argv); + ares_getopt_init(&state, argc, (const char * const *)argv); while ((c = ares_getopt(&state, "dt:h?D:s:")) != -1) { switch (c) { case 'd': @@ -276,18 +276,22 @@ static void usage(void) /* Information from the man page. Formatting taken from man -h */ static void print_help_info_ahost(void) { + /* Split due to maximum c89 string literal of 509 bytes */ printf("ahost, version %s\n\n", ARES_VERSION_STR); printf( "usage: ahost [-h] [-d] [-D domain] [-s server] [-t a|aaaa|u] host|addr " - "...\n\n" + "...\n\n"); + printf( " -h : Display this help and exit.\n" " -d : Print some extra debugging output.\n\n" " -D domain : Specify the domain to search instead of using the default " - "values\n" + "values\n"); + printf( " -s server : Connect to the specified DNS server, instead of the\n" " system's default one(s). Servers are tried in round-robin,\n" " if the previous one failed.\n" - " -t type : If type is \"a\", print the A record.\n" + " -t type : If type is \"a\", print the A record.\n"); + printf( " If type is \"aaaa\", print the AAAA record.\n" " If type is \"u\" (default), print both A and AAAA records.\n" "\n"); diff --git a/src/tools/ares_getopt.c b/src/tools/ares_getopt.c index ad0b8ae8..0c15d8fd 100644 --- a/src/tools/ares_getopt.c +++ b/src/tools/ares_getopt.c @@ -47,9 +47,9 @@ #define BADCH (int)'?' #define BADARG (int)':' -#define EMSG (char *)"" +#define EMSG "" -void ares_getopt_init(ares_getopt_state_t *state, int nargc, const char **nargv) +void ares_getopt_init(ares_getopt_state_t *state, int nargc, const char * const * nargv) { memset(state, 0, sizeof(*state)); state->opterr = 1; diff --git a/src/tools/ares_getopt.h b/src/tools/ares_getopt.h index a14f7ab4..7ff1fdee 100644 --- a/src/tools/ares_getopt.h +++ b/src/tools/ares_getopt.h @@ -40,10 +40,10 @@ typedef struct { int optopt; /* character checked for validity */ const char *place; int argc; - const char **argv; + const char * const *argv; } ares_getopt_state_t; -void ares_getopt_init(ares_getopt_state_t *state, int argc, const char **argv); +void ares_getopt_init(ares_getopt_state_t *state, int argc, const char * const * argv); int ares_getopt(ares_getopt_state_t *state, const char *ostr); #endif /* ARES_GETOPT_H */