cppcheck: fix various warnings/errors

[ircd/match.c:316]: (error) Shifting a negative value is undefined behaviour
[librb/src/patricia.c:55]: (error) Shifting a negative value is undefined behaviour
[modules/m_alias.c:64]: (portability) '(void*)message' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
[modules/m_time.c:111]: (warning) %u in format string (no. 9) requires 'unsigned int' but the argument type is 'signed int'.
[modules/m_time.c:111]: (warning) %u in format string (no. 10) requires 'unsigned int' but the argument type is 'signed int'.
[librb/src/dictionary.c:819]: (warning) %d in format string (no. 3) requires 'int' but the argument type is 'unsigned int'.
[librb/src/radixtree.c:1080]: (warning) %d in format string (no. 3) requires 'int' but the argument type is 'unsigned int'.
[ircd/s_user.c:351] -> [ircd/s_user.c:357]: (warning) Either the condition '0!=source_p' is redundant or there is possible null pointer dereference: source_p.
[extensions/ip_cloaking_3.0.c:109]: (warning, inconclusive) The buffer 'buf' may not be null-terminated after the call to strncpy().
[ircd/chmode.c:256]: (style) Clarify calculation precedence for '&' and '?'.
[modules/m_help.c:100]: (style) Clarify calculation precedence for '&' and '?'.
[modules/m_knock.c:169]: (style) Clarify calculation precedence for '&' and '?'.
[modules/m_stats.c:628]: (style) Clarify calculation precedence for '&' and '?'.
[modules/m_stats.c:727]: (style) Clarify calculation precedence for '&' and '?'.
[librb/src/radixtree.c:601]: (style) Clarify calculation precedence for '&' and '?'.
[librb/src/radixtree.c:704]: (style) Clarify calculation precedence for '&' and '?'.
[librb/src/radixtree.c:739]: (style) Clarify calculation precedence for '&' and '?'.
[librb/src/radixtree.c:763]: (style) Clarify calculation precedence for '&' and '?'.
[librb/src/radixtree.c:768]: (style) Clarify calculation precedence for '&' and '?'.
[librb/src/radixtree.c:774]: (style) Clarify calculation precedence for '&' and '?'.
[librb/src/radixtree.c:781]: (style) Clarify calculation precedence for '&' and '?'.
[librb/src/radixtree.c:786]: (style) Clarify calculation precedence for '&' and '?'.
[librb/src/radixtree.c:791]: (style) Clarify calculation precedence for '&' and '?'.
[librb/src/radixtree.c:804]: (style) Clarify calculation precedence for '&' and '?'.
[ircd/wsproc.c:372]: (style) Unused variable: len
[modules/core/m_modules.c:382]: (style) Unused variable: i
[modules/m_stats.c:741]: (style) Unused variable: amsg
[ircd/authproc.c:390]: (style) Unused variable: iter
[ircd/authproc.c:391]: (style) Unused variable: client_p
This commit is contained in:
Simon Arlott 2016-10-28 19:23:21 +01:00
parent 3608f31d39
commit d8f0b5d763
No known key found for this signature in database
GPG Key ID: C8975F2043CA5D24
16 changed files with 17 additions and 24 deletions

View File

@ -103,7 +103,7 @@ do_host_cloak_ip(const char *inbuf, char *outbuf)
{
char *tptr;
unsigned int accum = get_string_weighted_entropy(inbuf);
char buf[HOSTLEN];
char buf[HOSTLEN + 1] = { 0 };
int ipv6 = 0;
strncpy(buf, inbuf, HOSTLEN);
@ -216,7 +216,7 @@ check_new_user(void *vdata)
source_p->umodes &= ~user_modes['h'];
return;
}
source_p->localClient->mangledhost = rb_malloc(HOSTLEN);
source_p->localClient->mangledhost = rb_malloc(HOSTLEN + 1);
if (!irccmp(source_p->orighost, source_p->sockhost))
do_host_cloak_ip(source_p->orighost, source_p->localClient->mangledhost);
else

View File

@ -158,7 +158,7 @@ check_new_user(void *vdata)
source_p->umodes &= ~user_modes['h'];
return;
}
source_p->localClient->mangledhost = rb_malloc(HOSTLEN);
source_p->localClient->mangledhost = rb_malloc(HOSTLEN + 1);
if (!irccmp(source_p->orighost, source_p->sockhost))
do_host_cloak(source_p->orighost, source_p->localClient->mangledhost, 1);
else

View File

@ -387,9 +387,6 @@ authd_abort_client(struct Client *client_p)
static void
restart_authd_cb(rb_helper * helper)
{
rb_dictionary_iter iter;
struct Client *client_p;
iwarn("authd: restart_authd_cb called, authd died?");
sendto_realops_snomask(SNO_GENERAL, L_ALL, "authd: restart_authd_cb called, authd died?");

View File

@ -253,7 +253,7 @@ add_id(struct Client *source_p, struct Channel *chptr, const char *banid, const
*/
if(MyClient(source_p))
{
if((rb_dlink_list_length(&chptr->banlist) + rb_dlink_list_length(&chptr->exceptlist) + rb_dlink_list_length(&chptr->invexlist) + rb_dlink_list_length(&chptr->quietlist)) >= (unsigned long)(chptr->mode.mode & MODE_EXLIMIT ? ConfigChannel.max_bans_large : ConfigChannel.max_bans))
if((rb_dlink_list_length(&chptr->banlist) + rb_dlink_list_length(&chptr->exceptlist) + rb_dlink_list_length(&chptr->invexlist) + rb_dlink_list_length(&chptr->quietlist)) >= (unsigned long)((chptr->mode.mode & MODE_EXLIMIT) ? ConfigChannel.max_bans_large : ConfigChannel.max_bans))
{
sendto_one(source_p, form_str(ERR_BANLISTFULL),
me.name, source_p->name, chptr->chname, realban);

View File

@ -313,7 +313,7 @@ int comp_with_mask(void *addr, void *dest, unsigned int mask)
if (memcmp(addr, dest, mask / 8) == 0)
{
int n = mask / 8;
int m = ((-1) << (8 - (mask % 8)));
unsigned char m = (0xFF << (8 - (mask % 8)));
if (mask % 8 == 0 || (((unsigned char *) addr)[n] & m) == (((unsigned char *) dest)[n] & m))
{
return (1);

View File

@ -348,7 +348,6 @@ int
register_local_user(struct Client *client_p, struct Client *source_p)
{
struct ConfItem *aconf, *xconf;
struct User *user = source_p->user;
char tmpstr2[BUFSIZE];
char ipaddr[HOSTIPLEN];
char myusername[USERLEN+1];
@ -480,7 +479,7 @@ register_local_user(struct Client *client_p, struct Client *source_p)
}
}
if(IsNeedSasl(aconf) && !*user->suser)
if(IsNeedSasl(aconf) && !*source_p->user->suser)
{
ServerStats.is_ref++;
sendto_one_notice(source_p, ":*** Notice -- You need to identify via SASL to use this server");
@ -665,7 +664,7 @@ register_local_user(struct Client *client_p, struct Client *source_p)
free_pre_client(source_p);
introduce_client(client_p, source_p, user, source_p->name, 1);
introduce_client(client_p, source_p, source_p->user, source_p->name, 1);
return 0;
}

View File

@ -369,7 +369,6 @@ ws_process_cmd_recv(ws_ctl_t * ctl)
{
rb_dlink_node *ptr, *next;
ws_ctl_buf_t *ctl_buf;
unsigned long len;
if(ctl->dead)
return;

View File

@ -816,7 +816,7 @@ void rb_dictionary_stats(rb_dictionary *dict, void (*cb)(const char *line, void
{
maxdepth = 0;
sum = stats_recurse(dict->root, 0, &maxdepth);
snprintf(str, sizeof str, "%-30s %-15s %-10d %-10d %-10d %-10d", dict->id, "DICT", dict->count, sum, sum / dict->count, maxdepth);
snprintf(str, sizeof str, "%-30s %-15s %-10u %-10d %-10d %-10d", dict->id, "DICT", dict->count, sum, sum / dict->count, maxdepth);
}
else
{

View File

@ -52,7 +52,7 @@ comp_with_mask(void *addr, void *dest, unsigned int mask)
if( /* mask/8 == 0 || */ memcmp(addr, dest, mask / 8) == 0)
{
int n = mask / 8;
int m = ((-1) << (8 - (mask % 8)));
uint8_t m = (0xFF << (8 - (mask % 8)));
if(mask % 8 == 0 || (((uint8_t *)addr)[n] & m) == (((uint8_t *)dest)[n] & m))
return (1);

View File

@ -70,7 +70,7 @@ struct rb_radixtree
};
#define POINTERS_PER_NODE 16
#define NIBBLE_VAL(key, nibnum) (((key)[(nibnum) / 2] >> ((nibnum) & 1 ? 0 : 4)) & 0xF)
#define NIBBLE_VAL(key, nibnum) (((key)[(nibnum) / 2] >> (((nibnum) & 1) ? 0 : 4)) & 0xF)
struct rb_radixtree_node
{
@ -1077,7 +1077,7 @@ rb_radixtree_stats(rb_radixtree *dict, void (*cb)(const char *line, void *privda
if (dict->count > 0)
{
sum = stats_recurse(dict->root, 0, &maxdepth);
snprintf(str, sizeof str, "%-30s %-15s %-10d %-10d %-10d %-10d", dict->id, "RADIX", dict->count, sum, sum / dict->count, maxdepth);
snprintf(str, sizeof str, "%-30s %-15s %-10u %-10d %-10d %-10d", dict->id, "RADIX", dict->count, sum, sum / dict->count, maxdepth);
}
else
{

View File

@ -379,7 +379,6 @@ static void
do_modlist(struct Client *source_p, const char *pattern)
{
rb_dlink_node *ptr;
int i;
RB_DLINK_FOREACH(ptr, module_list.head)
{

View File

@ -61,7 +61,7 @@ create_aliases(void)
RB_DICTIONARY_FOREACH(alias, &iter, alias_dict)
{
struct Message *message = rb_malloc(sizeof(*message) + strlen(alias->name) + 1);
char *cmd = (void*)message + sizeof(*message);
char *cmd = (char*)message + sizeof(*message);
/* copy the alias name as it will be freed early on a rehash */
strcpy(cmd, alias->name);

View File

@ -97,7 +97,7 @@ dohelp(struct Client *source_p, int flags, const char *topic)
if(EmptyString(topic))
topic = ntopic;
hptr = rb_dictionary_retrieve(flags & HELP_OPER ? help_dict_oper : help_dict_user, topic);
hptr = rb_dictionary_retrieve((flags & HELP_OPER) ? help_dict_oper : help_dict_user, topic);
if(hptr == NULL || !(hptr->flags & flags))
{

View File

@ -166,7 +166,7 @@ m_knock(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_
chptr->last_knock = rb_current_time();
if(ConfigChannel.use_knock)
sendto_channel_local(chptr->mode.mode & MODE_FREEINVITE ? ALL_MEMBERS : ONLY_CHANOPS,
sendto_channel_local((chptr->mode.mode & MODE_FREEINVITE) ? ALL_MEMBERS : ONLY_CHANOPS,
chptr, form_str(RPL_KNOCK),
me.name, name, name, source_p->name,
source_p->username, source_p->host);

View File

@ -625,7 +625,7 @@ stats_tklines(struct Client *source_p)
get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason);
sendto_one_numeric(source_p, RPL_STATSKLINE,
form_str(RPL_STATSKLINE), aconf->flags & CONF_FLAGS_TEMPORARY ? 'k' : 'K',
form_str(RPL_STATSKLINE), (aconf->flags & CONF_FLAGS_TEMPORARY) ? 'k' : 'K',
host, user, pass, oper_reason ? "|" : "",
oper_reason ? oper_reason : "");
}
@ -724,7 +724,7 @@ stats_klines(struct Client *source_p)
get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason);
sendto_one_numeric(source_p, RPL_STATSKLINE, form_str(RPL_STATSKLINE),
aconf->flags & CONF_FLAGS_TEMPORARY ? 'k' : 'K',
(aconf->flags & CONF_FLAGS_TEMPORARY) ? 'k' : 'K',
host, user, pass, oper_reason ? "|" : "",
oper_reason ? oper_reason : "");
}
@ -738,7 +738,6 @@ stats_messages(struct Client *source_p)
{
rb_dictionary_iter iter;
struct Message *msg;
struct alias_entry *amsg;
RB_DICTIONARY_FOREACH(msg, &iter, cmd_dict)
{

View File

@ -111,7 +111,7 @@ date(void)
sprintf(buf, "%s %s %d %d -- %02u:%02u:%02u %c%02u:%02u",
weekdays[lt->tm_wday], months[lt->tm_mon], lt->tm_mday,
lt->tm_year + 1900, lt->tm_hour, lt->tm_min, lt->tm_sec,
plus, minswest / 60, minswest % 60);
plus, (unsigned int)minswest / 60, (unsigned int)minswest % 60);
return buf;
}