X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fbattery.c;h=badd8e752f47717df72b63cb5360e441b0c203f8;hb=5cdafc6cb9228b93cf9b6956c92df61d00bd2a9e;hp=2e27e60e4bcdce4b0be7452a943ce2d398636f60;hpb=4320ac5ec142c87bcf634cd85b89eadea65011ff;p=collectd.git diff --git a/src/battery.c b/src/battery.c index 2e27e60e..badd8e75 100644 --- a/src/battery.c +++ b/src/battery.c @@ -77,7 +77,7 @@ static int battery_init (void) { 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)) @@ -98,9 +98,9 @@ static void battery_submit (const char *plugin_instance, const char *type, doubl vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "battery"); - strcpy (vl.plugin_instance, plugin_instance); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "battery", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); plugin_dispatch_values (type, &vl); } /* void battery_submit */ @@ -360,11 +360,11 @@ static int battery_read (void) 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) @@ -438,7 +438,7 @@ static int battery_read (void) 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)