Add an exception handling about overflow 02/114302/4
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 13 Feb 2017 08:34:06 +0000 (17:34 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 13 Feb 2017 08:36:57 +0000 (17:36 +0900)
Change-Id: If173382502806a399ddfa1b5f6553a6601cb0bd1
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
inc/launchpad_common.h
src/launchpad.c
src/launchpad_common.c

index 63a9de3..93ba100 100644 (file)
@@ -105,7 +105,7 @@ void _appinfo_free(appinfo_t *menu_info);
 char *_appinfo_get_app_path(appinfo_t *menu_info);
 int _proc_get_attr_by_pid(int pid, char *buf, int size);
 int _close_all_fds(void);
-void _get_cpu_idle(long long *total, long long *idle);
+void _get_cpu_idle(unsigned long long *total, unsigned long long *idle);
 int _setup_stdio(const char *ident);
 
 #endif /* __LAUNCHPAD_COMMON_H__ */
index 9177a5f..2c38f2b 100755 (executable)
@@ -74,8 +74,8 @@ typedef struct {
        char *loader_extra;
        int detection_method;
        int timeout_val;
-       long long cpu_total_time;
-       long long cpu_idle_time;
+       unsigned long long cpu_total_time;
+       unsigned long long cpu_idle_time;
        guint idle_checker;
 } candidate_process_context_t;
 
@@ -1082,8 +1082,8 @@ static gboolean __handle_label_monitor(gpointer data)
 
 static gboolean __handle_idle_checker(gpointer data)
 {
-       long long total = 0;
-       long long idle = 0;
+       unsigned long long total = 0;
+       unsigned long long idle = 0;
        int per;
        candidate_process_context_t *cpc = data;
 
@@ -1109,8 +1109,8 @@ static int __dispatch_cmd_hint(bundle *kb, int detection_method)
 {
        candidate_process_context_t *cpc;
        GList *iter = candidate_slot_list;
-       long long total = 0;
-       long long idle = 0;
+       unsigned long long total = 0;
+       unsigned long long idle = 0;
 
        _W("cmd hint %d", detection_method);
        while (iter) {
@@ -1575,8 +1575,8 @@ static void __add_slot_from_info(gpointer data, gpointer user_data)
        candidate_process_context_t *cpc;
        bundle_raw *extra = NULL;
        int len;
-       long long total = 0;
-       long long idle = 0;
+       unsigned long long total = 0;
+       unsigned long long idle = 0;
 
        if (!strcmp(info->exe, "null")) {
                cpc = __add_slot(LAUNCHPAD_TYPE_USER + user_slot_offset,
index 201c3d9..d36c2e4 100644 (file)
@@ -72,13 +72,13 @@ static int __read_proc(const char *path, char *buf, int size)
        return ret;
 }
 
-void _get_cpu_idle(long long *total, long long *idle)
+void _get_cpu_idle(unsigned long long *total, unsigned long long *idle)
 {
        FILE *fp;
        int i;
-       long long sum = 0;
-       long long val;
-       long long iv = 0;
+       unsigned long long sum = 0;
+       unsigned long long val;
+       unsigned long long iv = 0;
        char buf[4] = { 0, };
 
        fp = fopen("/proc/stat", "rt");
@@ -96,6 +96,13 @@ void _get_cpu_idle(long long *total, long long *idle)
                        fclose(fp);
                        return;
                }
+
+               if (sum + val < sum) {
+                       _E("overflow");
+                       fclose(fp);
+                       return;
+               }
+
                sum += val;
                if (i == 3) /* idle */
                        iv = val;