Message ID | 1421175905-17035-28-git-send-email-colin.king@canonical.com |
---|---|
State | Accepted |
Headers | show |
On 01/14/2015 03:04 AM, Colin King wrote: > From: Colin Ian King <colin.king@canonical.com> > > cppcheck is picking up some minor style issues which can > be easily fixed: > > [src/lib/src/fwts_battery.c:142]: > (style) The scope of the variable 'units' can be reduced. > > Signed-off-by: Colin Ian King <colin.king@canonical.com> > --- > src/lib/src/fwts_battery.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/src/lib/src/fwts_battery.c b/src/lib/src/fwts_battery.c > index 8a84998..f6eb56d 100644 > --- a/src/lib/src/fwts_battery.c > +++ b/src/lib/src/fwts_battery.c > @@ -139,7 +139,6 @@ static int fwts_battery_get_capacity_proc_fs(fwts_framework *fw, > entry = readdir(dir); > if (entry && strlen(entry->d_name) > 2) { > char path[PATH_MAX]; > - char units[64]; > int val; > FILE *fp; > bool match = ((index == FWTS_BATTERY_ALL) || (index == i)); > @@ -156,6 +155,8 @@ static int fwts_battery_get_capacity_proc_fs(fwts_framework *fw, > while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) { > if (strstr(buffer, field) && > strlen(buffer) > 25) { > + char units[64]; > + > sscanf(buffer+25, "%d %63s", &val, units); > if (strncmp(units, "mAh",3) == 0) { > *capacity_mAh += val; > Acked-by: Ivan Hu <ivan.hu@canonical.com>
On 01/14/2015 03:04 AM, Colin King wrote: > From: Colin Ian King <colin.king@canonical.com> > > cppcheck is picking up some minor style issues which can > be easily fixed: > > [src/lib/src/fwts_battery.c:142]: > (style) The scope of the variable 'units' can be reduced. > > Signed-off-by: Colin Ian King <colin.king@canonical.com> > --- > src/lib/src/fwts_battery.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/src/lib/src/fwts_battery.c b/src/lib/src/fwts_battery.c > index 8a84998..f6eb56d 100644 > --- a/src/lib/src/fwts_battery.c > +++ b/src/lib/src/fwts_battery.c > @@ -139,7 +139,6 @@ static int fwts_battery_get_capacity_proc_fs(fwts_framework *fw, > entry = readdir(dir); > if (entry && strlen(entry->d_name) > 2) { > char path[PATH_MAX]; > - char units[64]; > int val; > FILE *fp; > bool match = ((index == FWTS_BATTERY_ALL) || (index == i)); > @@ -156,6 +155,8 @@ static int fwts_battery_get_capacity_proc_fs(fwts_framework *fw, > while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) { > if (strstr(buffer, field) && > strlen(buffer) > 25) { > + char units[64]; > + > sscanf(buffer+25, "%d %63s", &val, units); > if (strncmp(units, "mAh",3) == 0) { > *capacity_mAh += val; > Acked-by: Alex Hung <alex.hung@canonical.com>
diff --git a/src/lib/src/fwts_battery.c b/src/lib/src/fwts_battery.c index 8a84998..f6eb56d 100644 --- a/src/lib/src/fwts_battery.c +++ b/src/lib/src/fwts_battery.c @@ -139,7 +139,6 @@ static int fwts_battery_get_capacity_proc_fs(fwts_framework *fw, entry = readdir(dir); if (entry && strlen(entry->d_name) > 2) { char path[PATH_MAX]; - char units[64]; int val; FILE *fp; bool match = ((index == FWTS_BATTERY_ALL) || (index == i)); @@ -156,6 +155,8 @@ static int fwts_battery_get_capacity_proc_fs(fwts_framework *fw, while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) { if (strstr(buffer, field) && strlen(buffer) > 25) { + char units[64]; + sscanf(buffer+25, "%d %63s", &val, units); if (strncmp(units, "mAh",3) == 0) { *capacity_mAh += val;