diff options
| author | cyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864> | 2008-11-23 19:12:20 +0000 |
|---|---|---|
| committer | cyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864> | 2008-11-23 19:12:20 +0000 |
| commit | 8431ac369b2f12ac376798fb01748f52d327164a (patch) | |
| tree | 383144a0a102038cf5fd1aaf780f9594ffb376f1 /src | |
| parent | 5950b11a0f4903cd07c0068a428f499dd64bdd2b (diff) | |
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
Diffstat (limited to 'src')
63 files changed, 313 insertions, 313 deletions
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<long>(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<size_t>(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<size_t>(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<size_t>(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<size_t>(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<char *>(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<unsigned char *>(ia.s_addr); + b64_encode(reinterpret_cast<char *>(&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<struct in_addr *>(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<unsigned char>(*b64++)]; if (!b64) return 0; while (*b64) { v <<= 6; - v += base64_to_int6_map[(unsigned char) *b64++]; + v += base64_to_int6_map[static_cast<unsigned char>(*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<long>(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<long>(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<long>(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<char **>(&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<char **>(&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<long>(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<char *>(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<int>(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<int>(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<int>(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<int>(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<void *>(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<void *>(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<char *>(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<long>(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<char *>(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<char *>(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<int>(*s)] != 0) + *end2++ = csmodes[static_cast<int>(*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<int>(*s)] != 0) + *end2++ = csmodes[static_cast<int>(*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<int>(*s)] != 0) + *end2++ = csmodes[static_cast<int>(*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<unsigned long>(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<int16>(tmp16); } SAFE(read_int16(&ci->accesscount, f)); if (ci->accesscount) { - ci->access = (ChanAccess *)scalloc(ci->accesscount, sizeof(ChanAccess)); + ci->access = static_cast<ChanAccess *>(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<int16>(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<AutoKick *>(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<int16>(tmp16); SAFE(read_int16(&tmp16, f)); - ci->memos.memomax = (int16) tmp16; + ci->memos.memomax = static_cast<int16>(tmp16); if (ci->memos.memocount) { Memo *memos; - memos = (Memo *)scalloc(sizeof(Memo) * ci->memos.memocount, 1); + memos = static_cast<Memo *>(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<int16>(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<BadWord *>(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<int>(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<int>(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<int>(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<const char *>(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<const char *>(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<long>(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<unsigned char>(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<unsigned char>(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<unsigned char>(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<unsigned char>(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<unsigned long>(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<char **>(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<char **>(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<BadWord *>(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<BadWord *>(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")) { |
