summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 06d0305)
raw | patch | inline | side by side (parent: 06d0305)
author | Sebastian Harl <sh@tokkee.org> | |
Tue, 22 Jan 2008 18:11:00 +0000 (19:11 +0100) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Tue, 22 Jan 2008 19:18:38 +0000 (20:18 +0100) |
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>
* 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:
src/apcups.c | patch | blob | history | |
src/battery.c | patch | blob | history | |
src/collectd.c | patch | blob | history | |
src/collectdmon.c | patch | blob | history | |
src/common.c | patch | blob | history | |
src/cpufreq.c | patch | blob | history | |
src/disk.c | patch | blob | history | |
src/iptables.c | patch | blob | history | |
src/irq.c | patch | blob | history | |
src/network.c | patch | blob | history | |
src/ntpd.c | patch | blob | history | |
src/perl.c | patch | blob | history | |
src/plugin.c | patch | blob | history | |
src/plugin.h | patch | blob | history | |
src/types_list.c | patch | blob | history | |
src/unixsock.c | patch | blob | history | |
src/utils_avltree.c | patch | blob | history | |
src/utils_dns.c | patch | blob | history |
diff --git a/src/apcups.c b/src/apcups.c
index 08df0b50fbcb2cb36253bd2c97f9019f689962bb..5a03764f59f5ea53bc1ac63cd549f183d22e40d1 100644 (file)
--- a/src/apcups.c
+++ b/src/apcups.c
* 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)
{
int sd;
int status;
if (global_sockfd < 0)
{
- global_sockfd = net_open (host, NULL, port);
+ global_sockfd = net_open (host, port);
if (global_sockfd < 0)
{
ERROR ("apcups plugin: Connecting to the "
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);
diff --git a/src/battery.c b/src/battery.c
index 2e27e60e4bcdce4b0be7452a943ce2d398636f60..345f606e8f3f834b5398fd15b3c91308607fb4a0 100644 (file)
--- a/src/battery.c
+++ b/src/battery.c
{
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))
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);
- if ((len >= sizeof (batnum_str)) || (len < 0))
+ if ((len < 0) || ((unsigned int)len >= sizeof (batnum_str)))
continue;
if ((fh = fopen (filename, "r")) == NULL)
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)
diff --git a/src/collectd.c b/src/collectd.c
index c9ae66dd550cf8373ded07b341e2964991143b50..2d161aad6062815d4bdf220a7f30c02319e33075 100644 (file)
--- a/src/collectd.c
+++ b/src/collectd.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"
#endif
/* Issue all plugins */
- plugin_read_all (&loop);
+ plugin_read_all ();
if (gettimeofday (&tv_now, NULL) < 0)
{
#endif /* COLLECT_DAEMON */
case 'h':
default:
- exit_usage (argv[0]);
+ exit_usage ();
} /* switch (c) */
} /* while (1) */
diff --git a/src/collectdmon.c b/src/collectdmon.c
index 0295ad3d7813d8fe69611b0c8ba2dac6658b052e..e496eb07a65d23138513786967fb0fb2350f6fa3 100644 (file)
--- a/src/collectdmon.c
+++ b/src/collectdmon.c
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)
close (i);
errno = 0;
return 0;
} /* daemonize */
-static int collectd_start (int argc, char **argv)
+static int collectd_start (char **argv)
{
pid_t pid = 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;
}
diff --git a/src/common.c b/src/common.c
index 1138f96ff92e688063990c1bdd084eca816fbb47..b1fd953817afcc0232699249fdf4734d9f631151 100644 (file)
--- a/src/common.c
+++ b/src/common.c
return (-1);
}
- assert (nleft >= status);
+ assert ((0 > status) || (nleft >= (size_t)status));
nleft = nleft - status;
ptr = ptr + status;
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);
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))
{
diff --git a/src/cpufreq.c b/src/cpufreq.c
index b1037c38bc25abbe8702059bfba8a1dc3177c998..42248a98deebf9a8b4a5f6e5d5e7f76c72e0b2e9 100644 (file)
--- a/src/cpufreq.c
+++ b/src/cpufreq.c
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))
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)
diff --git a/src/disk.c b/src/disk.c
index d2e9f9873ea71025a4185f6652b918474c5b0ddb..8feaa8dff6fe77d8127c20c9afdaa9fd2530d14d 100644 (file)
--- a/src/disk.c
+++ b/src/disk.c
if (is_disk)
{
- 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) */
diff --git a/src/iptables.c b/src/iptables.c
index 0e7fa70f86740ec864f187e8e2b90d7c28644528..72b4481cc5148ff500d6ed01076c12378a6c3932 100644 (file)
--- a/src/iptables.c
+++ b/src/iptables.c
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);
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);
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')
diff --git a/src/irq.c b/src/irq.c
index b6b8c4c6a92ea91121d58706845b7c8b5a3437b2..9eb1de426b83bea8b7243f0c2e9c993de87fdb1c 100644 (file)
--- a/src/irq.c
+++ b/src/irq.c
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);
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);
diff --git a/src/network.c b/src/network.c
index c347552e904a981b0588028093ed759b10847d61..7fb19a1c73612885d2a66823881bcb3331660e38 100644 (file)
--- a/src/network.c
+++ b/src/network.c
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;
diff --git a/src/ntpd.c b/src/ntpd.c
index c5dcb8e53ca3489974f5e3052869b57df476c07d..90fdfd7c587628fd8f035dd43ae9d28b47f87094 100644 (file)
--- a/src/ntpd.c
+++ b/src/ntpd.c
}
/* 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;
@@ -766,7 +766,7 @@ static int ntpd_do_query (int req_code, int req_items, int req_size, char *req_d
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);
}
diff --git a/src/perl.c b/src/perl.c
index dc548b2590269328376cf6341b6d0b4ddc2891c8..b87d6b7e4b98c075f3fd25dd88c29af3320e00a3 100644 (file)
--- a/src/perl.c
+++ b/src/perl.c
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 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)
diff --git a/src/plugin.c b/src/plugin.c
index 88da209cec1a03610084484e9202c3a5ff83bad1..77f7affb9582fe23e73ef9fadcfbe2fb173f069b 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
}
} /* void plugin_init_all */
-void plugin_read_all (const int *loop)
+void plugin_read_all (void)
{
llentry_t *le;
read_func_t *rf;
diff --git a/src/plugin.h b/src/plugin.h
index 428c4f09319c5818c7ad89985a2561d12dd5cc4e..4918049771eb8408ed123f2d4cd11b9156bb8603 100644 (file)
--- a/src/plugin.h
+++ b/src/plugin.h
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);
/*
diff --git a/src/types_list.c b/src/types_list.c
index 43e87902efda3a0c54dc056dfc0e5e8b9ed8d157..ff8426286ac515472b63285aee83fe7df0d45cb7 100644 (file)
--- a/src/types_list.c
+++ b/src/types_list.c
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;
if (buf_len == 0)
continue;
- parse_line (buf, buf_len);
+ parse_line (buf);
} /* while (fgets) */
} /* void parse_file */
diff --git a/src/unixsock.c b/src/unixsock.c
index c7e0c4472f40e3ff7166ce8f802b77962eccd21b..3dd0b3dbbf7827613eabb76e06553cd4173e2c1a 100644 (file)
--- a/src/unixsock.c
+++ b/src/unixsock.c
/* 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;
/*
* Functions
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);
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);
diff --git a/src/utils_avltree.c b/src/utils_avltree.c
index 6ad02272c0220ff6eaef4cf9b42cd18fd386d39e..9f0b7968916863f1d42abfca8bc594afdeacea2a 100644 (file)
--- a/src/utils_avltree.c
+++ b/src/utils_avltree.c
} /* 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 */
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 */
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);
- r = c_avl_node_next (t, n);
+ r = c_avl_node_next (n);
}
assert ((r->left == NULL) || (r->right == NULL));
}
else
{
- n = c_avl_node_next (iter->tree, iter->node);
+ n = c_avl_node_next (iter->node);
}
if (n == NULL)
}
else
{
- n = c_avl_node_prev (iter->tree, iter->node);
+ n = c_avl_node_prev (iter->node);
}
if (n == NULL)
diff --git a/src/utils_dns.c b/src/utils_dns.c
index a412809fab051c77c718b158b623f813a2cbf49e..25ef18998bb9f62ad928130e49b531f71501f15f 100644 (file)
--- a/src/utils_dns.c
+++ b/src/utils_dns.c
handle_ipv6 (struct ip6_hdr *ipv6, int len)
{
char buf[PCAP_SNAPLEN];
- int offset;
+ unsigned int offset;
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;
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. */
} /* 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);
} *hdr;
uint16_t etype;
- if (len < sizeof (struct sll_header))
+ if ((0 > len) || ((unsigned int)len < sizeof (struct sll_header)))
return (0);
hdr = (struct sll_header *) pkt;