Skip to content

Commit e697d0c

Browse files
authored
Update code to C11 and fix compilation warnings. (#252)
* updating C standard to C11 * more changes to get to c11 * add definitions for u_types if system does not provide * force c11 and other declarations errors when compiling on Linux * adding code definition to make res functions work * attempting to not override our definition of res * Only use the needed guard definitions * Fix HEADER rcode compilation error on Linux x86_64 - Add x86_64 architecture detection to nameser.h BYTE_ORDER logic - Remove unnecessary header guards from res.c - Fixes 'HEADER has no member named rcode' error on Linux x86_64 hosts * Fixing compilation errors to refer to h_addr_list[0] instead of just h_addr as it is not compatible with C11 * remove version.c as we do not need it tracked * Fix C11 compilation issues and reduce warnings - Fix HEADER rcode compilation error on Linux x86_64 by adding x86_64 architecture detection to nameser.h - Replace h_addr with h_addr_list[0] throughout codebase for C11 compatibility - Add missing header includes and feature test macros for implicit function declarations - Add void casts for intentionally ignored return values - Fix static variable in inline function warning - Fix const qualifier warning in SSL certificate verification Tested on Linux x86_64, amd64, and FreeBSD. Build now succeeds with significantly fewer warnings. * Uncomment random() and srandom() * Significantly reduce compilation warnings and fix C11 compatibility - Fix HEADER rcode compilation errors on Linux x86_64 - Replace h_addr with h_addr_list[0] throughout codebase for C11 compatibility - Make clang pragma directives conditional to eliminate GCC warnings - Add missing header includes and feature test macros - Increase MAX_DATE_STRING buffer size to fix format overflow warnings - Add void casts for intentionally ignored return values - Fix static variable in inline function and const qualifier issues Reduces compilation warnings by ~40% while maintaining full functionality. Tested successfully on Linux x86_64, amd64, and FreeBSD. * Eliminate unused return value and implicit declaration warnings - Fix all write(), getcwd(), setuid(), and fscanf() unused return value warnings using __attribute__((unused)) - Fix sbrk() implicit declaration by properly placing _DEFAULT_SOURCE and unistd.h includes - Clean up memcount.c header structure Reduces compilation warnings by ~80% (40+ warnings → 9 warnings). Remaining 9 warnings are harmless unused function declarations in ircd.c. Build tested successfully on Linux x86_64 with C11 standards. * Fix all compilation errors and significantly reduce warnings COMPILATION FIXES: - Fix HEADER rcode compilation errors on Linux x86_64 by adding x86_64 architecture detection - Replace h_addr with h_addr_list[0] throughout codebase for C11 compatibility - Fix syntax errors in ircd.c and s_bsd.c function structures WARNING REDUCTIONS (~65% reduction): - Make clang pragma directives conditional to eliminate GCC warnings - Fix all unused return value warnings using __attribute__((unused)) pattern - Fix all implicit function declaration warnings with proper includes - Add explicit sbrk declaration for C11 compatibility - Increase MAX_DATE_STRING buffer size to prevent format overflow - Add proper feature test macros (_DEFAULT_SOURCE, _GNU_SOURCE) Build tested successfully on Linux x86_64, amd64, and FreeBSD. Remaining ~15 warnings are harmless format/string analysis warnings. * Fixing compilation warnings and addressing buffer sizes to comply with RFC and sizes needed * More fixes for handling new buffer sizes to address compilation warnings * Moved buffer length definitions earlier in file so they can be used throughout. Grouped all buffer length definitions together instead of having them scattered around * Fixing compilation issues * Increase buffer sizes to address compilation warnings * Resetting PATH_MAX to an appropriate value. Changed to strncpyzt to ensure null termination * Fixing write_pid to accommodate longer pids but also truncate file in case a shorter pid needs to be written * Removing USE_SSL definition
1 parent 3469619 commit e697d0c

35 files changed

+296
-356
lines changed

configure.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,10 @@ dnl Checks for programs.
360360
AC_PROG_CC
361361
AX_CFLAGS_WARN_ALL
362362
AX_CHECK_COMPILE_FLAG([-fno-strict-aliasing], [CFLAGS="$CFLAGS -fno-strict-aliasing"])
363-
AX_CHECK_COMPILE_FLAG([-fgnu89-inline], [CFLAGS="$CFLAGS -fgnu89-inline"])
363+
# Use modern C standard instead of GNU C89 inline behavior
364+
AX_CHECK_COMPILE_FLAG([-std=c11], [CFLAGS="$CFLAGS -std=c11"])
365+
# Remove -fgnu89-inline flag as it conflicts with C11 standard
366+
CFLAGS=`echo "$CFLAGS" | sed 's/-fgnu89-inline//g'`
364367
AC_CANONICAL_TARGET
365368
AC_SEARCH_LIBS([strerror],[cposix])
366369
AC_PROG_MAKE_SET

include/confparse.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct TopConf
1717
unsigned int flag; /* our token flag */
1818
unsigned int nest; /* tokens we allow to nest here */
1919
sConf *subtok; /* sub-tokens allowed in here */
20-
int (*func) (); /* function to call to add this */
20+
int (*func) (cVar **, int); /* function to call to add this */
2121
};
2222

2323
/* sub-token options */

include/h.h

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ extern int local_ip_limit, local_ip24_limit, global_ip_limit,
6969
global_ip24_limit;
7070

7171
#ifndef PATH_MAX
72-
#define PATH_MAX 4096
72+
#define PATH_MAX 4120 /* 4096 + reasonable space for appended filenames and null terminators */
7373
#endif
7474
extern char dpath[PATH_MAX], spath[PATH_MAX];
7575

@@ -90,7 +90,7 @@ extern struct stats *ircstp;
9090
extern int bootopt;
9191

9292
extern char *canonize(char *);
93-
extern void check_fdlists();
93+
extern void check_fdlists(void);
9494
extern aChannel *find_channel(char *, aChannel *);
9595
extern void flush_user_banserial(aClient *);
9696
extern aBan *nick_is_banned(aChannel *, char *, aClient *);
@@ -119,9 +119,9 @@ extern aClient *find_chasing(aClient *, char *, int *);
119119
extern int find_restrict(aClient *);
120120
extern int rehash(aClient *, aClient *, int);
121121
extern int initconf(char *);
122-
extern inline char *finishconf(void);
123-
extern void merge_confs();
124-
extern int lock_kline_file();
122+
extern char *finishconf(void);
123+
extern void merge_confs(void);
124+
extern int lock_kline_file(void);
125125

126126
extern void clear_scache_hash_table(void);
127127
extern char *find_or_add(char *);
@@ -195,13 +195,13 @@ extern void add_local_domain(char *, int);
195195
extern int check_client(aClient *);
196196
extern int check_server_init(aClient *);
197197
extern void close_connection(aClient *);
198-
extern void close_listeners();
199-
extern void open_listeners();
198+
extern void close_listeners(void);
199+
extern void open_listeners(void);
200200
extern int connect_server(aConnect *, aClient *, struct hostent *);
201201
extern void get_my_name(aClient *, char *, int);
202202
extern int get_sockerr(aClient *);
203203
extern int inetport(aClient *, char *, int, u_long);
204-
extern void init_sys();
204+
extern void init_sys(void);
205205
extern int read_message(time_t, fdlist *);
206206
extern void report_error(char *, aClient *);
207207
extern void set_non_blocking(int, aClient *);
@@ -218,7 +218,7 @@ extern int do_client_queue(aClient *);
218218
extern void read_error_exit(aClient *, int, int);
219219
extern int readwrite_client(aClient *, int, int);
220220

221-
extern inline char *get_listener_name(aListener *);
221+
extern char *get_listener_name(aListener *);
222222
extern int attach_Iline(aClient *, struct hostent *, char *);
223223
extern aConnect *find_aConnect(char *);
224224
extern aOper *find_oper(char *, char *, char *, char *);
@@ -238,8 +238,8 @@ extern void terminate(void), write_pidfile(void);
238238
extern int match(char *, char *);
239239
extern char *collapse(char *);
240240

241-
extern int load_settings();
242-
extern int save_settings();
241+
extern int load_settings(void);
242+
extern int save_settings(void);
243243

244244
extern int writecalls, writeb[];
245245
#ifdef WRITEV_IOV
@@ -263,7 +263,7 @@ extern int do_numeric(int, aClient *, aClient *, int, char **);
263263
extern int hunt_server(aClient *, aClient *, char *, int, int, char **);
264264
extern aClient *next_client(aClient *, char *);
265265
extern aClient *next_client_double(aClient *, char *);
266-
extern inline void verbose_to_opers(aClient *sptr, aChannel *chptr, char *cmd, char *reason); /* for m_message() */
266+
extern void verbose_to_opers(aClient *sptr, aChannel *chptr, char *cmd, char *reason); /* for m_message() */
267267

268268
extern int m_umode(aClient *, aClient *, int, char **);
269269
extern int m_names(aClient *, aClient *, int, char **);
@@ -278,7 +278,7 @@ extern void free_chanmember(chanMember *);
278278
extern void free_class(aClass *);
279279
extern void free_user(anUser *, aClient *);
280280
extern void free_channel(aChannel *);
281-
extern aChannel *make_channel();
281+
extern aChannel *make_channel(char *name);
282282
extern Link *make_link(void);
283283
extern DLink *make_dlink(void);
284284
extern chanMember *make_chanmember(void);
@@ -297,7 +297,7 @@ extern void block_garbage_collect(void); /* list.c */
297297
extern void block_destroy(void); /* list.c */
298298

299299
extern void set_effective_class(aClient *);
300-
extern void initclass();
300+
extern void initclass(void);
301301

302302
extern struct hostent *get_res(char *);
303303
extern struct hostent *gethost_byaddr(char *, Link *, int);
@@ -348,9 +348,9 @@ extern FILE *dumpfp;
348348
#endif
349349

350350
#ifdef FLUD
351-
int check_for_flood();
352-
void free_fluders();
353-
void free_fludees();
351+
int check_for_flood(aClient *cptr, char *text);
352+
void free_fluders(aClient *cptr, aChannel *chptr);
353+
void free_fludees(aClient *cptr);
354354
#define MyFludConnect(x) (((x)->fd >= 0) || ((x)->fd == -2))
355355

356356
#endif /* FLUD */
@@ -380,7 +380,6 @@ int probability_loadsets(char *);
380380
void probability_fini(void);
381381
void get_probabilities(aClient *, int *, int *, int *);
382382

383-
#ifdef USE_SSL
384383
int ssl_init();
385384
int ssl_rehash();
386385
int safe_ssl_read(aClient *, void *, int);
@@ -389,7 +388,6 @@ int safe_ssl_accept(aClient *, int);
389388
int ssl_smart_shutdown(SSL *);
390389
int safe_ssl_connect(aClient *);
391390
int ssl_verify_callback(int, X509_STORE_CTX *);
392-
#endif
393391

394392

395393
#include "find.h"

include/inet.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#define __u_l unsigned long
3030
#endif
3131

32-
#ifdef __STDC__
3332
extern __u_l inet_addr(char *);
3433
extern char *inet_ntoa(char *);
3534
extern __u_l inet_makeaddr(int, int);
@@ -39,17 +38,4 @@ extern __u_l inet_netof(struct in_addr);
3938
extern int inet_pton(int, const char *, void *);
4039
extern const char *inet_ntop(int, const void *, char *, socklen_t);
4140

42-
#else
43-
extern __u_l inet_addr();
44-
extern char *inet_ntoa();
45-
46-
extern __u_l inet_makeaddr();
47-
48-
#endif
49-
extern __u_l inet_network();
50-
extern __u_l inet_lnaof();
51-
extern __u_l inet_netof();
52-
extern int inet_pton();
53-
extern const char *inet_ntop();
54-
5541
#undef __u_l

include/libcrypto-compat.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#define LIBCRYPTO_COMPAT_H
33

44
#include <struct.h>
5-
#ifdef USE_SSL
65

76
#if OPENSSL_VERSION_NUMBER < 0x10100000L
87

@@ -16,6 +15,4 @@ int DH_set_length(DH *dh, long length);
1615

1716
#endif /* OPENSSL_VERSION_NUMBER */
1817

19-
#endif /* USE_SSL */
20-
2118
#endif /* LIBCRYPTO_COMPAT_H */

include/msg.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ AliasInfo aliastab[] =
263263
{ 0 }
264264
};
265265

266+
#ifdef __clang__
267+
#pragma clang diagnostic push
268+
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
269+
#endif
266270
struct Message msgtab[] =
267271
{
268272
{MSG_PRIVATE, m_private, MAXPARA, MF_RIDLE, 0},
@@ -381,6 +385,9 @@ struct Message msgtab[] =
381385
{MSG_WEBIRC, m_webirc, MAXPARA, MF_UNREG, 0},
382386
{ 0 }
383387
};
388+
#ifdef __clang__
389+
#pragma clang diagnostic pop
390+
#endif
384391

385392
MESSAGE_TREE *msg_tree_root;
386393
#else

include/nameser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
#if defined(vax) || defined(ns32000) || defined(sun386) || defined(MIPSEL) || \
127127
defined(BIT_ZERO_ON_RIGHT) || defined(i386) ||\
128128
defined(___vax__) || defined(__ns32000__) || defined(__sun386__) ||\
129-
defined(__alpha)
129+
defined(__alpha) || defined(__x86_64__) || defined(__i386__) || defined(__amd64__)
130130

131131
#define BYTE_ORDER LITTLE_ENDIAN
132132

include/resolv.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ struct state {
104104
extern struct state _res;
105105
#endif
106106

107-
extern char *p_cdname(), *p_rr(), *p_type(), *p_class(), *p_time();
107+
extern char *p_cdname(char *, char *, char **);
108+
extern char *p_rr(char *, char *, char **);
109+
extern char *p_type(int);
110+
extern char *p_class(int);
111+
extern char *p_time(u_int32_t);
108112

109113
#if !defined(HAVE_RES_INIT) && defined(HAVE___RES_INIT)
110114
#define res_init __res_init
@@ -116,7 +120,7 @@ extern char *p_cdname(), *p_rr(), *p_type(), *p_class(), *p_time();
116120
#define dn_expand __dn_expand
117121
#endif
118122

119-
extern int res_mkquery ();
120-
extern int dn_expand ();
121-
extern int res_init();
123+
extern int res_mkquery(int, char *, int, int, char *, int, char *, char *, int);
124+
extern int dn_expand(unsigned char *, unsigned char *, unsigned char *, char *, int);
125+
extern int res_init(void);
122126
#endif

include/send.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extern int send_queued(aClient *);
3131
#include <stdarg.h>
3232
#include "fdlist.h"
3333

34-
extern void init_send();
34+
extern void init_send(void);
3535

3636
#ifndef ATTRIBUTE_PRINTF
3737
#if defined(__GNUC__) && __GNUC__ >= 4
@@ -93,6 +93,8 @@ extern void vsendto_prefix_one(aClient *to, aClient *from,
9393
char *pattern, va_list vl);
9494
extern void vsendto_realops(char *pattern, va_list vl);
9595

96-
extern void flush_connections();
97-
extern void dump_connections();
96+
extern void flush_connections(int fd);
97+
extern void dump_connections(int fd);
98+
extern void free_fluders(aClient *cptr, aChannel *chptr);
99+
extern void free_fludees(aClient *cptr);
98100
#endif

include/struct.h

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,46 @@
4949
#endif
5050
#endif
5151

52-
#ifdef USE_SSL
5352
#include <openssl/rsa.h> /* OpenSSL stuff */
5453
#include <openssl/crypto.h>
5554
#include <openssl/x509.h>
5655
#include <openssl/objects.h>
5756
#include <openssl/pem.h>
5857
#include <openssl/ssl.h>
5958
#include <openssl/err.h>
60-
#endif
59+
60+
/* ========================================================================
61+
* Buffer Length Definitions - defined early for use in extern declarations
62+
* ======================================================================== */
63+
64+
/* Core IRC protocol lengths */
65+
#define HOSTLEN 255 /* Length of hostname. RFC1123 compliant - maximum FQDN length is 255 */
66+
#define HOSTIPLEN 45 /* Length of an IPv4 or IPv6 address */
67+
#define NICKLEN 30 /* Maximum nickname length */
68+
#define USERLEN 10 /* Maximum username length */
69+
#define CHANNELLEN 32 /* Maximum channel name length */
70+
#define KEYLEN 23 /* Maximum channel key length */
71+
72+
/* Message and content lengths */
73+
#define REALLEN 50 /* Maximum real name length */
74+
#define TOPICLEN 307 /* Maximum topic length */
75+
#define PASSWDLEN 63 /* Maximum password length */
76+
#define MOTDLINELEN 90 /* Maximum MOTD line length */
77+
#define MAX_DATE_STRING 64 /* Maximum string length for a date string */
78+
#define MAXSILELENGTH 128 /* Maximum silence mask length */
79+
80+
/* Calculated lengths */
81+
#define KILLLEN (HOSTLEN * 3 + USERLEN + 10) /* 3 hostnames + username + separators */
82+
#define USERHOST_REPLYLEN (NICKLEN+HOSTLEN+USERLEN+5) /* nick!user@host format */
83+
84+
/* System buffer sizes */
85+
#define BUFSIZE 512 /* WARNING: *DONT* CHANGE THIS!!!! */
86+
87+
/* Protocol limits */
88+
#define MAXRECIPIENTS 20 /* Maximum recipients per message */
89+
#define MAXBANS 200 /* Maximum bans per channel */
90+
#define MAXINVITELIST 100 /* Maximum invite list entries */
91+
#define MAXEXEMPTLIST 100 /* Maximum exempt list entries */
6192

6293
#define REPORT_DO_DNS_ ":%s NOTICE AUTH :*** Looking up your hostname..."
6394
#define REPORT_FIN_DNS_ ":%s NOTICE AUTH :*** Found your hostname"
@@ -70,9 +101,9 @@
70101
#define REPORT_REJECT_ID_ ":%s NOTICE AUTH :*** Ignoring encrypted/unusable "\
71102
"Ident response"
72103

73-
extern char REPORT_DO_DNS[256], REPORT_FIN_DNS[256], REPORT_FIN_DNSC[256],
74-
REPORT_FAIL_DNS[256], REPORT_DO_ID[256], REPORT_FIN_ID[256],
75-
REPORT_FAIL_ID[256], REPORT_REJECT_ID[256];
104+
extern char REPORT_DO_DNS[HOSTLEN + 100], REPORT_FIN_DNS[HOSTLEN + 100], REPORT_FIN_DNSC[HOSTLEN + 100],
105+
REPORT_FAIL_DNS[HOSTLEN + 100], REPORT_DO_ID[HOSTLEN + 100], REPORT_FIN_ID[HOSTLEN + 100],
106+
REPORT_FAIL_ID[HOSTLEN + 100], REPORT_REJECT_ID[HOSTLEN + 100];
76107

77108
#include "hash.h"
78109

@@ -111,47 +142,22 @@ typedef struct SServicesTag ServicesTag;
111142

112143

113144

114-
#define HOSTLEN 63 /* Length of hostname. Updated to */
115-
116-
/* comply with RFC1123 */
117-
118-
#define HOSTIPLEN 45 /* Length of an IPv4 or IPv6 address */
119145

120-
#define NICKLEN 30
121146

122147
/* Necessary to put 9 here instead of 10 if
123148
* s_msg.c/m_nick has been corrected. This
124149
* preserves compatibility with old * servers --msa
125150
*/
126151

127-
#define MAX_DATE_STRING 32 /* maximum string length for a date string */
128-
129-
#define USERLEN 10
130-
#define REALLEN 50
131-
#define TOPICLEN 307
132-
#define KILLLEN 400
133-
#define CHANNELLEN 32
134-
#define PASSWDLEN 63
135-
#define KEYLEN 23
136-
#define BUFSIZE 512 /* WARNING: *DONT* CHANGE THIS!!!! */
137-
#define MAXRECIPIENTS 20
138-
#define MAXBANS 200
139-
#define MAXINVITELIST 100
140-
#define MAXEXEMPTLIST 100
141-
142-
#define MOTDLINELEN 90
143152

144153
#define MAXSILES 10
145-
#define MAXSILELENGTH 128
146154

147155
#define MAXDCCALLOW 5
148156
#define DCC_LINK_ME 0x01 /* This is my dcc allow */
149157
#define DCC_LINK_REMOTE 0x02 /* I need to remove these dcc allows from
150158
* these clients when I die
151159
*/
152160

153-
#define USERHOST_REPLYLEN (NICKLEN+HOSTLEN+USERLEN+5)
154-
155161
/*
156162
* 'offsetof' is defined in ANSI-C. The following definition * is not
157163
* absolutely portable (I have been told), but so far * it has worked
@@ -833,10 +839,8 @@ struct Listener {
833839
int clients; /* number of clients currently on this */
834840
aPort *aport; /* link to the P: line I came from */
835841
int flags; /* Flags for ssl (and nodns/noidentd in the future) */
836-
#ifdef USE_SSL
837842
SSL *ssl;
838843
X509 *client_cert;
839-
#endif
840844
};
841845

842846
struct SServicesTag
@@ -1064,10 +1068,8 @@ struct Client
10641068
unsigned int num_target_errors;
10651069
#endif
10661070

1067-
#ifdef USE_SSL
10681071
SSL *ssl;
10691072
X509 *client_cert;
1070-
#endif
10711073

10721074
char *webirc_username;
10731075
char *webirc_ip;

0 commit comments

Comments
 (0)