The following issues have been addressed:
* comparison between signed and unsigned - this was found in several places
throughout the code and has been fixed in various ways
* missing initializer - an incomplete initializer has been used for two
struct instances in perl.c
* unused parameter - when applicable, the parameter has been removed; in
thirteen cases the parameter is required by different library API's and in
two cases the parameter was left in place to retain a consistent interface
within the affected modules; as __attribute__((unused)) is a GNU extension,
it has not been used to document those exceptions
Signed-off-by: Sebastian Harl <sh@tokkee.org>
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
18 files changed:
* Returns -1 on error
* Returns socket file descriptor otherwise
*/
* Returns -1 on error
* Returns socket file descriptor otherwise
*/
-static int net_open (char *host, char *service, int port)
+static int net_open (char *host, int port)
- global_sockfd = net_open (host, NULL, port);
+ global_sockfd = net_open (host, port);
if (global_sockfd < 0)
{
ERROR ("apcups plugin: Connecting to the "
if (global_sockfd < 0)
{
ERROR ("apcups plugin: Connecting to the "
while ((n = net_recv (&global_sockfd, recvline, sizeof (recvline) - 1)) > 0)
{
while ((n = net_recv (&global_sockfd, recvline, sizeof (recvline) - 1)) > 0)
{
- assert (n < sizeof (recvline));
+ assert ((unsigned int)n < sizeof (recvline));
recvline[n] = '\0';
#if APCMAIN
printf ("net_recv = `%s';\n", recvline);
recvline[n] = '\0';
#if APCMAIN
printf ("net_recv = `%s';\n", recvline);
{
len = snprintf (filename, sizeof (filename), battery_pmu_file, battery_pmu_num);
{
len = snprintf (filename, sizeof (filename), battery_pmu_file, battery_pmu_num);
- if ((len >= sizeof (filename)) || (len < 0))
+ if ((len < 0) || ((unsigned int)len >= sizeof (filename)))
break;
if (access (filename, R_OK))
break;
if (access (filename, R_OK))
double *valptr = NULL;
len = snprintf (filename, sizeof (filename), battery_pmu_file, i);
double *valptr = NULL;
len = snprintf (filename, sizeof (filename), battery_pmu_file, i);
- if ((len >= sizeof (filename)) || (len < 0))
+ if ((len < 0) || ((unsigned int)len >= sizeof (filename)))
continue;
len = snprintf (batnum_str, sizeof (batnum_str), "%i", i);
continue;
len = snprintf (batnum_str, sizeof (batnum_str), "%i", i);
- if ((len >= sizeof (batnum_str)) || (len < 0))
+ if ((len < 0) || ((unsigned int)len >= sizeof (batnum_str)))
continue;
if ((fh = fopen (filename, "r")) == NULL)
continue;
if ((fh = fopen (filename, "r")) == NULL)
len = snprintf (filename, sizeof (filename),
"/proc/acpi/battery/%s/state",
ent->d_name);
len = snprintf (filename, sizeof (filename),
"/proc/acpi/battery/%s/state",
ent->d_name);
- if ((len >= sizeof (filename)) || (len < 0))
+ if ((len < 0) || ((unsigned int)len >= sizeof (filename)))
continue;
if ((fh = fopen (filename, "r")) == NULL)
continue;
if ((fh = fopen (filename, "r")) == NULL)
/* TODO
* Remove all settings but `-f' and `-C'
*/
/* TODO
* Remove all settings but `-f' and `-C'
*/
-static void exit_usage (char *name)
+static void exit_usage (void)
{
printf ("Usage: "PACKAGE" [OPTIONS]\n\n"
{
printf ("Usage: "PACKAGE" [OPTIONS]\n\n"
#endif
/* Issue all plugins */
#endif
/* Issue all plugins */
- plugin_read_all (&loop);
if (gettimeofday (&tv_now, NULL) < 0)
{
if (gettimeofday (&tv_now, NULL) < 0)
{
#endif /* COLLECT_DAEMON */
case 'h':
default:
#endif /* COLLECT_DAEMON */
case 'h':
default:
} /* switch (c) */
} /* while (1) */
} /* switch (c) */
} /* while (1) */
if (RLIM_INFINITY == rl.rlim_max)
rl.rlim_max = 1024;
if (RLIM_INFINITY == rl.rlim_max)
rl.rlim_max = 1024;
- for (i = 0; i < rl.rlim_max; ++i)
+ for (i = 0; i < (int)rl.rlim_max; ++i)
return 0;
} /* daemonize */
return 0;
} /* daemonize */
-static int collectd_start (int argc, char **argv)
+static int collectd_start (char **argv)
while (0 == loop) {
int status = 0;
while (0 == loop) {
int status = 0;
- if (0 != collectd_start (collectd_argc, collectd_argv)) {
+ if (0 != collectd_start (collectd_argv)) {
syslog (LOG_ERR, "Error: failed to start collectd.");
break;
}
syslog (LOG_ERR, "Error: failed to start collectd.");
break;
}
- assert (nleft >= status);
+ assert ((0 > status) || (nleft >= (size_t)status));
nleft = nleft - status;
ptr = ptr + status;
nleft = nleft - status;
ptr = ptr + status;
char **fields, size_t fields_num,
const char *sep)
{
char **fields, size_t fields_num,
const char *sep)
{
- int field_len;
- int sep_len;
+ size_t field_len;
+ size_t sep_len;
int i;
memset (dst, '\0', dst_len);
int i;
memset (dst, '\0', dst_len);
if (sep != NULL)
sep_len = strlen (sep);
if (sep != NULL)
sep_len = strlen (sep);
- for (i = 0; i < fields_num; i++)
+ for (i = 0; i < (int)fields_num; i++)
{
if ((i > 0) && (sep_len > 0))
{
{
if ((i > 0) && (sep_len > 0))
{
status = snprintf (filename, sizeof (filename),
"/sys/devices/system/cpu/cpu%d/cpufreq/"
"scaling_cur_freq", num_cpu);
status = snprintf (filename, sizeof (filename),
"/sys/devices/system/cpu/cpu%d/cpufreq/"
"scaling_cur_freq", num_cpu);
- if (status < 1 || status >= sizeof (filename))
+ if ((status < 1) || ((unsigned int)status >= sizeof (filename)))
break;
if (access (filename, R_OK))
break;
if (access (filename, R_OK))
status = snprintf (filename, sizeof (filename),
"/sys/devices/system/cpu/cpu%d/cpufreq/"
"scaling_cur_freq", i);
status = snprintf (filename, sizeof (filename),
"/sys/devices/system/cpu/cpu%d/cpufreq/"
"scaling_cur_freq", i);
- if (status < 1 || status >= sizeof (filename))
+ if ((status < 1) || ((unsigned int)status >= sizeof (filename)))
return (-1);
if ((fp = fopen (filename, "r")) == NULL)
return (-1);
if ((fp = fopen (filename, "r")) == NULL)
- if ((read_merged != -1LL) || (write_merged != -1LL))
- disk_submit (disk_name, "disk_merged",
- read_merged, write_merged);
+ disk_submit (disk_name, "disk_merged",
+ read_merged, write_merged);
} /* if (is_disk) */
} /* while (fgets (buffer, sizeof (buffer), fh) != NULL) */
} /* if (is_disk) */
} /* while (fgets (buffer, sizeof (buffer), fh) != NULL) */
chain = fields[1];
table_len = strlen (table);
chain = fields[1];
table_len = strlen (table);
- if (table_len >= sizeof(temp.table))
+ if ((unsigned int)table_len >= sizeof(temp.table))
{
ERROR ("Table `%s' too long.", table);
free (value_copy);
{
ERROR ("Table `%s' too long.", table);
free (value_copy);
temp.table[table_len] = '\0';
chain_len = strlen (chain);
temp.table[table_len] = '\0';
chain_len = strlen (chain);
- if (chain_len >= sizeof(temp.chain))
+ if ((unsigned int)chain_len >= sizeof(temp.chain))
{
ERROR ("Chain `%s' too long.", chain);
free (value_copy);
{
ERROR ("Chain `%s' too long.", chain);
free (value_copy);
status = snprintf (vl.plugin_instance, sizeof (vl.plugin_instance),
"%s-%s", chain->table, chain->chain);
status = snprintf (vl.plugin_instance, sizeof (vl.plugin_instance),
"%s-%s", chain->table, chain->chain);
- if ((status >= sizeof (vl.plugin_instance)) || (status < 1))
+ if ((status < 1) || ((unsigned int)status >= sizeof (vl.plugin_instance)))
return (0);
if (chain->name[0] != '\0')
return (0);
if (chain->name[0] != '\0')
if (irq_list_num < 1)
return (0);
if (irq_list_num < 1)
return (0);
- for (i = 0; i < irq_list_num; i++)
+ for (i = 0; (unsigned int)i < irq_list_num; i++)
if (irq == irq_list[i])
return (irq_list_action);
if (irq == irq_list[i])
return (irq_list_action);
status = snprintf (vl.type_instance, sizeof (vl.type_instance),
"%u", irq);
status = snprintf (vl.type_instance, sizeof (vl.type_instance),
"%u", irq);
- if ((status < 1) || (status >= sizeof (vl.type_instance)))
+ if ((status < 1) || ((unsigned int)status >= sizeof (vl.type_instance)))
return;
plugin_dispatch_values ("irq", &vl);
return;
plugin_dispatch_values ("irq", &vl);
memset (&type, '\0', sizeof (type));
status = 0;
memset (&type, '\0', sizeof (type));
status = 0;
- while ((status == 0) && (buffer_len > sizeof (part_header_t)))
+ while ((status == 0) && (0 < buffer_len)
+ && ((unsigned int)buffer_len > sizeof (part_header_t)))
{
header = (part_header_t *) buffer;
{
header = (part_header_t *) buffer;
}
/* For a description of the arguments see `ntpd_do_query' below. */
}
/* For a description of the arguments see `ntpd_do_query' below. */
-static int ntpd_receive_response (int req_code, int *res_items, int *res_size,
+static int ntpd_receive_response (int *res_items, int *res_size,
char **res_data, int res_item_size)
{
int sd;
char **res_data, int res_item_size)
{
int sd;
if (status != 0)
return (status);
if (status != 0)
return (status);
- status = ntpd_receive_response (req_code, res_items, res_size, res_data,
+ status = ntpd_receive_response (res_items, res_size, res_data,
res_item_size);
return (status);
}
res_item_size);
return (status);
}
status = snprintf (buf, buf_len, "%s", module);
else
status = snprintf (buf, buf_len, "%s::%s", base_name, module);
status = snprintf (buf, buf_len, "%s", module);
else
status = snprintf (buf, buf_len, "%s::%s", base_name, module);
- if ((status < 0) || (status >= buf_len))
+ if ((status < 0) || ((unsigned int)status >= buf_len))
return (NULL);
buf[buf_len - 1] = '\0';
return (buf);
return (NULL);
buf[buf_len - 1] = '\0';
return (buf);
return 0;
} /* static int g_iv_set (pTHX_ SV *, MAGIC *) */
return 0;
} /* static int g_iv_set (pTHX_ SV *, MAGIC *) */
-static MGVTBL g_pv_vtbl = { g_pv_get, g_pv_set, NULL, NULL, NULL };
-static MGVTBL g_iv_vtbl = { g_iv_get, g_iv_set, NULL, NULL, NULL };
+static MGVTBL g_pv_vtbl = { g_pv_get, g_pv_set, NULL, NULL, NULL, NULL, NULL };
+static MGVTBL g_iv_vtbl = { g_iv_get, g_iv_set, NULL, NULL, NULL, NULL, NULL };
/* bootstrap the Collectd module */
static void xs_init (pTHX)
/* bootstrap the Collectd module */
static void xs_init (pTHX)
}
} /* void plugin_init_all */
}
} /* void plugin_init_all */
-void plugin_read_all (const int *loop)
+void plugin_read_all (void)
{
llentry_t *le;
read_func_t *rf;
{
llentry_t *le;
read_func_t *rf;
int plugin_load (const char *name);
void plugin_init_all (void);
int plugin_load (const char *name);
void plugin_init_all (void);
-void plugin_read_all (const int *loop);
+void plugin_read_all (void);
void plugin_shutdown_all (void);
/*
void plugin_shutdown_all (void);
/*
return (0);
} /* int parse_ds */
return (0);
} /* int parse_ds */
-static void parse_line (char *buf, size_t buf_len)
+static void parse_line (char *buf)
{
char *fields[64];
size_t fields_num;
{
char *fields[64];
size_t fields_num;
if (buf_len == 0)
continue;
if (buf_len == 0)
continue;
- parse_line (buf, buf_len);
} /* while (fgets) */
} /* void parse_file */
} /* while (fgets) */
} /* void parse_file */
/* Linked list and auxilliary variables for saving values */
static value_cache_t *cache_head = NULL;
static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER;
/* Linked list and auxilliary variables for saving values */
static value_cache_t *cache_head = NULL;
static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER;
-static unsigned int cache_oldest = UINT_MAX;
+static time_t cache_oldest = -1;
cache_head = vc;
vc->time = vl->time;
cache_head = vc;
vc->time = vl->time;
- if (vc->time < cache_oldest)
+ if ((vc->time < cache_oldest) || (-1 == cache_oldest))
cache_oldest = vc->time;
pthread_mutex_unlock (&cache_lock);
cache_oldest = vc->time;
pthread_mutex_unlock (&cache_lock);
vc->ds = ds;
vc->time = vl->time;
vc->ds = ds;
vc->time = vl->time;
- if (vc->time < cache_oldest)
+ if ((vc->time < cache_oldest) || (-1 == cache_oldest))
cache_oldest = vc->time;
pthread_mutex_unlock (&cache_lock);
cache_oldest = vc->time;
pthread_mutex_unlock (&cache_lock);
} /* while (n != NULL) */
} /* void rebalance */
} /* while (n != NULL) */
} /* void rebalance */
-static c_avl_node_t *c_avl_node_next (c_avl_tree_t *t, c_avl_node_t *n)
+static c_avl_node_t *c_avl_node_next (c_avl_node_t *n)
{
c_avl_node_t *r; /* return node */
{
c_avl_node_t *r; /* return node */
return (r);
} /* c_avl_node_t *c_avl_node_next */
return (r);
} /* c_avl_node_t *c_avl_node_next */
-static c_avl_node_t *c_avl_node_prev (c_avl_tree_t *t, c_avl_node_t *n)
+static c_avl_node_t *c_avl_node_prev (c_avl_node_t *n)
{
c_avl_node_t *r; /* return node */
{
c_avl_node_t *r; /* return node */
if (BALANCE (n) > 0) /* left subtree is higher */
{
assert (n->left != NULL);
if (BALANCE (n) > 0) /* left subtree is higher */
{
assert (n->left != NULL);
- r = c_avl_node_prev (t, n);
+ r = c_avl_node_prev (n);
}
else /* right subtree is higher */
{
assert (n->right != NULL);
}
else /* right subtree is higher */
{
assert (n->right != NULL);
- r = c_avl_node_next (t, n);
+ r = c_avl_node_next (n);
}
assert ((r->left == NULL) || (r->right == NULL));
}
assert ((r->left == NULL) || (r->right == NULL));
- n = c_avl_node_next (iter->tree, iter->node);
+ n = c_avl_node_next (iter->node);
- n = c_avl_node_prev (iter->tree, iter->node);
+ n = c_avl_node_prev (iter->node);
handle_ipv6 (struct ip6_hdr *ipv6, int len)
{
char buf[PCAP_SNAPLEN];
handle_ipv6 (struct ip6_hdr *ipv6, int len)
{
char buf[PCAP_SNAPLEN];
int nexthdr;
struct in6_addr s_addr;
struct in6_addr d_addr;
uint16_t payload_len;
int nexthdr;
struct in6_addr s_addr;
struct in6_addr d_addr;
uint16_t payload_len;
+ if (0 > len)
+ return (0);
+
offset = sizeof (struct ip6_hdr);
nexthdr = ipv6->ip6_nxt;
s_addr = ipv6->ip6_src;
offset = sizeof (struct ip6_hdr);
nexthdr = ipv6->ip6_nxt;
s_addr = ipv6->ip6_src;
uint16_t ext_hdr_len;
/* Catch broken packets */
uint16_t ext_hdr_len;
/* Catch broken packets */
- if ((offset + sizeof (struct ip6_ext)) > len)
+ if ((offset + sizeof (struct ip6_ext)) > (unsigned int)len)
return (0);
/* Cannot handle fragments. */
return (0);
/* Cannot handle fragments. */
} /* while */
/* Catch broken and empty packets */
} /* while */
/* Catch broken and empty packets */
- if (((offset + payload_len) > len)
+ if (((offset + payload_len) > (unsigned int)len)
|| (payload_len == 0)
|| (payload_len > PCAP_SNAPLEN))
return (0);
|| (payload_len == 0)
|| (payload_len > PCAP_SNAPLEN))
return (0);
- if (len < sizeof (struct sll_header))
+ if ((0 > len) || ((unsigned int)len < sizeof (struct sll_header)))
return (0);
hdr = (struct sll_header *) pkt;
return (0);
hdr = (struct sll_header *) pkt;