[gnome-power-manager] Correct some shoddy error checking. Spotted by clang
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-power-manager] Correct some shoddy error checking. Spotted by clang
- Date: Mon, 7 Sep 2009 08:20:23 +0000 (UTC)
commit 1155708ecc64854dd1f1051946693a82d9deb024
Author: Richard Hughes <richard hughsie com>
Date: Mon Sep 7 09:19:02 2009 +0100
Correct some shoddy error checking. Spotted by clang
src/gpm-load.c | 25 ++++++++++++++++++-------
1 files changed, 18 insertions(+), 7 deletions(-)
---
diff --git a/src/gpm-load.c b/src/gpm-load.c
index f625842..94f37b9 100644
--- a/src/gpm-load.c
+++ b/src/gpm-load.c
@@ -170,20 +170,31 @@ gpm_load_get_cpu_values (long unsigned *cpu_idle, long unsigned *cpu_total)
char str[80];
FILE *fd;
char *suc;
+ gboolean ret = FALSE;
+ /* open file */
fd = fopen("/proc/stat", "r");
if (!fd)
- return FALSE;
+ goto out;
+
+ /* get data */
suc = fgets (str, 80, fd);
+ if (suc == NULL)
+ goto out;
+
+ /* parse */
len = sscanf (str, "%s %lu %lu %lu %lu", tmp,
&cpu_user, &cpu_nice, &cpu_system, cpu_idle);
- fclose (fd);
- /*
- * Summing up all these times gives you the system uptime in jiffies.
- * This is what the uptime command does.
- */
+ if (len != 5)
+ goto out;
+
+ /* summing up all these times gives you the system uptime in jiffies */
*cpu_total = cpu_user + cpu_nice + cpu_system + *cpu_idle;
- return TRUE;
+ ret = TRUE;
+out:
+ if (!fd)
+ fclose (fd);
+ return ret;
}
#endif /* sun & __SVR4 */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]