From 8431ac369b2f12ac376798fb01748f52d327164a Mon Sep 17 00:00:00 2001 From: cyberbotx Date: Sun, 23 Nov 2008 19:12:20 +0000 Subject: Converted many C-style casts to C++-style casts. git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1788 5417fbe8-f217-4b02-8779-1006273d7864 --- src/actions.c | 2 +- src/base64.c | 20 ++++++------- src/botserv.c | 14 +++++----- src/channels.c | 36 ++++++++++++------------ src/chanserv.c | 40 +++++++++++++------------- src/config.c | 4 +-- src/core/bs_badwords.c | 4 +-- src/core/bs_kick.c | 20 ++++++------- src/core/cs_access.c | 6 ++-- src/core/cs_akick.c | 4 +-- src/core/cs_ban.c | 2 +- src/core/cs_clear.c | 8 +++--- src/core/cs_set.c | 4 +-- src/core/cs_xop.c | 6 ++-- src/core/hs_delall.c | 6 ++-- src/core/hs_setall.c | 2 +- src/core/ms_set.c | 6 ++-- src/core/ns_access.c | 6 ++-- src/core/ns_group.c | 10 +++---- src/core/ns_identify.c | 2 +- src/core/ns_register.c | 12 ++++---- src/core/ns_saset.c | 2 +- src/core/ns_set.c | 2 +- src/core/os_admin.c | 16 +++++------ src/core/os_akill.c | 16 +++++------ src/core/os_oper.c | 14 +++++----- src/core/os_quit.c | 2 +- src/core/os_reload.c | 2 +- src/core/os_restart.c | 2 +- src/core/os_sgline.c | 12 ++++---- src/core/os_shutdown.c | 2 +- src/core/os_sqline.c | 12 ++++---- src/core/os_staff.c | 10 +++---- src/core/os_stats.c | 12 ++++---- src/core/os_szline.c | 12 ++++---- src/datafiles.c | 4 +-- src/events.c | 4 +-- src/hostserv.c | 4 +-- src/init.c | 2 +- src/log.c | 2 +- src/main.c | 6 ++-- src/memoserv.c | 4 +-- src/messages.c | 22 +++++++-------- src/misc.c | 24 ++++++++-------- src/modulemanager.cpp | 6 ++-- src/modules.c | 12 ++++---- src/modules/hs_request.c | 8 +++--- src/modules/os_ignore_db.c | 4 +-- src/news.c | 4 +-- src/nickserv.c | 16 +++++------ src/operserv.c | 68 ++++++++++++++++++++++----------------------- src/process.c | 6 ++-- src/protocol/bahamut.c | 6 ++-- src/protocol/inspircd11.c | 4 +-- src/protocol/inspircd12.cpp | 8 +++--- src/protocol/ratbox.c | 8 +++--- src/protocol/unreal32.c | 4 +-- src/servers.c | 4 +-- src/sessions.c | 10 +++---- src/slist.c | 22 +++++++-------- src/sockutil.c | 24 ++++++++-------- src/timeout.c | 4 +-- src/users.c | 6 ++-- 63 files changed, 313 insertions(+), 313 deletions(-) (limited to 'src') diff --git a/src/actions.c b/src/actions.c index 9d1a415d1..91f072051 100644 --- a/src/actions.c +++ b/src/actions.c @@ -167,7 +167,7 @@ void common_unban(ChannelInfo * ci, char *nick) ircdproto->SendBanDel(ci->name, nick); } else { if (ircdcap->tsmode) { - snprintf(buf, BUFSIZE - 1, "%ld", (long int) time(NULL)); + snprintf(buf, BUFSIZE - 1, "%ld", static_cast(time(NULL))); av[0] = ci->name; av[1] = buf; av[2] = "-b"; diff --git a/src/base64.c b/src/base64.c index 87212fa00..80022607b 100644 --- a/src/base64.c +++ b/src/base64.c @@ -184,7 +184,7 @@ int b64_decode(const char *src, char *target, size_t targsize) switch (state) { case 0: if (target) { - if ((size_t) tarindex >= targsize) + if (static_cast(tarindex) >= targsize) return (-1); target[tarindex] = (pos - Base64) << 2; } @@ -192,7 +192,7 @@ int b64_decode(const char *src, char *target, size_t targsize) break; case 1: if (target) { - if ((size_t) tarindex + 1 >= targsize) + if (static_cast(tarindex) + 1 >= targsize) return (-1); target[tarindex] |= (pos - Base64) >> 4; target[tarindex + 1] = ((pos - Base64) & 0x0f) @@ -203,7 +203,7 @@ int b64_decode(const char *src, char *target, size_t targsize) break; case 2: if (target) { - if ((size_t) tarindex + 1 >= targsize) + if (static_cast(tarindex) + 1 >= targsize) return (-1); target[tarindex] |= (pos - Base64) >> 2; target[tarindex + 1] = ((pos - Base64) & 0x03) @@ -214,7 +214,7 @@ int b64_decode(const char *src, char *target, size_t targsize) break; case 3: if (target) { - if ((size_t) tarindex >= targsize) + if (static_cast(tarindex) >= targsize) return (-1); target[tarindex] |= (pos - Base64); } @@ -290,13 +290,13 @@ const char* encode_ip(unsigned char *ip) if (!ip) return "*"; - if (strchr((char *) ip, ':')) { + if (strchr(reinterpret_cast(ip), ':')) { return NULL; } else { s_ip = str_signed(ip); ia.s_addr = inet_addr(s_ip); - cp = (unsigned char *) ia.s_addr; - b64_encode((char *) &cp, sizeof(struct in_addr), buf, 25); + cp = reinterpret_cast(ia.s_addr); + b64_encode(reinterpret_cast(&cp), sizeof(struct in_addr), buf, 25); } return buf; } @@ -308,7 +308,7 @@ int decode_ip(const char *buf) struct in_addr ia; b64_decode(buf, targ, 25); - ia = *(struct in_addr *) targ; + ia = *reinterpret_cast(targ); if (len == 24) { /* IPv6 */ return 0; } else if (len == 8) /* IPv4 */ @@ -378,14 +378,14 @@ static char *int_to_base64(long val) static long base64_to_int(char *b64) { - int v = base64_to_int6_map[(unsigned char) *b64++]; + int v = base64_to_int6_map[static_cast(*b64++)]; if (!b64) return 0; while (*b64) { v <<= 6; - v += base64_to_int6_map[(unsigned char) *b64++]; + v += base64_to_int6_map[static_cast(*b64++)]; } return v; diff --git a/src/botserv.c b/src/botserv.c index 404c8cefc..6b0a1bbf4 100644 --- a/src/botserv.c +++ b/src/botserv.c @@ -694,7 +694,7 @@ void bot_join(ChannelInfo * ci) int ac; if (ircdcap->tsmode) { - snprintf(buf, BUFSIZE - 1, "%ld", (long int) time(NULL)); + snprintf(buf, BUFSIZE - 1, "%ld", static_cast(time(NULL))); av[0] = ci->c->name; av[1] = buf; av[2] = "-b"; @@ -723,7 +723,7 @@ void bot_join(ChannelInfo * ci) /* Should we be invited? */ if ((ci->c->mode & anope_get_invite_mode()) - || (ci->c->limit && (unsigned int)ci->c->usercount >= ci->c->limit)) + || (ci->c->limit && ci->c->usercount >= ci->c->limit)) ircdproto->SendNoticeChanops(NULL, ci->c->name, "%s invited %s into the channel.", ci->bi->nick, ci->bi->nick); @@ -757,7 +757,7 @@ static void check_ban(ChannelInfo * ci, User * u, int ttbtype) get_idealban(ci, u, mask, sizeof(mask)); if (ircdcap->tsmode) { - snprintf(buf, BUFSIZE - 1, "%ld", (long int) time(NULL)); + snprintf(buf, BUFSIZE - 1, "%ld", static_cast(time(NULL))); av[0] = ci->name; av[1] = buf; av[2] = "+b"; @@ -845,7 +845,7 @@ void bot_raw_ban(User * requester, ChannelInfo * ci, char *nick, get_idealban(ci, u, mask, sizeof(mask)); if (ircdcap->tsmode) { - snprintf(buf, BUFSIZE - 1, "%ld", (long int) time(NULL)); + snprintf(buf, BUFSIZE - 1, "%ld", static_cast(time(NULL))); av[0] = ci->name; av[1] = buf; av[2] = "+b"; @@ -868,7 +868,7 @@ void bot_raw_ban(User * requester, ChannelInfo * ci, char *nick, kav[2] = ci->bi->nick; } else { if (strlen(reason) > 200) - *((char **)&reason[200]) = '\0'; // Unsafe cast -- will review later -- CyberBotX + (*const_cast(&reason))[200] = '\0'; // Unsafe cast -- will review later -- CyberBotX kav[2] = reason; } @@ -917,7 +917,7 @@ void bot_raw_kick(User * requester, ChannelInfo * ci, char *nick, av[2] = ci->bi->nick; } else { if (strlen(reason) > 200) - *((char **)&reason[200]) = '\0'; // Unsafe cast -- will review later -- CyberBotX + (*const_cast(&reason))[200] = '\0'; // Unsafe cast -- will review later -- CyberBotX av[2] = reason; } @@ -950,7 +950,7 @@ void bot_raw_mode(User * requester, ChannelInfo * ci, const char *mode, if (!u || !is_on_chan(ci->c, u)) return; - snprintf(buf, BUFSIZE - 1, "%ld", (long int) time(NULL)); + snprintf(buf, BUFSIZE - 1, "%ld", static_cast(time(NULL))); if (ircd->protectedumode) { if (is_protected(u) && *mode == '-' && (requester != u)) { diff --git a/src/channels.c b/src/channels.c index 4d6f1a3c6..a91ae2b0f 100644 --- a/src/channels.c +++ b/src/channels.c @@ -182,7 +182,7 @@ void chan_set_modes(const char *source, Channel * chan, int ac, const char **av, alog("debug: Removing instead of setting due to DEOPPED flag"); /* Swap adding and removing of the modes */ - for (s = (char *)av[0]; *s; s++) { // XXX Unsafe cast, this needs reviewing -- CyberBotX + for (s = const_cast(av[0]); *s; s++) { // XXX Unsafe cast, this needs reviewing -- CyberBotX if (*s == '+') *s = '-'; else if (*s == '-') @@ -208,13 +208,13 @@ void chan_set_modes(const char *source, Channel * chan, int ac, const char **av, continue; } - if (((int) mode) < 0) { + if (static_cast(mode) < 0) { if (debug) alog("Debug: Malformed mode detected on %s.", chan->name); continue; } - if ((cum = &cumodes[(int) mode])->status != 0) { + if ((cum = &cumodes[static_cast(mode)])->status != 0) { if (ac == 0) { alog("channel: mode %c%c with no parameter (?) for channel %s", add ? '+' : '-', mode, chan->name); continue; @@ -262,7 +262,7 @@ void chan_set_modes(const char *source, Channel * chan, int ac, const char **av, chan_remove_user_status(chan, user, cum->status); } - } else if ((cbm = &cbmodes[(int) mode])->flag != 0) { + } else if ((cbm = &cbmodes[static_cast(mode)])->flag != 0) { if (check >= 0) { if (add) chan->mode |= cbm->flag; @@ -288,7 +288,7 @@ void chan_set_modes(const char *source, Channel * chan, int ac, const char **av, else chan->mode &= ~cbm->flag; } - } else if ((cmm = &cmmodes[(int) mode])->addmask) { + } else if ((cmm = &cmmodes[static_cast(mode)])->addmask) { if (ac == 0) { alog("channel: mode %c%c with no parameter (?) for channel %s", add ? '+' : '-', mode, chan->name); continue; @@ -374,13 +374,13 @@ Channel *findchan(const char *chan) while (c) { if (stricmp(c->name, chan) == 0) { if (debug >= 3) - alog("debug: findchan(%s) -> %p", chan, (void *) c); + alog("debug: findchan(%s) -> %p", chan, static_cast(c)); return c; } c = c->next; } if (debug >= 3) - alog("debug: findchan(%s) -> %p", chan, (void *) c); + alog("debug: findchan(%s) -> %p", chan, static_cast(c)); return NULL; } @@ -539,7 +539,7 @@ void do_join(const char *source, int ac, const char **av) return; } - t = (char *)av[0]; // XXX Unsafe cast, this needs reviewing -- CyberBotX + t = const_cast(av[0]); // XXX Unsafe cast, this needs reviewing -- CyberBotX while (*(s = t)) { t = s + strcspn(s, ","); if (*t) @@ -576,7 +576,7 @@ void do_join(const char *source, int ac, const char **av) if (ac == 2) { if (debug) { alog("debug: recieved a new TS for JOIN: %ld", - (long int) ts); + static_cast(ts)); } ts = strtoul(av[1], NULL, 10); } @@ -605,7 +605,7 @@ void do_kick(const char *source, int ac, const char **av) char *s, *t; struct u_chanlist *c; - t = (char *)av[1]; // XXX unsafe cast, this needs reviewing -- w00t + t = const_cast(av[1]); // XXX unsafe cast, this needs reviewing -- w00t while (*(s = t)) { t = s + strcspn(s, ","); if (*t) @@ -682,7 +682,7 @@ void do_part(const char *source, int ac, const char **av) } return; } - t = (char *)av[0]; // XXX Unsafe cast, this needs reviewing -- CyberBotX + t = const_cast(av[0]); // XXX Unsafe cast, this needs reviewing -- CyberBotX while (*(s = t)) { t = s + strcspn(s, ","); if (*t) @@ -850,8 +850,8 @@ void do_sjoin(const char *source, int ac, const char **av) } } - while (csmodes[(int) *s] != 0) - *end2++ = csmodes[(int) *s++]; + while (csmodes[static_cast(*s)] != 0) + *end2++ = csmodes[static_cast(*s++)]; *end2 = 0; @@ -936,8 +936,8 @@ void do_sjoin(const char *source, int ac, const char **av) end2 = cubuf + 1; - while (csmodes[(int) *s] != 0) - *end2++ = csmodes[(int) *s++]; + while (csmodes[static_cast(*s)] != 0) + *end2++ = csmodes[static_cast(*s++)]; *end2 = 0; if (ircd->ts6) { @@ -1011,8 +1011,8 @@ void do_sjoin(const char *source, int ac, const char **av) end2 = cubuf + 1; - while (csmodes[(int) *s] != 0) - *end2++ = csmodes[(int) *s++]; + while (csmodes[static_cast(*s)] != 0) + *end2++ = csmodes[static_cast(*s++)]; *end2 = 0; if (ircd->ts6) { @@ -1788,7 +1788,7 @@ char *get_limit(Channel * chan) if (chan->limit == 0) return NULL; - snprintf(limit, sizeof(limit), "%lu", (unsigned long int) chan->limit); + snprintf(limit, sizeof(limit), "%lu", static_cast(chan->limit)); return limit; } diff --git a/src/chanserv.c b/src/chanserv.c index 944cd2e98..2751a24c1 100644 --- a/src/chanserv.c +++ b/src/chanserv.c @@ -387,17 +387,17 @@ void load_cs_dbase(void) for (j = 0; j < n_levels; j++) { SAFE(read_int16(&tmp16, f)); if (j < CA_SIZE) - ci->levels[j] = (int16) tmp16; + ci->levels[j] = static_cast(tmp16); } SAFE(read_int16(&ci->accesscount, f)); if (ci->accesscount) { - ci->access = (ChanAccess *)scalloc(ci->accesscount, sizeof(ChanAccess)); + ci->access = static_cast(scalloc(ci->accesscount, sizeof(ChanAccess))); for (j = 0; j < ci->accesscount; j++) { SAFE(read_int16(&ci->access[j].in_use, f)); if (ci->access[j].in_use) { SAFE(read_int16(&tmp16, f)); - ci->access[j].level = (int16) tmp16; + ci->access[j].level = static_cast(tmp16); SAFE(read_string(&s, f)); if (s) { ci->access[j].nc = findcore(s); @@ -415,7 +415,7 @@ void load_cs_dbase(void) SAFE(read_int16(&ci->akickcount, f)); if (ci->akickcount) { - ci->akick = (AutoKick *)scalloc(ci->akickcount, sizeof(AutoKick)); + ci->akick = static_cast(scalloc(ci->akickcount, sizeof(AutoKick))); for (j = 0; j < ci->akickcount; j++) { SAFE(read_int16(&ci->akick[j].flags, f)); if (ci->akick[j].flags & AK_USED) { @@ -468,12 +468,12 @@ void load_cs_dbase(void) } SAFE(read_int16(&tmp16, f)); - ci->memos.memocount = (int16) tmp16; + ci->memos.memocount = static_cast(tmp16); SAFE(read_int16(&tmp16, f)); - ci->memos.memomax = (int16) tmp16; + ci->memos.memomax = static_cast(tmp16); if (ci->memos.memocount) { Memo *memos; - memos = (Memo *)scalloc(sizeof(Memo) * ci->memos.memocount, 1); + memos = static_cast(scalloc(sizeof(Memo) * ci->memos.memocount, 1)); ci->memos.memos = memos; for (j = 0; j < ci->memos.memocount; j++, memos++) { SAFE(read_int32(&memos->number, f)); @@ -507,7 +507,7 @@ void load_cs_dbase(void) for (j = 0; j < n_ttb; j++) { SAFE(read_int16(&tmp16, f)); if (j < TTB_SIZE) - ci->ttb[j] = (int16) tmp16; + ci->ttb[j] = static_cast(tmp16); } for (j = n_ttb; j < TTB_SIZE; j++) ci->ttb[j] = 0; @@ -524,7 +524,7 @@ void load_cs_dbase(void) SAFE(read_int16(&ci->bwcount, f)); if (ci->bwcount) { - ci->badwords = (BadWord *)scalloc(ci->bwcount, sizeof(BadWord)); + ci->badwords = static_cast(scalloc(ci->bwcount, sizeof(BadWord))); for (j = 0; j < ci->bwcount; j++) { SAFE(read_int16(&ci->badwords[j].in_use, f)); if (ci->badwords[j].in_use) { @@ -791,7 +791,7 @@ void check_modes(Channel * c) else value = cbmi->csgetvalue(ci); - cbm = &cbmodes[(int) cbmi->mode]; + cbm = &cbmodes[static_cast(cbmi->mode)]; cbm->setvalue(c, value); if (value) { @@ -817,7 +817,7 @@ void check_modes(Channel * c) if (value && csvalue && strcmp(value, csvalue)) { *end++ = cbmi->mode; - cbm = &cbmodes[(int) cbmi->mode]; + cbm = &cbmodes[static_cast(cbmi->mode)]; cbm->setvalue(c, csvalue); *end2++ = ' '; @@ -845,7 +845,7 @@ void check_modes(Channel * c) /* Add the eventual parameter and clean up the Channel structure */ if (cbmi->getvalue) { - cbm = &cbmodes[(int) cbmi->mode]; + cbm = &cbmodes[static_cast(cbmi->mode)]; if (!(cbm->flags & CBM_MINUS_NO_ARG)) { char *value = cbmi->getvalue(c); @@ -1102,14 +1102,14 @@ int check_should_protect(User * user, char *chan) static void timeout_leave(Timeout * to) { - const char *chan = (const char *)to->data; + const char *chan = static_cast(to->data); ChannelInfo *ci = cs_findchan(chan); if (ci) /* Check cos the channel may be dropped in the meantime */ ci->flags &= ~CI_INHABIT; ircdproto->SendPart(findbot(s_ChanServ), chan, NULL); - delete [] (const char *)to->data; + delete [] static_cast(to->data); } @@ -1228,7 +1228,7 @@ int check_kick(User * user, const char *chan, time_t chants) if (c) { if (ircdcap->tsmode) { - snprintf(buf, BUFSIZE - 1, "%ld", (long int) time(NULL)); + snprintf(buf, BUFSIZE - 1, "%ld", static_cast(time(NULL))); av[0] = chan; av[1] = buf; av[2] = "+b"; @@ -1507,7 +1507,7 @@ ChannelInfo *cs_findchan(const char *chan) return NULL; } - for (ci = chanlists[(unsigned char) tolower(chan[1])]; ci; + for (ci = chanlists[static_cast(tolower(chan[1]))]; ci; ci = ci->next) { if (stricmp(ci->name, chan) == 0) return ci; @@ -1572,13 +1572,13 @@ void alpha_insert_chan(ChannelInfo * ci) chan = ci->name; - for (prev = NULL, ptr = chanlists[(unsigned char) tolower(chan[1])]; + for (prev = NULL, ptr = chanlists[static_cast(tolower(chan[1]))]; ptr != NULL && stricmp(ptr->name, chan) < 0; prev = ptr, ptr = ptr->next); ci->prev = prev; ci->next = ptr; if (!prev) - chanlists[(unsigned char) tolower(chan[1])] = ci; + chanlists[static_cast(tolower(chan[1]))] = ci; else prev->next = ci; if (ptr) @@ -1682,7 +1682,7 @@ int delchan(ChannelInfo * ci) if (ci->prev) ci->prev->next = ci->next; else - chanlists[(unsigned char) tolower(ci->name[1])] = ci->next; + chanlists[static_cast(tolower(ci->name[1]))] = ci->next; if (ci->desc) delete [] ci->desc; if (ci->url) @@ -1994,7 +1994,7 @@ char *cs_get_limit(ChannelInfo * ci) return NULL; snprintf(limit, sizeof(limit), "%lu", - (unsigned long int) ci->mlock_limit); + static_cast(ci->mlock_limit)); return limit; } diff --git a/src/config.c b/src/config.c index 8846ebf39..ea3bea1c1 100644 --- a/src/config.c +++ b/src/config.c @@ -1627,7 +1627,7 @@ int read_config(int reload) if (s) { RootNumber++; ServicesRoots = - (char **)realloc(ServicesRoots, sizeof(char *) * RootNumber); + static_cast(realloc(ServicesRoots, sizeof(char *) * RootNumber)); ServicesRoots[RootNumber - 1] = sstrdup(s); } } while ((s = strtok(NULL, " "))); @@ -1647,7 +1647,7 @@ int read_config(int reload) do { if (s) { NumUlines++; - Ulines = (char **)realloc(Ulines, sizeof(char *) * NumUlines); + Ulines = static_cast(realloc(Ulines, sizeof(char *) * NumUlines)); Ulines[NumUlines - 1] = sstrdup(s); } } while ((s = strtok(NULL, " "))); diff --git a/src/core/bs_badwords.c b/src/core/bs_badwords.c index 15e7c15ef..3fce1698e 100644 --- a/src/core/bs_badwords.c +++ b/src/core/bs_badwords.c @@ -118,7 +118,7 @@ int do_badwords(User * u) if (i < BSBadWordsMax) { ci->bwcount++; ci->badwords = - (BadWord *)srealloc(ci->badwords, sizeof(BadWord) * ci->bwcount); + static_cast(srealloc(ci->badwords, sizeof(BadWord) * ci->bwcount)); } else { notice_lang(s_BotServ, u, BOT_BADWORDS_REACHED_LIMIT, BSBadWordsMax); @@ -211,7 +211,7 @@ int do_badwords(User * u) ci->bwcount--; } ci->badwords = - (BadWord *)srealloc(ci->badwords,sizeof(BadWord) * ci->bwcount); + static_cast(srealloc(ci->badwords,sizeof(BadWord) * ci->bwcount)); } } else if (stricmp(cmd, "LIST") == 0) { diff --git a/src/core/bs_kick.c b/src/core/bs_kick.c index 229b4dba2..55d230710 100644 --- a/src/core/bs_kick.c +++ b/src/core/bs_kick.c @@ -6,8 +6,8 @@ * Please read COPYING and README for further details. * * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - * + * Based on the original code of Services by Andy Church. + * * $Id$ * */ @@ -95,7 +95,7 @@ int do_kickcmd(User * u) if (!stricmp(value, "ON")) { if (ttb) { ci->ttb[TTB_BADWORDS] = - strtol(ttb, (char **) NULL, 10); + strtol(ttb, NULL, 10); /* Only error if errno returns ERANGE or EINVAL or we are less then 0 - TSL */ if (errno == ERANGE || errno == EINVAL || ci->ttb[TTB_BADWORDS] < 0) { @@ -124,7 +124,7 @@ int do_kickcmd(User * u) } else if (!stricmp(option, "BOLDS")) { if (!stricmp(value, "ON")) { if (ttb) { - ci->ttb[TTB_BOLDS] = strtol(ttb, (char **) NULL, 10); + ci->ttb[TTB_BOLDS] = strtol(ttb, NULL, 10); if (errno == ERANGE || errno == EINVAL || ci->ttb[TTB_BOLDS] < 0) { if (debug) { @@ -152,7 +152,7 @@ int do_kickcmd(User * u) char *percent = strtok(NULL, " "); if (ttb) { - ci->ttb[TTB_CAPS] = strtol(ttb, (char **) NULL, 10); + ci->ttb[TTB_CAPS] = strtol(ttb, NULL, 10); if (errno == ERANGE || errno == EINVAL || ci->ttb[TTB_CAPS] < 0) { if (debug) { @@ -194,7 +194,7 @@ int do_kickcmd(User * u) } else if (!stricmp(option, "COLORS")) { if (!stricmp(value, "ON")) { if (ttb) { - ci->ttb[TTB_COLORS] = strtol(ttb, (char **) NULL, 10); + ci->ttb[TTB_COLORS] = strtol(ttb, NULL, 10); if (errno == ERANGE || errno == EINVAL || ci->ttb[TTB_COLORS] < 0) { if (debug) { @@ -222,7 +222,7 @@ int do_kickcmd(User * u) char *secs = strtok(NULL, " "); if (ttb) { - ci->ttb[TTB_FLOOD] = strtol(ttb, (char **) NULL, 10); + ci->ttb[TTB_FLOOD] = strtol(ttb, NULL, 10); if (errno == ERANGE || errno == EINVAL || ci->ttb[TTB_FLOOD] < 0) { if (debug) { @@ -266,7 +266,7 @@ int do_kickcmd(User * u) char *times = strtok(NULL, " "); if (ttb) { - ci->ttb[TTB_REPEAT] = strtol(ttb, (char **) NULL, 10); + ci->ttb[TTB_REPEAT] = strtol(ttb, NULL, 10); if (errno == ERANGE || errno == EINVAL || ci->ttb[TTB_REPEAT] < 0) { if (debug) { @@ -301,7 +301,7 @@ int do_kickcmd(User * u) if (!stricmp(value, "ON")) { if (ttb) { ci->ttb[TTB_REVERSES] = - strtol(ttb, (char **) NULL, 10); + strtol(ttb, NULL, 10); if (errno == ERANGE || errno == EINVAL || ci->ttb[TTB_REVERSES] < 0) { if (debug) { @@ -327,7 +327,7 @@ int do_kickcmd(User * u) if (!stricmp(value, "ON")) { if (ttb) { ci->ttb[TTB_UNDERLINES] = - strtol(ttb, (char **) NULL, 10); + strtol(ttb, NULL, 10); if (errno == ERANGE || errno == EINVAL || ci->ttb[TTB_UNDERLINES] < 0) { if (debug) { diff --git a/src/core/cs_access.c b/src/core/cs_access.c index 486c482e4..604761d82 100644 --- a/src/core/cs_access.c +++ b/src/core/cs_access.c @@ -232,8 +232,8 @@ int do_access(User * u) if (i < CSAccessMax) { ci->accesscount++; ci->access = - (ChanAccess *)srealloc(ci->access, - sizeof(ChanAccess) * ci->accesscount); + static_cast(srealloc(ci->access, + sizeof(ChanAccess) * ci->accesscount)); } else { notice_lang(s_ChanServ, u, CHAN_ACCESS_REACHED_LIMIT, CSAccessMax); @@ -346,7 +346,7 @@ int do_access(User * u) ci->accesscount--; } ci->access = - (ChanAccess *)srealloc(ci->access,sizeof(ChanAccess) * ci->accesscount); + static_cast(srealloc(ci->access,sizeof(ChanAccess) * ci->accesscount)); /* We don't know the nick if someone used numbers, so we trigger the event without * nick param. We just do this once, even if someone enters a range. -Certus */ diff --git a/src/core/cs_akick.c b/src/core/cs_akick.c index df4bd69f5..cc90381d9 100644 --- a/src/core/cs_akick.c +++ b/src/core/cs_akick.c @@ -299,7 +299,7 @@ int do_akick(User * u) } ci->akickcount++; ci->akick = - (AutoKick *)srealloc(ci->akick, sizeof(AutoKick) * ci->akickcount); + static_cast(srealloc(ci->akick, sizeof(AutoKick) * ci->akickcount)); akick = &ci->akick[i]; akick->flags = AK_USED; if (nc) { @@ -518,7 +518,7 @@ int do_akick(User * u) ci->akickcount--; } ci->akick = - (AutoKick *)srealloc(ci->akick,sizeof(AutoKick) * ci->akickcount); + static_cast(srealloc(ci->akick,sizeof(AutoKick) * ci->akickcount)); } } else if (stricmp(cmd, "LIST") == 0) { int sent_header = 0; diff --git a/src/core/cs_ban.c b/src/core/cs_ban.c index 4f8db1fd0..77e1b0b9b 100644 --- a/src/core/cs_ban.c +++ b/src/core/cs_ban.c @@ -68,7 +68,7 @@ int do_ban(User * u) int is_same; if (!reason) { - reason = (char *)"Requested"; // XXX unsafe cast -- w00t + reason = const_cast("Requested"); // XXX unsafe cast -- w00t } else { if (strlen(reason) > 200) reason[200] = '\0'; diff --git a/src/core/cs_clear.c b/src/core/cs_clear.c index 3d2e13fdf..683468f58 100644 --- a/src/core/cs_clear.c +++ b/src/core/cs_clear.c @@ -185,7 +185,7 @@ int do_clear(User * u) ircd->adminunset+1 : ""), (isown ? ircd->ownerunset+1 : "")); if (ircdcap->tsmode) { - snprintf(buf, BUFSIZE - 1, "%ld", (long int) time(NULL)); + snprintf(buf, BUFSIZE - 1, "%ld", static_cast(time(NULL))); av[1] = buf; av[2] = tmp; /* We have to give as much nicks as modes.. - Viper */ @@ -221,7 +221,7 @@ int do_clear(User * u) (isadmin ? cu->user->nick : ""), (isown ? cu->user->nick : "")); if (ircdcap->tsmode) { - snprintf(buf, BUFSIZE - 1, "%ld", (long int) time(NULL)); + snprintf(buf, BUFSIZE - 1, "%ld", static_cast(time(NULL))); av[1] = buf; av[2] = tmp; /* We have to give as much nicks as modes.. - Viper */ @@ -256,7 +256,7 @@ int do_clear(User * u) continue; if (ircdcap->tsmode) { - snprintf(buf, BUFSIZE - 1, "%ld", (long int) time(NULL)); + snprintf(buf, BUFSIZE - 1, "%ld", static_cast(time(NULL))); av[0] = chan; av[1] = buf; av[2] = "-h"; @@ -300,7 +300,7 @@ int do_clear(User * u) continue; if (ircdcap->tsmode) { - snprintf(buf, BUFSIZE - 1, "%ld", (long int) time(NULL)); + snprintf(buf, BUFSIZE - 1, "%ld", static_cast(time(NULL))); av[0] = chan; av[1] = buf; av[2] = "-v"; diff --git a/src/core/cs_set.c b/src/core/cs_set.c index f6ed8611b..2861222fa 100644 --- a/src/core/cs_set.c +++ b/src/core/cs_set.c @@ -56,7 +56,7 @@ class CSSet : public Module c = createCommand("SET FOUNDER", NULL, NULL, CHAN_HELP_SET_FOUNDER, -1, -1, -1, -1); this->AddCommand(CHANSERV, c, MOD_UNIQUE); c = createCommand("SET SUCCESSOR", NULL, NULL, CHAN_HELP_SET_SUCCESSOR, -1, -1, -1, -1); - c->help_param1 = (char *) (long) CSMaxReg; + c->help_param1 = reinterpret_cast(static_cast(CSMaxReg)); this->AddCommand(CHANSERV, c, MOD_UNIQUE); c = createCommand("SET PASSWORD", NULL, NULL, CHAN_HELP_SET_PASSWORD, -1, -1, -1, -1); this->AddCommand(CHANSERV, c, MOD_UNIQUE); @@ -470,7 +470,7 @@ int do_set_mlock(User * u, ChannelInfo * ci, char *param) continue; } - if ((int) mode < 128 && (cbm = &cbmodes[(int) mode])->flag != 0) { + if (static_cast(mode) < 128 && (cbm = &cbmodes[static_cast(mode)])->flag != 0) { if ((cbm->flags & CBM_NO_MLOCK) || ((cbm->flags & CBM_NO_USER_MLOCK) && !is_oper(u))) { notice_lang(s_ChanServ, u, CHAN_SET_MLOCK_IMPOSSIBLE_CHAR, diff --git a/src/core/cs_xop.c b/src/core/cs_xop.c index a757f7968..e7d73d5c7 100644 --- a/src/core/cs_xop.c +++ b/src/core/cs_xop.c @@ -301,8 +301,8 @@ int do_xop(User * u, const char *xname, int xlev, int *xmsgs) if (i < CSAccessMax) { ci->accesscount++; ci->access = - (ChanAccess *)srealloc(ci->access, - sizeof(ChanAccess) * ci->accesscount); + static_cast(srealloc(ci->access, + sizeof(ChanAccess) * ci->accesscount)); } else { notice_lang(s_ChanServ, u, CHAN_XOP_REACHED_LIMIT, CSAccessMax); @@ -434,7 +434,7 @@ int do_xop(User * u, const char *xname, int xlev, int *xmsgs) ci->accesscount--; } ci->access = - (ChanAccess *)srealloc(ci->access,sizeof(ChanAccess) * ci->accesscount); + static_cast(srealloc(ci->access,sizeof(ChanAccess) * ci->accesscount)); } } else if (stricmp(cmd, "LIST") == 0) { int sent_header = 0; diff --git a/src/core/hs_delall.c b/src/core/hs_delall.c index c950afe60..ea6b35e62 100644 --- a/src/core/hs_delall.c +++ b/src/core/hs_delall.c @@ -6,8 +6,8 @@ * Please read COPYING and README for further details. * * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - * + * Based on the original code of Services by Andy Church. + * * $Id$ * */ @@ -72,7 +72,7 @@ int do_delall(User * u) } nc = na->nc; for (i = 0; i < nc->aliases.count; i++) { - na = (NickAlias *)nc->aliases.list[i]; + na = static_cast(nc->aliases.list[i]); delHostCore(na->nick); } alog("vHosts for all nicks in group \002%s\002 deleted by oper \002%s\002", nc->display, u->nick); diff --git a/src/core/hs_setall.c b/src/core/hs_setall.c index 10555d7b7..1e865cb58 100644 --- a/src/core/hs_setall.c +++ b/src/core/hs_setall.c @@ -57,7 +57,7 @@ void myHostServHelp(User * u) **/ int do_setall(User * u) { - char *nick = (char *)strtok(NULL, " "); + char *nick = strtok(NULL, " "); char *rawhostmask = strtok(NULL, " "); char *hostmask = new char[HOSTMAX]; diff --git a/src/core/ms_set.c b/src/core/ms_set.c index a4aebd3e0..f3d00bf8d 100644 --- a/src/core/ms_set.c +++ b/src/core/ms_set.c @@ -6,8 +6,8 @@ * Please read COPYING and README for further details. * * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - * + * Based on the original code of Services by Andy Church. + * * $Id$ * */ @@ -38,7 +38,7 @@ class MSSet : public Module this->AddCommand(MEMOSERV, c, MOD_UNIQUE); c = createCommand("SET LIMIT", NULL, NULL, -1, MEMO_HELP_SET_LIMIT, MEMO_SERVADMIN_HELP_SET_LIMIT, MEMO_SERVADMIN_HELP_SET_LIMIT, MEMO_SERVADMIN_HELP_SET_LIMIT); - c->help_param1 = (char *) (long) MSMaxMemos; + c->help_param1 = reinterpret_cast(static_cast(MSMaxMemos)); this->AddCommand(MEMOSERV, c, MOD_UNIQUE); moduleSetMemoHelp(myMemoServHelp); diff --git a/src/core/ns_access.c b/src/core/ns_access.c index c4409928d..7fb6ab79b 100644 --- a/src/core/ns_access.c +++ b/src/core/ns_access.c @@ -125,7 +125,7 @@ int do_access(User * u) na->nc->accesscount++; na->nc->access = - (char **)srealloc(na->nc->access, sizeof(char *) * na->nc->accesscount); + static_cast(srealloc(na->nc->access, sizeof(char *) * na->nc->accesscount)); na->nc->access[na->nc->accesscount - 1] = sstrdup(mask); notice_lang(s_NickServ, u, NICK_ACCESS_ADDED, mask); @@ -149,8 +149,8 @@ int do_access(User * u) (na->nc->accesscount - i) * sizeof(char *)); if (na->nc->accesscount) /* if there are any entries left... */ na->nc->access = - (char **)srealloc(na->nc->access, - na->nc->accesscount * sizeof(char *)); + static_cast(srealloc(na->nc->access, + na->nc->accesscount * sizeof(char *))); else { free(na->nc->access); na->nc->access = NULL; diff --git a/src/core/ns_group.c b/src/core/ns_group.c index c40d961ac..10cb9fee8 100644 --- a/src/core/ns_group.c +++ b/src/core/ns_group.c @@ -104,14 +104,14 @@ int do_group(User * u) return MOD_CONT; } } - for (i = 0; i < servadmins.count && (nc = (NickCore *)servadmins.list[i]); i++) { + for (i = 0; i < servadmins.count && (nc = static_cast(servadmins.list[i])); i++) { if (stristr(u->nick, nc->display) && !is_oper(u)) { notice_lang(s_NickServ, u, NICK_CANNOT_BE_REGISTERED, u->nick); return MOD_CONT; } } - for (i = 0; i < servopers.count && (nc = (NickCore *)servopers.list[i]); i++) { + for (i = 0; i < servopers.count && (nc = static_cast(servopers.list[i])); i++) { if (stristr(u->nick, nc->display) && !is_oper(u)) { notice_lang(s_NickServ, u, NICK_CANNOT_BE_REGISTERED, u->nick); @@ -182,7 +182,7 @@ int do_group(User * u) common_get_vhost(u)); na->last_realname = sstrdup(u->realname); na->time_registered = na->last_seen = time(NULL); - na->status = (int16) (NS_IDENTIFIED | NS_RECOGNIZED); + na->status = static_cast(NS_IDENTIFIED | NS_RECOGNIZED); if (!(na->nc->flags & NI_SERVICES_ROOT)) { for (i = 0; i < RootNumber; i++) { @@ -202,7 +202,7 @@ int do_group(User * u) u->lastnickreg = time(NULL); snprintf(tsbuf, sizeof(tsbuf), "%lu", - (unsigned long int) u->timestamp); + static_cast(u->timestamp)); if (ircd->modeonreg) { len = strlen(ircd->modeonreg); strncpy(modes,ircd->modeonreg,512); @@ -282,7 +282,7 @@ int do_glist(User * u) nick ? NICK_GLIST_HEADER_X : NICK_GLIST_HEADER, na->nc->display); for (i = 0; i < na->nc->aliases.count; i++) { - na2 = (NickAlias *)na->nc->aliases.list[i]; + na2 = static_cast(na->nc->aliases.list[i]); if (na2->nc == na->nc) { if (!(wont_expire = na2->status & NS_NO_EXPIRE)) { expt = na2->last_seen + NSExpire; diff --git a/src/core/ns_identify.c b/src/core/ns_identify.c index ee328ef19..19fc791bf 100644 --- a/src/core/ns_identify.c +++ b/src/core/ns_identify.c @@ -105,7 +105,7 @@ int do_identify(User * u) na->status |= NS_IDENTIFIED; na->last_seen = time(NULL); snprintf(tsbuf, sizeof(tsbuf), "%lu", - (unsigned long int) u->timestamp); + static_cast(u->timestamp)); if (ircd->modeonreg) { len = strlen(ircd->modeonreg); diff --git a/src/core/ns_register.c b/src/core/ns_register.c index 692c21531..bb2e2d741 100644 --- a/src/core/ns_register.c +++ b/src/core/ns_register.c @@ -133,14 +133,14 @@ int do_register(User * u) return MOD_CONT; } } - for (i = 0; i < servadmins.count && (nc = (NickCore *)servadmins.list[i]); i++) { + for (i = 0; i < servadmins.count && (nc = static_cast(servadmins.list[i])); i++) { if (stristr(u->nick, nc->display) && !is_oper(u)) { notice_lang(s_NickServ, u, NICK_CANNOT_BE_REGISTERED, u->nick); return MOD_CONT; } } - for (i = 0; i < servopers.count && (nc = (NickCore *)servopers.list[i]); i++) { + for (i = 0; i < servopers.count && (nc = static_cast(servopers.list[i])); i++) { if (stristr(u->nick, nc->display) && !is_oper(u)) { notice_lang(s_NickServ, u, NICK_CANNOT_BE_REGISTERED, u->nick); @@ -180,7 +180,7 @@ int do_register(User * u) for (idx = 0; idx < 9; idx++) { passcode[idx] = chars[(1 + - (int) (((float) (max - min)) * getrandom16() / + static_cast((static_cast(max - min)) * getrandom16() / (65535 + 1.0)) + min)]; } passcode[idx] = '\0'; nr = makerequest(u->nick); @@ -301,7 +301,7 @@ int do_confirm(User * u) char tmp_pass[PASSMAX]; memcpy(na->nc->pass, nr->password, PASSMAX); - na->status = (int16) (NS_IDENTIFIED | NS_RECOGNIZED); + na->status = static_cast(NS_IDENTIFIED | NS_RECOGNIZED); /* na->nc->flags |= NI_ENCRYPTEDPW; */ na->nc->flags |= NSDefFlags; @@ -326,7 +326,7 @@ int do_confirm(User * u) na->time_registered = na->last_seen = time(NULL); if (NSAddAccessOnReg) { na->nc->accesscount = 1; - na->nc->access = (char **)scalloc(sizeof(char *), 1); + na->nc->access = static_cast(scalloc(sizeof(char *), 1)); na->nc->access[0] = create_mask(u); } else { na->nc->accesscount = 0; @@ -365,7 +365,7 @@ int do_confirm(User * u) if (ircd->tsonmode) { snprintf(tsbuf, sizeof(tsbuf), "%lu", - (unsigned long int) u->timestamp); + static_cast(u->timestamp)); common_svsmode(u, modes, tsbuf); } else { common_svsmode(u, modes, NULL); diff --git a/src/core/ns_saset.c b/src/core/ns_saset.c index 54fb2fc0f..4bc2eab66 100644 --- a/src/core/ns_saset.c +++ b/src/core/ns_saset.c @@ -170,7 +170,7 @@ int do_saset_display(User * u, NickCore * nc, char *param) /* First check whether param is a valid nick of the group */ for (i = 0; i < nc->aliases.count; i++) { - na = (NickAlias *)nc->aliases.list[i]; + na = static_cast(nc->aliases.list[i]); if (stricmp(na->nick, param) == 0) { param = na->nick; /* Because case may differ */ break; diff --git a/src/core/ns_set.c b/src/core/ns_set.c index 4267f46b2..221743603 100644 --- a/src/core/ns_set.c +++ b/src/core/ns_set.c @@ -154,7 +154,7 @@ int do_set_display(User * u, NickCore * nc, char *param) /* First check whether param is a valid nick of the group */ for (i = 0; i < nc->aliases.count; i++) { - na = (NickAlias *)nc->aliases.list[i]; + na = static_cast(nc->aliases.list[i]); if (!stricmp(na->nick, param)) { param = na->nick; /* Because case may differ */ break; diff --git a/src/core/os_admin.c b/src/core/os_admin.c index d7e8c3c75..21905e3b5 100644 --- a/src/core/os_admin.c +++ b/src/core/os_admin.c @@ -6,8 +6,8 @@ * Please read COPYING and README for further details. * * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - * + * Based on the original code of Services by Andy Church. + * * $Id$ * */ @@ -154,7 +154,7 @@ int do_admin(User * u) notice_lang(s_OperServ, u, READ_ONLY_MODE); } else if (!stricmp(cmd, "LIST")) { int sent_header = 0; - + if (servadmins.count == 0) { notice_lang(s_OperServ, u, OPER_ADMIN_LIST_EMPTY); return MOD_CONT; @@ -176,11 +176,11 @@ int do_admin(User * u) for (i = 0; i < servadmins.count; i++) if (!stricmp - (nick, ((NickCore *) servadmins.list[i])->display) + (nick, (static_cast(servadmins.list[i]))->display) || match_wild_nocase(nick, - ((NickCore *) servadmins. - list[i])->display)) - admin_list(i + 1, (NickCore *)servadmins.list[i], u, &sent_header); + (static_cast(servadmins. + list[i]))->display)) + admin_list(i + 1, static_cast(servadmins.list[i]), u, &sent_header); if (!sent_header) notice_lang(s_OperServ, u, OPER_ADMIN_NO_MATCH); @@ -213,7 +213,7 @@ int admin_list_callback(SList * slist, int number, void *item, User *u = va_arg(args, User *); int *sent_header = va_arg(args, int *); - return admin_list(number, (NickCore *)item, u, sent_header); + return admin_list(number, static_cast(item), u, sent_header); } int admin_list(int number, NickCore * nc, User * u, int *sent_header) diff --git a/src/core/os_akill.c b/src/core/os_akill.c index a85c50cb1..c2c6a2d64 100644 --- a/src/core/os_akill.c +++ b/src/core/os_akill.c @@ -249,11 +249,11 @@ int do_akill(User * u) for (i = 0; i < akills.count; i++) { snprintf(amask, sizeof(amask), "%s@%s", - ((Akill *) akills.list[i])->user, - ((Akill *) akills.list[i])->host); + (static_cast(akills.list[i]))->user, + (static_cast(akills.list[i]))->host); if (!stricmp(mask, amask) || match_wild_nocase(mask, amask)) - akill_list(i + 1, (Akill *)akills.list[i], u, &sent_header); + akill_list(i + 1, static_cast(akills.list[i]), u, &sent_header); } if (!sent_header) @@ -288,11 +288,11 @@ int do_akill(User * u) for (i = 0; i < akills.count; i++) { snprintf(amask, sizeof(amask), "%s@%s", - ((Akill *) akills.list[i])->user, - ((Akill *) akills.list[i])->host); + (static_cast(akills.list[i]))->user, + (static_cast(akills.list[i]))->host); if (!stricmp(mask, amask) || match_wild_nocase(mask, amask)) - akill_view(i + 1, (Akill *)akills.list[i], u, &sent_header); + akill_view(i + 1, static_cast(akills.list[i]), u, &sent_header); } if (!sent_header) @@ -340,7 +340,7 @@ int akill_list_callback(SList * slist, int number, void *item, User *u = va_arg(args, User *); int *sent_header = va_arg(args, int *); - return akill_list(number, (Akill *)item, u, sent_header); + return akill_list(number, static_cast(item), u, sent_header); } /* Callback for enumeration purposes */ @@ -351,7 +351,7 @@ int akill_view_callback(SList * slist, int number, void *item, User *u = va_arg(args, User *); int *sent_header = va_arg(args, int *); - return akill_view(number, (Akill *)item, u, sent_header); + return akill_view(number, static_cast(item), u, sent_header); } /* Lists an AKILL entry, prefixing it with the header if needed */ diff --git a/src/core/os_oper.c b/src/core/os_oper.c index f93dab779..6586ceae7 100644 --- a/src/core/os_oper.c +++ b/src/core/os_oper.c @@ -6,8 +6,8 @@ * Please read COPYING and README for further details. * * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - * + * Based on the original code of Services by Andy Church. + * * $Id$ * */ @@ -154,7 +154,7 @@ int do_oper(User * u) notice_lang(s_OperServ, u, PERMISSION_DENIED); return MOD_CONT; } - + if (servopers.count == 0) { notice_lang(s_OperServ, u, OPER_OPER_LIST_EMPTY); return MOD_CONT; @@ -176,11 +176,11 @@ int do_oper(User * u) for (i = 0; i < servopers.count; i++) if (!stricmp - (nick, ((NickCore *) servopers.list[i])->display) + (nick, (static_cast(servopers.list[i]))->display) || match_wild_nocase(nick, - ((NickCore *) servopers.list[i])-> + (static_cast(servopers.list[i]))-> display)) - oper_list(i + 1, (NickCore *)servopers.list[i], u, &sent_header); + oper_list(i + 1, static_cast(servopers.list[i]), u, &sent_header); if (!sent_header) notice_lang(s_OperServ, u, OPER_OPER_NO_MATCH); @@ -230,7 +230,7 @@ int oper_list_callback(SList * slist, int number, void *item, va_list args) User *u = va_arg(args, User *); int *sent_header = va_arg(args, int *); - return oper_list(number, (NickCore *)item, u, sent_header); + return oper_list(number, static_cast(item), u, sent_header); } MODULE_INIT("os_oper", OSOper) diff --git a/src/core/os_quit.c b/src/core/os_quit.c index a06bb6966..9ae6b05be 100644 --- a/src/core/os_quit.c +++ b/src/core/os_quit.c @@ -59,7 +59,7 @@ int do_os_quit(User * u) if (!quitmsg) quitmsg = "QUIT command received, but out of memory!"; else - sprintf((char *)quitmsg, "QUIT command received from %s", u->nick); // XXX we know this is safe, but.. + sprintf(const_cast(quitmsg), "QUIT command received from %s", u->nick); // XXX we know this is safe, but.. if (GlobalOnCycle) { oper_global(NULL, "%s", GlobalOnCycleMessage); diff --git a/src/core/os_reload.c b/src/core/os_reload.c index 9e4495ec4..e31c1207c 100644 --- a/src/core/os_reload.c +++ b/src/core/os_reload.c @@ -61,7 +61,7 @@ int do_reload(User * u) quitmsg = "Error during the reload of the configuration file, but out of memory!"; else - sprintf((char *)quitmsg, /* XXX */ + sprintf(const_cast(quitmsg), /* XXX */ "Error during the reload of the configuration file!"); quitting = 1; } diff --git a/src/core/os_restart.c b/src/core/os_restart.c index fe0f8ddb7..537db5d3a 100644 --- a/src/core/os_restart.c +++ b/src/core/os_restart.c @@ -64,7 +64,7 @@ int do_restart(User * u) if (!quitmsg) quitmsg = "RESTART command received, but out of memory!"; else - sprintf((char *)quitmsg, /* XXX */ "RESTART command received from %s", u->nick); + sprintf(const_cast(quitmsg), /* XXX */ "RESTART command received from %s", u->nick); if (GlobalOnCycle) { oper_global(NULL, "%s", GlobalOnCycleMessage); diff --git a/src/core/os_sgline.c b/src/core/os_sgline.c index 49aa459fe..934a8abf5 100644 --- a/src/core/os_sgline.c +++ b/src/core/os_sgline.c @@ -229,10 +229,10 @@ int do_sgline(User * u) char *amask; for (i = 0; i < sglines.count; i++) { - amask = ((SXLine *) sglines.list[i])->mask; + amask = (static_cast(sglines.list[i]))->mask; if (!stricmp(mask, amask) || match_wild_nocase(mask, amask)) - sgline_list(i + 1, (SXLine *)sglines.list[i], u, &sent_header); + sgline_list(i + 1, static_cast(sglines.list[i]), u, &sent_header); } if (!sent_header) @@ -266,10 +266,10 @@ int do_sgline(User * u) char *amask; for (i = 0; i < sglines.count; i++) { - amask = ((SXLine *) sglines.list[i])->mask; + amask = (static_cast(sglines.list[i]))->mask; if (!stricmp(mask, amask) || match_wild_nocase(mask, amask)) - sgline_view(i + 1, (SXLine *)sglines.list[i], u, &sent_header); + sgline_view(i + 1, static_cast(sglines.list[i]), u, &sent_header); } if (!sent_header) @@ -317,7 +317,7 @@ int sgline_view_callback(SList * slist, int number, void *item, User *u = va_arg(args, User *); int *sent_header = va_arg(args, int *); - return sgline_view(number, (SXLine *)item, u, sent_header); + return sgline_view(number, static_cast(item), u, sent_header); } /* Lists an SGLINE entry, prefixing it with the header if needed */ @@ -346,7 +346,7 @@ int sgline_list_callback(SList * slist, int number, void *item, User *u = va_arg(args, User *); int *sent_header = va_arg(args, int *); - return sgline_list(number, (SXLine *)item, u, sent_header); + return sgline_list(number, static_cast(item), u, sent_header); } MODULE_INIT("os_sgline", OSSGLine) diff --git a/src/core/os_shutdown.c b/src/core/os_shutdown.c index 32ab16141..5fa4080a6 100644 --- a/src/core/os_shutdown.c +++ b/src/core/os_shutdown.c @@ -59,7 +59,7 @@ int do_shutdown(User * u) if (!quitmsg) quitmsg = "SHUTDOWN command received, but out of memory!"; else - sprintf((char *)quitmsg, /* XXX */ "SHUTDOWN command received from %s", u->nick); + sprintf(const_cast(quitmsg), /* XXX */ "SHUTDOWN command received from %s", u->nick); if (GlobalOnCycle) { oper_global(NULL, "%s", GlobalOnCycleMessage); diff --git a/src/core/os_sqline.c b/src/core/os_sqline.c index 072c224f8..822334f36 100644 --- a/src/core/os_sqline.c +++ b/src/core/os_sqline.c @@ -224,10 +224,10 @@ int do_sqline(User * u) char *amask; for (i = 0; i < sqlines.count; i++) { - amask = ((SXLine *) sqlines.list[i])->mask; + amask = (static_cast(sqlines.list[i]))->mask; if (!stricmp(mask, amask) || match_wild_nocase(mask, amask)) - sqline_list(i + 1, (SXLine *)sqlines.list[i], u, &sent_header); + sqline_list(i + 1, static_cast(sqlines.list[i]), u, &sent_header); } if (!sent_header) @@ -261,10 +261,10 @@ int do_sqline(User * u) char *amask; for (i = 0; i < sqlines.count; i++) { - amask = ((SXLine *) sqlines.list[i])->mask; + amask = (static_cast(sqlines.list[i]))->mask; if (!stricmp(mask, amask) || match_wild_nocase(mask, amask)) - sqline_view(i + 1, (SXLine *)sqlines.list[i], u, &sent_header); + sqline_view(i + 1, static_cast(sqlines.list[i]), u, &sent_header); } if (!sent_header) @@ -310,7 +310,7 @@ int sqline_view_callback(SList * slist, int number, void *item, User *u = va_arg(args, User *); int *sent_header = va_arg(args, int *); - return sqline_view(number, (SXLine *)item, u, sent_header); + return sqline_view(number, static_cast(item), u, sent_header); } /* Lists an SQLINE entry, prefixing it with the header if needed */ @@ -339,7 +339,7 @@ int sqline_list_callback(SList * slist, int number, void *item, User *u = va_arg(args, User *); int *sent_header = va_arg(args, int *); - return sqline_list(number, (SXLine *)item, u, sent_header); + return sqline_list(number, static_cast(item), u, sent_header); } MODULE_INIT("os_sqline", OSSQLine) diff --git a/src/core/os_staff.c b/src/core/os_staff.c index 9e5b820b4..c5a58121e 100644 --- a/src/core/os_staff.c +++ b/src/core/os_staff.c @@ -6,8 +6,8 @@ * Please read COPYING and README for further details. * * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - * + * Based on the original code of Services by Andy Church. + * * $Id$ * */ @@ -75,7 +75,7 @@ int do_staff(User * u) ServicesRoots[idx]); } else if ((nc = findcore(ServicesRoots[idx]))) { for (i = 0; i < nc->aliases.count; i++) { /* check all aliases */ - na = (NickAlias *)nc->aliases.list[i]; + na = static_cast(nc->aliases.list[i]); if ((au = finduser(na->nick))) { /* see if user is online */ found = 1; notice_lang(s_OperServ, u, OPER_STAFF_AFORMAT, @@ -102,7 +102,7 @@ int opers_list_callback(SList * slist, int number, void *item, User *u = va_arg(args, User *); char *level = va_arg(args, char *); - return opers_list(number, (NickCore *)item, u, level); + return opers_list(number, static_cast(item), u, level); } @@ -126,7 +126,7 @@ int opers_list(int number, NickCore * nc, User * u, char *level) nc->display); } else { for (i = 0; i < nc->aliases.count; i++) { /* check all aliases */ - na = (NickAlias *)nc->aliases.list[i]; + na = static_cast(nc->aliases.list[i]); if ((au = finduser(na->nick))) { /* see if user is online */ found = 1; notice_lang(s_OperServ, u, OPER_STAFF_AFORMAT, '*', level, diff --git a/src/core/os_stats.c b/src/core/os_stats.c index 35a0f03f7..d4dc8b085 100644 --- a/src/core/os_stats.c +++ b/src/core/os_stats.c @@ -6,8 +6,8 @@ * Please read COPYING and README for further details. * * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - * + * Based on the original code of Services by Andy Church. + * * $Id$ * */ @@ -382,7 +382,7 @@ void get_operserv_stats(long *nrec, long *memuse) mem += akills.count * sizeof(Akill); for (i = 0; i < akills.count; i++) { - ak = (Akill *)akills.list[i]; + ak = static_cast(akills.list[i]); mem += strlen(ak->user) + 1; mem += strlen(ak->host) + 1; mem += strlen(ak->by) + 1; @@ -395,7 +395,7 @@ void get_operserv_stats(long *nrec, long *memuse) mem += sglines.count * sizeof(SXLine); for (i = 0; i < sglines.count; i++) { - sx = (SXLine *)sglines.list[i]; + sx = static_cast(sglines.list[i]); mem += strlen(sx->mask) + 1; mem += strlen(sx->by) + 1; mem += strlen(sx->reason) + 1; @@ -407,7 +407,7 @@ void get_operserv_stats(long *nrec, long *memuse) mem += sqlines.count * sizeof(SXLine); for (i = 0; i < sqlines.count; i++) { - sx = (SXLine *)sqlines.list[i]; + sx = static_cast(sqlines.list[i]); mem += strlen(sx->mask) + 1; mem += strlen(sx->by) + 1; mem += strlen(sx->reason) + 1; @@ -419,7 +419,7 @@ void get_operserv_stats(long *nrec, long *memuse) mem += szlines.count * sizeof(SXLine); for (i = 0; i < szlines.count; i++) { - sx = (SXLine *)szlines.list[i]; + sx = static_cast(szlines.list[i]); mem += strlen(sx->mask) + 1; mem += strlen(sx->by) + 1; mem += strlen(sx->reason) + 1; diff --git a/src/core/os_szline.c b/src/core/os_szline.c index 4e324b261..b9181c135 100644 --- a/src/core/os_szline.c +++ b/src/core/os_szline.c @@ -221,10 +221,10 @@ int do_szline(User * u) char *amask; for (i = 0; i < szlines.count; i++) { - amask = ((SXLine *) szlines.list[i])->mask; + amask = (static_cast(szlines.list[i]))->mask; if (!stricmp(mask, amask) || match_wild_nocase(mask, amask)) - szline_list(i + 1, (SXLine *)szlines.list[i], u, &sent_header); + szline_list(i + 1, static_cast(szlines.list[i]), u, &sent_header); } if (!sent_header) @@ -255,10 +255,10 @@ int do_szline(User * u) char *amask; for (i = 0; i < szlines.count; i++) { - amask = ((SXLine *) szlines.list[i])->mask; + amask = (static_cast(szlines.list[i]))->mask; if (!stricmp(mask, amask) || match_wild_nocase(mask, amask)) - szline_view(i + 1, (SXLine *)szlines.list[i], u, &sent_header); + szline_view(i + 1, static_cast(szlines.list[i]), u, &sent_header); } if (!sent_header) @@ -305,7 +305,7 @@ int szline_view_callback(SList * slist, int number, void *item, User *u = va_arg(args, User *); int *sent_header = va_arg(args, int *); - return szline_view(number, (SXLine *)item, u, sent_header); + return szline_view(number, static_cast(item), u, sent_header); } /* Callback for enumeration purposes */ @@ -316,7 +316,7 @@ int szline_list_callback(SList * slist, int number, void *item, User *u = va_arg(args, User *); int *sent_header = va_arg(args, int *); - return szline_list(number, (SXLine *)item, u, sent_header); + return szline_list(number, static_cast(item), u, sent_header); } /* Lists an SZLINE entry, prefixing it with the header if needed */ diff --git a/src/datafiles.c b/src/datafiles.c index d14e47343..541ad9ca5 100644 --- a/src/datafiles.c +++ b/src/datafiles.c @@ -466,7 +466,7 @@ int read_ptr(void **ret, dbFILE * f) c = fgetc(f->fp); if (c == EOF) return -1; - *ret = (c ? (void *) 1 : (void *) 0); + *ret = (c ? reinterpret_cast(1) : reinterpret_cast(0)); return 0; } @@ -533,7 +533,7 @@ int write_string(const char *s, dbFILE * f) len = strlen(s); if (len > 65534) len = 65534; - if (write_int16((uint16) (len + 1), f) < 0) + if (write_int16(static_cast(len + 1), f) < 0) return -1; if (len > 0 && fwrite(s, 1, len, f->fp) != len) return -1; diff --git a/src/events.c b/src/events.c index 1804f9260..ce36aa3e2 100644 --- a/src/events.c +++ b/src/events.c @@ -91,7 +91,7 @@ int displayEventHook(EvtHook * evh) int i = 0; alog("Displaying message list for %s", evh->name); for (msg = evh; msg; msg = msg->next) { - alog("%d: 0x%p", ++i, (void *) msg); + alog("%d: 0x%p", ++i, static_cast(msg)); } alog("end"); return 0; @@ -199,7 +199,7 @@ int addEventHook(EvtHookHash * hookEvtTable[], EvtHook * evh) current->evh = evh; if (debug) alog("debug: existing msg: (0x%p), new msg (0x%p)", - (void *) evh->next, (void *) evh); + static_cast(evh->next), static_cast(evh)); return MOD_ERR_OK; } lastHash = current; diff --git a/src/hostserv.c b/src/hostserv.c index 93515fb04..bcfde7d53 100644 --- a/src/hostserv.c +++ b/src/hostserv.c @@ -469,7 +469,7 @@ int do_hs_sync(NickCore * nc, char *vIdent, char *hostmask, char *creator, NickAlias *na; for (i = 0; i < nc->aliases.count; i++) { - na = (NickAlias *)nc->aliases.list[i]; + na = static_cast(nc->aliases.list[i]); addHostCore(na->nick, vIdent, hostmask, creator, time); } return MOD_CONT; @@ -517,7 +517,7 @@ int is_host_setter(User * u) /* Look through all user's aliases (0000412) */ for (i = 0; i < u->na->nc->aliases.count; i++) { - na = (NickAlias *)u->na->nc->aliases.list[i]; + na = static_cast(u->na->nc->aliases.list[i]); for (j = 0; j < HostNumber; j++) { if (stricmp(HostSetters[j], na->nick) == 0) { return 1; diff --git a/src/init.c b/src/init.c index d6122fa3e..ac1837fb9 100644 --- a/src/init.c +++ b/src/init.c @@ -317,7 +317,7 @@ static void write_pidfile(void) pidfile = fopen(PIDFilename, "w"); if (pidfile) { - fprintf(pidfile, "%d\n", (int) getpid()); + fprintf(pidfile, "%d\n", static_cast(getpid())); fclose(pidfile); atexit(remove_pidfile); } else { diff --git a/src/log.c b/src/log.c index 959b173a4..867c43f6a 100644 --- a/src/log.c +++ b/src/log.c @@ -134,7 +134,7 @@ char *log_gettimestamp(void) strftime(tbuf, sizeof(tbuf) - 1, "[%b %d %H:%M:%S", &tm); s = tbuf + strlen(tbuf); s += snprintf(s, sizeof(tbuf) - (s - tbuf), ".%06d", - (int) tv.tv_usec); + static_cast(tv.tv_usec)); strftime(s, sizeof(tbuf) - (s - tbuf) - 1, " %Y]", &tm); } else { #endif diff --git a/src/main.c b/src/main.c index 59c63c1fc..53bebd298 100644 --- a/src/main.c +++ b/src/main.c @@ -418,7 +418,7 @@ void sighandler(int signum) !(quitmsg = new char[BUFSIZE])) { quitmsg = "Out of memory!"; } else { - snprintf((char *)quitmsg, BUFSIZE, "Services terminating on signal %d", signum); + snprintf(const_cast(quitmsg), BUFSIZE, "Services terminating on signal %d", signum); } if (signum == SIGSEGV) { @@ -554,7 +554,7 @@ int main(int ac, char **av, char **envp) waiting = 1; /* this is a nasty nasty typecast. we need to rewrite the socket stuff -Certus */ - i = (int) (long) sgets2(inbuf, sizeof(inbuf), servsock); + i = static_cast(reinterpret_cast(sgets2(inbuf, sizeof(inbuf), servsock))); waiting = 0; if ((i > 0) || (i < (-1))) { process(); @@ -563,7 +563,7 @@ int main(int ac, char **av, char **envp) quitmsg = new char[BUFSIZE]; if (quitmsg) { // Naughty, but oh well. :) - snprintf((char *)quitmsg, BUFSIZE, + snprintf(const_cast(quitmsg), BUFSIZE, "Read error from server: %s (error num: %d)", strerror(errno_save), errno_save); } else { diff --git a/src/memoserv.c b/src/memoserv.c index 35c433e4d..df970565e 100644 --- a/src/memoserv.c +++ b/src/memoserv.c @@ -253,7 +253,7 @@ void memo_send(User * u, char *name, char *text, int z) } else { u->lastmemosend = now; mi->memocount++; - mi->memos = (Memo *)srealloc(mi->memos, sizeof(Memo) * mi->memocount); + mi->memos = static_cast(srealloc(mi->memos, sizeof(Memo) * mi->memocount)); m = &mi->memos[mi->memocount - 1]; strscpy(m->sender, source, NICKMAX); if (mi->memocount > 1) { @@ -289,7 +289,7 @@ void memo_send(User * u, char *name, char *text, int z) int i; for (i = 0; i < nc->aliases.count; i++) { - na = (NickAlias *)nc->aliases.list[i]; + na = static_cast(nc->aliases.list[i]); if (na->u && nick_identified(na->u)) notice_lang(s_MemoServ, na->u, MEMO_NEW_MEMO_ARRIVED, source, diff --git a/src/messages.c b/src/messages.c index 4f82d96df..81f3d02c0 100644 --- a/src/messages.c +++ b/src/messages.c @@ -133,7 +133,7 @@ int m_privmsg(const char *source, const char *receiver, const char *msg) if (s_BotServ && (ci = cs_findchan(receiver))) { /* Some paranoia checks */ if (!(ci->flags & CI_VERBOTEN) && ci->c && ci->bi) { - botchanmsgs(u, ci, (char *)msg); // XXX Unsafe cast, this needs reviewing -- CyberBotX + botchanmsgs(u, ci, const_cast(msg)); // XXX Unsafe cast, this needs reviewing -- CyberBotX } } } else { @@ -173,25 +173,25 @@ int m_privmsg(const char *source, const char *receiver, const char *msg) s_OperServ, u->nick, u->username, u->host); } else { - operserv(u, (char *)msg); // XXX Unsafe cast, this needs reviewing -- CyberBotX + operserv(u, const_cast(msg)); // XXX Unsafe cast, this needs reviewing -- CyberBotX } } else if (!stricmp(receiver, s_NickServ)) { - nickserv(u, (char *)msg); // XXX Unsafe cast, this needs reviewing -- CyberBotX + nickserv(u, const_cast(msg)); // XXX Unsafe cast, this needs reviewing -- CyberBotX } else if (!stricmp(receiver, s_ChanServ)) { if (!is_oper(u) && CSOpersOnly) notice_lang(s_ChanServ, u, ACCESS_DENIED); else - chanserv(u, (char *)msg); // XXX Unsafe cast, this needs reviewing -- CyberBotX + chanserv(u, const_cast(msg)); // XXX Unsafe cast, this needs reviewing -- CyberBotX } else if (!stricmp(receiver, s_MemoServ)) { - memoserv(u, (char *)msg); // XXX Unsafe cast, this needs reviewing -- CyberBotX + memoserv(u, const_cast(msg)); // XXX Unsafe cast, this needs reviewing -- CyberBotX } else if (s_HostServ && !stricmp(receiver, s_HostServ)) { - hostserv(u, (char *)msg); // XXX Unsafe cast, this needs reviewing -- CyberBotX + hostserv(u, const_cast(msg)); // XXX Unsafe cast, this needs reviewing -- CyberBotX } else if (s_HelpServ && !stricmp(receiver, s_HelpServ)) { - helpserv(u, (char *)msg); // XXX Unsafe cast, this needs reviewing -- CyberBotX + helpserv(u, const_cast(msg)); // XXX Unsafe cast, this needs reviewing -- CyberBotX } else if (s_BotServ && !stricmp(receiver, s_BotServ)) { - botserv(u, (char *)msg); // XXX Unsafe cast, this needs reviewing -- CyberBotX + botserv(u, const_cast(msg)); // XXX Unsafe cast, this needs reviewing -- CyberBotX } else if (s_BotServ && (bi = findbot(receiver))) { - botmsgs(u, bi, (char *)msg); // XXX Unsafe cast, this needs reviewing -- CyberBotX + botmsgs(u, bi, const_cast(msg)); // XXX Unsafe cast, this needs reviewing -- CyberBotX } /* Add to ignore list if the command took a significant amount of time. */ @@ -237,10 +237,10 @@ int m_stats(const char *source, int ac, const char **av) } else { for (i = 0; i < RootNumber; i++) ircdproto->SendNumeric(ServerName, 243, source, "O * * %s Root 0", ServicesRoots[i]); - for (i = 0; i < servadmins.count && (nc = (NickCore *)servadmins.list[i]); + for (i = 0; i < servadmins.count && (nc = static_cast(servadmins.list[i])); i++) ircdproto->SendNumeric(ServerName, 243, source, "O * * %s Admin 0", nc->display); - for (i = 0; i < servopers.count && (nc = (NickCore *)servopers.list[i]); + for (i = 0; i < servopers.count && (nc = static_cast(servopers.list[i])); i++) ircdproto->SendNumeric(ServerName, 243, source, "O * * %s Oper 0", nc->display); diff --git a/src/misc.c b/src/misc.c index 437d9ece4..ccdfeaf15 100644 --- a/src/misc.c +++ b/src/misc.c @@ -37,9 +37,9 @@ struct arc4_stream { int toupper(char c) { if (islower(c)) { - return (unsigned char) c - ('a' - 'A'); + return static_cast(c) - ('a' - 'A'); } else { - return (unsigned char) c; + return static_cast(c); } } @@ -54,9 +54,9 @@ int toupper(char c) int tolower(char c) { if (isupper(c)) { - return (unsigned char) c + ('a' - 'A'); + return static_cast(c) + ('a' - 'A'); } else { - return (unsigned char) c; + return static_cast(c); } } @@ -326,13 +326,13 @@ int process_numlist(const char *numstr, int *count_ret, * end of a valid number or range to the next comma or null. */ for (;;) { - n1 = n2 = strtol(numstr, (char **) &numstr, 10); + n1 = n2 = strtol(numstr, const_cast(&numstr), 10); numstr += strcspn(numstr, "0123456789,-"); if (*numstr == '-') { numstr++; numstr += strcspn(numstr, "0123456789,"); if (isdigit(*numstr)) { - n2 = strtol(numstr, (char **) &numstr, 10); + n2 = strtol(numstr, const_cast(&numstr), 10); numstr += strcspn(numstr, "0123456789,-"); } } @@ -387,7 +387,7 @@ int dotime(const char *s) return -1; } - amount = strtol(s, (char **) &s, 10); + amount = strtol(s, const_cast(&s), 10); if (*s) { switch (*s) { case 's': @@ -937,7 +937,7 @@ static void arc4_addrandom(void *dat, int datlen) for (n = 0; n < 256; n++) { rs.i = (rs.i + 1); si = rs.s[rs.i]; - rs.j = (rs.j + si + ((unsigned char *) dat)[n % datlen]); + rs.j = (rs.j + si + (static_cast(dat))[n % datlen]); rs.s[rs.i] = rs.s[rs.j]; rs.s[rs.j] = si; } @@ -1130,9 +1130,9 @@ char *str_signed(unsigned char *str) { char *nstr; - nstr = (char *) str; + nstr = reinterpret_cast(str); while (*str) { - *nstr = (char) *str; + *nstr = static_cast(*str); str++; nstr++; } @@ -1157,7 +1157,7 @@ char *stripModePrefix(const char *str) void ntoa(struct in_addr addr, char *ipaddr, int len) { - unsigned char *bytes = (unsigned char *) &addr.s_addr; + unsigned char *bytes = reinterpret_cast(&addr.s_addr); snprintf(ipaddr, len, "%u.%u.%u.%u", bytes[0], bytes[1], bytes[2], bytes[3]); } @@ -1176,7 +1176,7 @@ char **buildStringList(const std::string &src, int *number) while (tokens.G