[FIX] MSG_SYSTEM_INFO length calculation
authorNikita Kalyazin <n.kalyazin@samsung.com>
Fri, 25 Oct 2013 11:34:45 +0000 (15:34 +0400)
committerNikita Kalyazin <n.kalyazin@samsung.com>
Fri, 25 Oct 2013 13:23:05 +0000 (17:23 +0400)
Change-Id: I248137a87f3556e5347542e474a0dc44853563cd
Signed-off-by: Nikita Kalyazin <n.kalyazin@samsung.com>
daemon/sys_stat.c

index ded26aa..345eb7d 100644 (file)
@@ -2717,12 +2717,24 @@ struct msg_data_t *pack_system_info(struct system_info_t *sys_info)
        struct msg_data_t *msg = NULL;
        char *p = NULL;
        int i = 0;
-       uint32_t len = sizeof(*sys_info) -
-               (sizeof(sys_info->thread_load) +
-                sizeof(sys_info->process_load)) +
-               2 * num_of_cpu * sizeof(float) +
-               sys_info->count_of_threads * sizeof(*sys_info->thread_load) +
-               sys_info->count_of_processes * sizeof(*sys_info->process_load);
+       uint32_t len = 0;
+
+       len += sizeof(*sys_info);
+
+       // num_of_cpu is unknown at compile time
+       len += 2 * num_of_cpu * sizeof(float);
+
+       // subtract pointers
+       len -= sizeof(sys_info->cpu_frequency) + sizeof(sys_info->cpu_load);
+       len -= sizeof(sys_info->thread_load) + sizeof(sys_info->process_load);
+
+       if (IS_OPT_SET(FL_CPU))
+               len += sys_info->count_of_threads *
+                       sizeof(*sys_info->thread_load);
+
+       if (IS_OPT_SET(FL_PROCESSES))
+               len += sys_info->count_of_processes *
+                       sizeof(*sys_info->process_load);
 
        msg = malloc(MSG_DATA_HDR_LEN + len);
        if (!msg) {