Fix: SVACE Issues in Source Code 50/223650/3 accepted/tizen/unified/20200219.130122 submit/tizen/20200219.053054
authorDewal Agarwal <d1.agarwal@samsung.com>
Fri, 31 Jan 2020 12:48:13 +0000 (18:18 +0530)
committerDewal Agarwal <d1.agarwal@samsung.com>
Wed, 19 Feb 2020 05:26:39 +0000 (05:26 +0000)
Change-Id: I77d41645a46f7bcb768d6b3e87e04b5918ba5be5
Signed-off-by: Dewal Agarwal <d1.agarwal@samsung.com>
include/bd_history_item.h
src/battery_dump/bd_history_item.c
src/battery_dump/bd_history_item_dummy.c
src/bm_server_db.c

index e287f0d..7263e01 100644 (file)
@@ -99,7 +99,7 @@ typedef struct _encoding_map_s {
 // Functions for the other part of the service
 int bd_initialize_battery_dump(void);
 int bd_deinitialize_battery_dump(void);
-int bd_print_history_item_main(int fd, int num_h_items, long base_time, bool chkin);
+int bd_print_history_item_main(int fd, int num_h_items, long long base_time, bool chkin);
 int bd_store_history_item(history_item_s* nrec);
 int bd_print_history_item_reset(history_item_s* old_state);
 
index 805354b..c52dd14 100644 (file)
@@ -223,7 +223,7 @@ static int bd_get_and_print_battery_usage_from_dump(int fd, long int duration)
                //ret = bm_engine_get_total_usage_by_app_id(appid, 1, &usage);
                usageMAh = (usageMAh/1000);
                dump_p = g_string_sized_new(30);
-               BM_CHECK_MEM_ALLOC(dump_p, {});
+               BM_CHECK_MEM_ALLOC(dump_p, { BM_FREE(app_use); });
                g_string_append(dump_p, TIZEN_DUMP_VERSION);
                g_string_append_printf(dump_p, ",%d,l,pwi,uid,", *uid_n);
                g_string_append_printf(dump_p, "%0.2f", usageMAh);
@@ -246,10 +246,14 @@ static int bd_get_and_print_battery_usage_from_dump(int fd, long int duration)
                }
                resourceid_usage_s *res_use =
                        bm_server_query_resource_usage_resourceid(rid_str, 1, &ret);
+               if (res_use == NULL || ret != BATTERY_MONITOR_ERROR_NONE) {
+                       _ERR("For resourceid %s", rid_str);
+                       continue;
+               }
+               dump_p = g_string_sized_new(30);
+               BM_CHECK_MEM_ALLOC(dump_p, {BM_FREE(res_use); });
                usage = res_use->usage;
                usageMAh = (float)usage/1000;
-               dump_p = g_string_sized_new(30);
-               BM_CHECK_MEM_ALLOC(dump_p, {});
                g_string_append(dump_p, TIZEN_DUMP_VERSION);
                switch (i) {
                case 0://BT
@@ -680,7 +684,7 @@ int bd_print_history_item_reset(history_item_s* old_state)
        return BATTERY_MONITOR_ERROR_NONE;
 }
 
-int bd_print_history_item_main(int fd, int num_h_items, long base_time, bool chkin)
+int bd_print_history_item_main(int fd, int num_h_items, long long base_time, bool chkin)
 {
        ENTER;
 
@@ -1119,8 +1123,12 @@ static int bd_set_history_from_listener(history_item_s* nrec)
 
        time_t current_time = tv.tv_sec;
 
-//     history_data[h_count].time_s = current_time;// comment for testing with test fn
+
+#ifdef DUMP_DUMMY
        history_data[h_count].time_s = nrec->time_s;
+#else
+       history_data[h_count].time_s = ((long long)tv.tv_sec * 1000) + ((long long)tv.tv_usec / 1000);
+#endif
 
        dvar1 = ((nrec->cmd_s) & 0xff) | ((nrec->battery_level << 8) & 0xff00) |
                ((nrec->battery_status << 16) & 0xf0000) |
@@ -1145,7 +1153,6 @@ static int bd_set_history_from_listener(history_item_s* nrec)
        if (nrec->wakereason_tag != NULL)
                history_data[h_count].wakereason_tag = nrec->wakereason_tag;
        if (nrec->event_code != ET_NONE) {
-               _DBG("HI");
                if (nrec->event_tag == NULL)
                        _ERR("IT is NULL");
                history_data[h_count].event_code = nrec->event_code;
@@ -1160,14 +1167,15 @@ static int bd_set_history_from_listener(history_item_s* nrec)
        history_data[h_count].usage_type = nrec->usage_type;
        history_data[h_count].usage = nrec->usage;
 
-       if (h_count < HISTORY_SIZE_MAX)
+       if (h_count < HISTORY_SIZE_MAX - 1)
                h_count++;
        else {
-               //: Give some buffer
                // FIXME modify 1st argument (fd)
                int ret = bd_print_history_item_main(-1, 0, current_time, 1);
-               if (ret != BATTERY_MONITOR_ERROR_NONE)
+               if (ret != BATTERY_MONITOR_ERROR_NONE) {
+                       h_count = 0;
                        return ret;
+               }
                h_count = 0;
        }
 
index 53dc602..32545e8 100644 (file)
@@ -87,15 +87,13 @@ static int create_event_tag(history_item_s* ts, int mask, int state, int on)
                                ts->event_tag->sp_idx = pool_idx_map_s2[mask];
                        } else {
                                ts->event_tag->sp_idx = pool_idx_map_s2[mask];
-                               pool_idx_map_s1[mask] = -1;
+                               pool_idx_map_s2[mask] = -1;
                        }
                } else
                        ts->event_tag->sp_idx = pool_idx++;
 
-               if (on)
-                       temp = g_string_append(temp, "tizen");
-               else
-                       temp = g_string_append(temp, "tizen");
+               _DBG("Value of ON is %d:" on);
+               temp = g_string_append(temp, "tizen");
                ts->event_tag->string_info = temp;
                _DBG("%s", ts->event_tag->string_info->str);
        }
@@ -114,7 +112,7 @@ static int create_wakelock_tag(history_item_s* ts, int mask, int state, int on)
                GString *temp = ts->wakelock_tag->string_info;
                temp = g_string_sized_new(30);
                BM_CHECK_MEM_ALLOC(temp, {});
-               ts->wakelock_tag->uid = 0;
+               ts->wakelock_tag->uid = 1000;
                if (state == 1) {
                        if (pool_idx_map_s1[mask] == -1) {
                                pool_idx_map_s1[mask] = pool_idx++;
@@ -126,10 +124,8 @@ static int create_wakelock_tag(history_item_s* ts, int mask, int state, int on)
                } else
                        ts->wakelock_tag->sp_idx = pool_idx++;
 
-               if (on)
-                       temp = g_string_append(temp, "tizen");
-               else
-                       temp = g_string_append(temp, "tizen");
+               _DBG("Value of ON is %d:" on);
+               temp = g_string_append(temp, "tizen");
                ts->wakelock_tag->string_info = temp;
                _DBG("%s", ts->wakelock_tag->string_info->str);
        }
index 26cb218..98abad7 100644 (file)
@@ -261,8 +261,6 @@ static int bm_query_bind_text(bm_stmt pStmt, int pos, const char *str)
                _INFO("sqlite3_bind_null");
                return sqlite3_bind_null(pStmt, pos);
        }
-
-       EXIT;
 }
 
 static int bm_query_table_column_int(bm_stmt pStmt, int pos)