Skip to content

Commit 253bdee

Browse files
committed
enable more GCC/clang warnings, fix reported warnings
1 parent bbcb1a2 commit 253bdee

17 files changed

+78
-77
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ SET (RECVFROM_TYPE_ARG5 "struct sockaddr *")
564564
SET (RECV_TYPE_ARG4 int)
565565
SET (GETNAMEINFO_TYPE_ARG1 "struct sockaddr *")
566566
SET (GETNAMEINFO_TYPE_ARG7 int)
567-
SET (SEND_TYPE_ARG2 "void *")
567+
SET (SEND_TYPE_ARG2 "const void *")
568568
SET (SEND_TYPE_ARG4 int)
569569
################################################################################
570570

Makefile.dj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ OBJ_DIR = djgpp
2121

2222
CFLAGS = -g -O2 -I./include -I./src/lib \
2323
-I$(WATT32_ROOT)/inc \
24+
-std=c90 \
2425
-Wall \
2526
-Wextra \
27+
-Waggregate-return \
2628
-Wcast-align \
29+
-Wcast-qual \
2730
-Wconversion \
2831
-Wdeclaration-after-statement \
2932
-Wdouble-promotion \
@@ -40,19 +43,22 @@ CFLAGS = -g -O2 -I./include -I./src/lib \
4043
-Wno-coverage-mismatch \
4144
-Wold-style-definition \
4245
-Wpacked \
46+
-Wpedantic \
4347
-Wpointer-arith \
4448
-Wshadow \
4549
-Wsign-conversion \
4650
-Wstrict-overflow \
4751
-Wstrict-prototypes \
4852
-Wtrampolines \
4953
-Wundef \
54+
-Wunreachable-code \
5055
-Wunused \
5156
-Wvariadic-macros \
5257
-Wvla \
5358
-Wwrite-strings \
5459
-Werror=implicit-int \
5560
-Werror=implicit-function-declaration \
61+
-Wno-long-long \
5662
-DWATT32 -DHAVE_CONFIG_H \
5763
-D_REENTRANT \
5864
-DCARES_NO_DEPRECATED \

cmake/EnableWarnings.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,9 @@ else ()
305305
-Wextra
306306

307307
# Enable additional warnings not covered by Wall and Wextra.
308+
-Waggregate-return
308309
-Wcast-align
310+
-Wcast-qual
309311
-Wconversion
310312
-Wdeclaration-after-statement
311313
-Wdouble-promotion
@@ -323,6 +325,7 @@ else ()
323325
-Wno-coverage-mismatch
324326
-Wold-style-definition
325327
-Wpacked
328+
-Wpedantic
326329
-Wpointer-arith
327330
-Wredundant-decls
328331
-Wshadow
@@ -331,6 +334,7 @@ else ()
331334
-Wstrict-prototypes
332335
-Wtrampolines
333336
-Wundef
337+
-Wunreachable-code
334338
-Wunused
335339
-Wvariadic-macros
336340
-Wvla
@@ -349,6 +353,8 @@ else ()
349353
# Some clang versions might warn if an argument like "-I/path/to/headers" is unused,
350354
# silence these.
351355
-Qunused-arguments
356+
357+
-Wno-long-long
352358
)
353359

354360
# C++ flags:

configure.ac

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -245,42 +245,8 @@ AC_SUBST(CARES_SYMBOL_HIDING_CFLAG)
245245

246246

247247
if test "$enable_warnings" = "yes"; then
248-
AX_APPEND_COMPILE_FLAGS([-Wall \
249-
-Wextra \
250-
-Wcast-align \
251-
-Wconversion \
252-
-Wdeclaration-after-statement \
253-
-Wdouble-promotion \
254-
-Wfloat-equal \
255-
-Wformat-security \
256-
-Winit-self \
257-
-Wjump-misses-init \
258-
-Wlogical-op \
259-
-Wmissing-braces \
260-
-Wmissing-declarations \
261-
-Wmissing-format-attribute \
262-
-Wmissing-include-dirs \
263-
-Wmissing-prototypes \
264-
-Wnested-externs \
265-
-Wno-coverage-mismatch \
266-
-Wold-style-definition \
267-
-Wpacked \
268-
-Wpointer-arith \
269-
-Wredundant-decls \
270-
-Wshadow \
271-
-Wsign-conversion \
272-
-Wstrict-overflow \
273-
-Wstrict-prototypes \
274-
-Wtrampolines \
275-
-Wundef \
276-
-Wunused \
277-
-Wvariadic-macros \
278-
-Wvla \
279-
-Wwrite-strings \
280-
-Werror=implicit-int \
281-
-Werror=implicit-function-declaration \
282-
-Werror=partial-availability \
283-
], [AM_CFLAGS], [-Werror])
248+
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 ],
249+
[AM_CFLAGS], [-Werror])
284250
fi
285251

286252
if test "$ax_cv_c_compiler_vendor" = "intel"; then
@@ -663,7 +629,7 @@ recvfrom_type_arg5="struct sockaddr *"
663629
recv_type_arg4=int
664630
getnameinfo_type_arg1="struct sockaddr *"
665631
getnameinfo_type_arg7=int
666-
send_type_arg2="void *"
632+
send_type_arg2="const void *"
667633
send_type_arg4=int
668634

669635
AC_DEFINE_UNQUOTED([RECVFROM_TYPE_RETV], [ ${recvfrom_type_retv} ], [ recvfrom() return value ])

include/ares_dns_record.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ typedef enum {
9494
ARES_OPCODE_IQUERY = 1, /*!< Inverse query. Obsolete. */
9595
ARES_OPCODE_STATUS = 2, /*!< Name server status query */
9696
ARES_OPCODE_NOTIFY = 4, /*!< Zone change notification (RFC 1996) */
97-
ARES_OPCODE_UPDATE = 5, /*!< Zone update message (RFC2136) */
97+
ARES_OPCODE_UPDATE = 5 /*!< Zone update message (RFC2136) */
9898
} ares_dns_opcode_t;
9999

100100
/*! DNS Header flags */
@@ -108,7 +108,7 @@ typedef enum {
108108
ARES_FLAG_AD = 1 << 5, /*!< RFC 2065. Authentic Data bit indicates in a
109109
* response that the data included has been verified by
110110
* the server providing it */
111-
ARES_FLAG_CD = 1 << 6, /*!< RFC 2065. Checking Disabled bit indicates in a
111+
ARES_FLAG_CD = 1 << 6 /*!< RFC 2065. Checking Disabled bit indicates in a
112112
* query that non-verified data is acceptable to the
113113
* resolver sending the query. */
114114
} ares_dns_flags_t;
@@ -152,7 +152,7 @@ typedef enum {
152152
ARES_RCODE_BADNAME = 20, /*!< RFC 2930. Duplicate Key Name */
153153
ARES_RCODE_BADALG = 21, /*!< RFC 2930. Algorithm not supported */
154154
ARES_RCODE_BADTRUNC = 22, /*!< RFC 8945. Bad Truncation */
155-
ARES_RCODE_BADCOOKIE = 23, /*!< RVC 7973. Bad/missing Server Cookie */
155+
ARES_RCODE_BADCOOKIE = 23 /*!< RVC 7973. Bad/missing Server Cookie */
156156
} ares_dns_rcode_t;
157157

158158
/*! Data types used */
@@ -169,7 +169,7 @@ typedef enum {
169169
* printable. Guaranteed to have a NULL
170170
* terminator for convenience (not included in
171171
* length) */
172-
ARES_DATATYPE_OPT = 10, /*!< Array of options. 16bit identifier, BIN
172+
ARES_DATATYPE_OPT = 10 /*!< Array of options. 16bit identifier, BIN
173173
* data. */
174174
} ares_dns_datatype_t;
175175

@@ -292,7 +292,7 @@ typedef enum {
292292
/*! RAW Record. RR Type. Datatype: U16 */
293293
ARES_RR_RAW_RR_TYPE = (ARES_REC_TYPE_RAW_RR * 100) + 1,
294294
/*! RAW Record. RR Data. Datatype: BIN */
295-
ARES_RR_RAW_RR_DATA = (ARES_REC_TYPE_RAW_RR * 100) + 2,
295+
ARES_RR_RAW_RR_DATA = (ARES_REC_TYPE_RAW_RR * 100) + 2
296296
} ares_dns_rr_key_t;
297297

298298
/*! TLSA Record ARES_RR_TLSA_CERT_USAGE known values */
@@ -372,7 +372,7 @@ typedef enum {
372372
/*! RFC 8145. Signaling Trust Anchor Knowledge in DNSSEC */
373373
ARES_OPT_PARAM_EDNS_KEY_TAG = 14,
374374
/*! RFC 8914. Extended ERROR code and message */
375-
ARES_OPT_PARAM_EXTENDED_DNS_ERROR = 15,
375+
ARES_OPT_PARAM_EXTENDED_DNS_ERROR = 15
376376
} ares_opt_param_t;
377377

378378
/*! Data type for option records for keys like ARES_RR_OPT_OPTIONS and

src/lib/ares__addrinfo2hostent.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,13 @@ ares_status_t ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family,
165165
if (family == AF_INET6) {
166166
memcpy(
167167
(*host)->h_addr_list[i],
168-
&(CARES_INADDR_CAST(struct sockaddr_in6 *, next->ai_addr)->sin6_addr),
168+
&(CARES_INADDR_CAST(const struct sockaddr_in6 *, next->ai_addr)->sin6_addr),
169169
(size_t)(*host)->h_length);
170170
}
171171
if (family == AF_INET) {
172172
memcpy(
173173
(*host)->h_addr_list[i],
174-
&(CARES_INADDR_CAST(struct sockaddr_in *, next->ai_addr)->sin_addr),
174+
&(CARES_INADDR_CAST(const struct sockaddr_in *, next->ai_addr)->sin_addr),
175175
(size_t)(*host)->h_length);
176176
}
177177
++i;
@@ -256,7 +256,7 @@ ares_status_t ares__addrinfo2addrttl(const struct ares_addrinfo *ai, int family,
256256

257257
memcpy(
258258
&addr6ttls[*naddrttls].ip6addr,
259-
&(CARES_INADDR_CAST(struct sockaddr_in6 *, next->ai_addr)->sin6_addr),
259+
&(CARES_INADDR_CAST(const struct sockaddr_in6 *, next->ai_addr)->sin6_addr),
260260
sizeof(struct ares_in6_addr));
261261
} else {
262262
if (next->ai_ttl > cname_ttl) {
@@ -266,7 +266,7 @@ ares_status_t ares__addrinfo2addrttl(const struct ares_addrinfo *ai, int family,
266266
}
267267
memcpy(
268268
&addrttls[*naddrttls].ipaddr,
269-
&(CARES_INADDR_CAST(struct sockaddr_in *, next->ai_addr)->sin_addr),
269+
&(CARES_INADDR_CAST(const struct sockaddr_in *, next->ai_addr)->sin_addr),
270270
sizeof(struct in_addr));
271271
}
272272
(*naddrttls)++;

src/lib/ares_event_configchg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ ares_status_t ares_event_configchg_init(ares_event_configchg_t **configchg,
473473
continue;
474474
}
475475

476-
pdns_configuration_notify_key =
476+
pdns_configuration_notify_key = (const char *(*)(void))
477477
dlsym(handle, "dns_configuration_notify_key");
478478
if (pdns_configuration_notify_key != NULL) {
479479
break;

src/lib/ares_gethostbyname.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,17 @@ static void ares_gethostbyname_callback(void *arg, int status, int timeouts,
102102
void ares_gethostbyname(ares_channel_t *channel, const char *name, int family,
103103
ares_host_callback callback, void *arg)
104104
{
105-
const struct ares_addrinfo_hints hints = { ARES_AI_CANONNAME, family, 0, 0 };
106-
struct host_query *ghbn_arg;
105+
struct ares_addrinfo_hints hints;
106+
struct host_query *ghbn_arg;
107107

108108
if (!callback) {
109109
return;
110110
}
111111

112+
memset(&hints, 0, sizeof(hints));
113+
hints.ai_flags = ARES_AI_CANONNAME;
114+
hints.ai_family = family;
115+
112116
ghbn_arg = ares_malloc(sizeof(*ghbn_arg));
113117
if (!ghbn_arg) {
114118
callback(arg, ARES_ENOMEM, 0, NULL);

src/lib/ares_getnameinfo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ static void ares_getnameinfo_int(ares_channel_t *channel,
100100
/* Validate socket address family and length */
101101
if (sa && sa->sa_family == AF_INET &&
102102
salen >= (ares_socklen_t)sizeof(struct sockaddr_in)) {
103-
addr = CARES_INADDR_CAST(struct sockaddr_in *, sa);
103+
addr = CARES_INADDR_CAST(const struct sockaddr_in *, sa);
104104
port = addr->sin_port;
105105
} else if (sa && sa->sa_family == AF_INET6 &&
106106
salen >= (ares_socklen_t)sizeof(struct sockaddr_in6)) {
107-
addr6 = CARES_INADDR_CAST(struct sockaddr_in6 *, sa);
107+
addr6 = CARES_INADDR_CAST(const struct sockaddr_in6 *, sa);
108108
port = addr6->sin6_port;
109109
} else {
110110
callback(arg, ARES_ENOTIMP, 0, NULL, NULL);

src/lib/ares_private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
* warning: cast from 'const struct sockaddr *' to 'const struct sockaddr_in6 *'
4242
* increases required alignment from 1 to 4 [-Wcast-align]
4343
*/
44-
#define CARES_INADDR_CAST(type, var) ((type)((void *)var))
44+
#define CARES_INADDR_CAST(type, var) ((type)((const void *)var))
4545

4646
#if defined(USE_WINSOCK)
4747

0 commit comments

Comments
 (0)