Rearrange the scope of each temporary variables
[platform/core/uifw/voice-control.git] / common / vc_command.c
old mode 100755 (executable)
new mode 100644 (file)
index 61053a9..e6b5767
 #include "voice_control_common.h"
 #include "voice_control_key_defines.h"
 
+static pthread_mutex_t g_cmd_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t g_cmd_list_mutex = PTHREAD_MUTEX_INITIALIZER;
+#define CMD_MUTEX_LOCK()       pthread_mutex_lock(&g_cmd_mutex)
+#define CMD_MUTEX_UNLOCK()     pthread_mutex_unlock(&g_cmd_mutex)
+#define CMD_LIST_MUTEX_LOCK()  pthread_mutex_lock(&g_cmd_list_mutex)
+#define CMD_LIST_MUTEX_UNLOCK()        pthread_mutex_unlock(&g_cmd_list_mutex)
+
 static int g_feature_enabled = -1;
+static bool g_privilege_allowed = false;
 
-static int g_privilege_allowed = 1; /* Always True */
+static pthread_mutex_t g_cynara_mutex = PTHREAD_MUTEX_INITIALIZER;
 static cynara *p_cynara = NULL;
+static GList *g_cmd_list = NULL;
+static GList *g_cmdlist_list = NULL;
+
 
 // For getting timestamp using regular expression
 static regex_t reg[MAX_NUM_REGEX];
 static time_t t_now;           //time_t is based on UTC
-static struct tm *td_now;      //if use localtime function, the value follows the local time zone, otherwise it follows the UTC.
+static struct tm td_now;       //if use localtime function, the value follows the local time zone, otherwise it follows the UTC.
 
 static int g_time_flag;
 static int g_date_flag;
@@ -76,7 +87,7 @@ static int __vc_cmd_get_feature_enabled()
                }
        }
 
-       return 0;
+       return VC_ERROR_NONE;
 }
 
 static int __check_privilege_initialize()
@@ -95,15 +106,15 @@ static int __check_privilege(const char* uid, const char * privilege)
        char smack_label[1024] = {'\0',};
 
        if (!p_cynara) {
-           return false;
+               return false;
        }
 
        fp = fopen(label_path, "r");
        if (fp != NULL) {
-           if (fread(smack_label, 1, sizeof(smack_label), fp) <= 0)
-               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] fail to fread");
+               if (0 >= fread(smack_label, 1, sizeof(smack_label), fp))
+                       SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] fail to fread");
 
-           fclose(fp);
+               fclose(fp);
        }
 
        pid_t pid = getpid();
@@ -111,44 +122,60 @@ static int __check_privilege(const char* uid, const char * privilege)
        int ret = cynara_check(p_cynara, smack_label, session, uid, privilege);
        SLOG(LOG_DEBUG, TAG_VCCMD, "[Client]cynara_check returned %d(%s)", ret, (CYNARA_API_ACCESS_ALLOWED == ret) ? "Allowed" : "Denied");
        if (session)
-           free(session);
+               free(session);
 
        if (ret != CYNARA_API_ACCESS_ALLOWED)
-           return false;
+               return false;
        return true;
 }
 
 static void __check_privilege_deinitialize()
 {
        if (p_cynara)
-               cynara_finish(p_cynara);
+       {
+               int ret = cynara_finish(p_cynara);
+               if (ret != CYNARA_API_SUCCESS)
+                       SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] cynara finish %d", ret);
+       }
        p_cynara = NULL;
 }
 
 static int __vc_cmd_check_privilege()
 {
-       char uid[16];
+       if (true == g_privilege_allowed)
+               return VC_ERROR_NONE;
 
-       if (0 == g_privilege_allowed) {
-               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Permission is denied");
-               return VC_ERROR_PERMISSION_DENIED;
-       } else if (-1 == g_privilege_allowed) {
-               if (false == __check_privilege_initialize()) {
+       pthread_mutex_lock(&g_cynara_mutex);
+
+       if (false == g_privilege_allowed) {
+               bool ret = true;
+               ret = __check_privilege_initialize();
+               if (false == ret) {
                        SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] privilege initialize is failed");
+                       g_privilege_allowed = false;
+                       pthread_mutex_unlock(&g_cynara_mutex);
                        return VC_ERROR_PERMISSION_DENIED;
                }
-               snprintf(uid, 16, "%d", getuid());
-               if (false == __check_privilege(uid, VC_PRIVILEGE)) {
-                       SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Permission is denied");
-                       g_privilege_allowed = 0;
+
+               char uid[32];
+               snprintf(uid, 32, "%d", getuid());
+               ret = true;
+               ret = __check_privilege(uid, VC_PRIVILEGE_RECORDER);
+               if (false == ret) {
+                       //LCOV_EXCL_START
+                       SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Permission is denied(%s)(%s)", VC_PRIVILEGE_RECORDER, uid);
                        __check_privilege_deinitialize();
+                       g_privilege_allowed = false;
+                       pthread_mutex_unlock(&g_cynara_mutex);
                        return VC_ERROR_PERMISSION_DENIED;
+                       //LCOV_EXCL_STOP
                }
+
                __check_privilege_deinitialize();
        }
 
-       g_privilege_allowed = 1;
-
+       g_privilege_allowed = true;
+       pthread_mutex_unlock(&g_cynara_mutex);
        return VC_ERROR_NONE;
 }
 
@@ -161,8 +188,11 @@ int vc_cmd_list_create(vc_cmd_list_h* vc_cmd_list)
                return VC_ERROR_PERMISSION_DENIED;
        }
 
+       CMD_LIST_MUTEX_LOCK();
+
        if (NULL == vc_cmd_list) {
                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
+               CMD_LIST_MUTEX_UNLOCK();
                return VC_ERROR_INVALID_PARAMETER;
        }
 
@@ -170,6 +200,7 @@ int vc_cmd_list_create(vc_cmd_list_h* vc_cmd_list)
 
        if (NULL == list) {
                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Not enough memory");
+               CMD_LIST_MUTEX_UNLOCK();
                return VC_ERROR_OUT_OF_MEMORY;
        }
 
@@ -178,8 +209,11 @@ int vc_cmd_list_create(vc_cmd_list_h* vc_cmd_list)
 
        *vc_cmd_list = (vc_cmd_list_h)list;
 
+       g_cmdlist_list = g_list_append(g_cmdlist_list, list);
+
        SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p)", *vc_cmd_list);
 
+       CMD_LIST_MUTEX_UNLOCK();
        return VC_ERROR_NONE;
 }
 
@@ -192,23 +226,37 @@ int vc_cmd_list_destroy(vc_cmd_list_h vc_cmd_list, bool release_command)
                return VC_ERROR_PERMISSION_DENIED;
        }
 
+       CMD_LIST_MUTEX_LOCK();
+
        if (NULL == vc_cmd_list) {
                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
+               CMD_LIST_MUTEX_UNLOCK();
                return VC_ERROR_INVALID_PARAMETER;
        }
 
-       vc_cmd_list_remove_all(vc_cmd_list, release_command);
 
        vc_cmd_list_s* list = NULL;
        list = (vc_cmd_list_s*)vc_cmd_list;
 
        SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p)", list);
 
-       if (NULL != list) {
-               free(list);
-               list = NULL;
+       GList *iter = NULL;
+       iter = g_list_find(g_cmdlist_list, list);
+       if (NULL == iter) {
+               SLOG(LOG_ERROR, TAG_VCCMD, "Fail to destroy client : handle is not valid");
+               CMD_LIST_MUTEX_UNLOCK();
+               return VC_ERROR_INVALID_PARAMETER;
        }
 
+       g_cmdlist_list = g_list_delete_link(g_cmdlist_list, iter);
+
+       vc_cmd_list_remove_all((vc_cmd_list_h)list, release_command);
+       free(list);
+       list = NULL;
+
+       SLOG(LOG_DEBUG, TAG_VCCMD, "Client destroy");
+
+       CMD_LIST_MUTEX_UNLOCK();
        return VC_ERROR_NONE;
 }
 
@@ -289,41 +337,34 @@ int vc_cmd_list_remove(vc_cmd_list_h vc_cmd_list, vc_cmd_h vc_command)
 
        SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p), command(%p)", list, cmd);
 
-       vc_cmd_s* temp_cmd = NULL;
        GSList *iter = NULL;
-
-       iter = g_slist_nth(list->list, 0);
-
-       while (NULL != iter) {
-               temp_cmd = iter->data;
-
-               if (NULL != temp_cmd && cmd == temp_cmd) {
-                       list->list = g_slist_remove(list->list, temp_cmd);
-                       /*
-                       if (true == release_command) {
-                               SLOG(LOG_DEBUG, TAG_VCCMD, "Release command data");
-                               if (NULL != temp_cmd->command)          free(temp_cmd->command);
-                               if (NULL != temp_cmd->parameter)        free(temp_cmd->parameter);
-                               free(temp_cmd);
-                               temp_cmd = NULL;
-                       }
-                       */
-               }
-
-               iter = g_slist_next(iter);
+       iter = g_slist_find(list->list, cmd);
+       if (NULL == iter) {
+               SLOG(LOG_ERROR, TAG_VCCMD, "Fail to destroy command : handle is not valid");
+               return VC_ERROR_INVALID_PARAMETER;
        }
 
-       int count = g_slist_length(list->list);
+       list->list = g_slist_remove_link(list->list, iter);
+       SLOG(LOG_DEBUG, TAG_VCCMD, "destroy command");
 
-       if (0 == count) {
+       int len = g_slist_length(list->list);
+       if (0 == len)
                list->index = -1;
-       } else if (list->index == count) {
-               list->index = count - 1;
-       }
+       else if (list->index == len)
+               list->index = len - 1;
 
        return VC_ERROR_NONE;
 }
 
+static void __vc_cmd_list_remove_all_foreach(gpointer data)
+{
+       vc_cmd_s *temp = (vc_cmd_s *)data;
+       if (temp) {
+               SECURE_SLOG(LOG_DEBUG, TAG_VCCMD, "Free command(%p)", temp);
+               vc_cmd_destroy((vc_cmd_h)temp);
+       }
+}
+
 int vc_cmd_list_remove_all(vc_cmd_list_h vc_cmd_list, bool release_command)
 {
        if (0 != __vc_cmd_get_feature_enabled()) {
@@ -333,44 +374,33 @@ int vc_cmd_list_remove_all(vc_cmd_list_h vc_cmd_list, bool release_command)
                return VC_ERROR_PERMISSION_DENIED;
        }
 
-       SLOG(LOG_DEBUG, TAG_VCCMD, "===== Destroy all command");
+       SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Destroy all command");
 
        if (NULL == vc_cmd_list) {
                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
                return VC_ERROR_INVALID_PARAMETER;
        }
 
-       vc_cmd_list_s* list = NULL;
-       list = (vc_cmd_list_s*)vc_cmd_list;
+       vc_cmd_list_s* cmd_list = (vc_cmd_list_s*)vc_cmd_list;
 
        SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list (%p), release command (%s)"
-                , list, release_command ? "true" : "false");
+                , cmd_list, release_command ? "true" : "false");
 
-       int count = g_slist_length(list->list);
-
-       int i ;
-       vc_cmd_s *temp_cmd;
-
-       for (i = 0; i < count ; i++) {
-               temp_cmd = g_slist_nth_data(list->list, 0);
-
-               if (NULL != temp_cmd) {
-                       list->list = g_slist_remove(list->list, temp_cmd);
+       if (NULL == cmd_list->list) {
+               SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ List is already empty.");
+               return VC_ERROR_NONE;
+       }
 
-                       if (true == release_command) {
-                               SLOG(LOG_DEBUG, TAG_VCCMD, "Free command(%p)", temp_cmd);
-                               if (NULL != temp_cmd->command)          free(temp_cmd->command);
-                               if (NULL != temp_cmd->parameter)        free(temp_cmd->parameter);
-                               free(temp_cmd);
-                               temp_cmd = NULL;
-                       }
-               }
+       if (true == release_command) {
+               g_slist_free_full(cmd_list->list, __vc_cmd_list_remove_all_foreach);
+       } else {
+               g_slist_free(cmd_list->list);
        }
 
-       list->index = -1;
+       cmd_list->list = NULL;
+       cmd_list->index = -1;
 
-       SLOG(LOG_DEBUG, TAG_VCCMD, "=====");
-       SLOG(LOG_DEBUG, TAG_VCCMD, " ");
+       SLOG(LOG_DEBUG, TAG_VCCMD, "@@@");
 
        return VC_ERROR_NONE;
 }
@@ -384,7 +414,7 @@ int vc_cmd_list_foreach_commands(vc_cmd_list_h vc_cmd_list, vc_cmd_list_cb callb
                return VC_ERROR_PERMISSION_DENIED;
        }
 
-       if (NULL == vc_cmd_list) {
+       if (NULL == vc_cmd_list || NULL == callback) {
                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
                return VC_ERROR_INVALID_PARAMETER;
        }
@@ -392,39 +422,29 @@ int vc_cmd_list_foreach_commands(vc_cmd_list_h vc_cmd_list, vc_cmd_list_cb callb
        vc_cmd_list_s* list = NULL;
        list = (vc_cmd_list_s*)vc_cmd_list;
 
-       int count = g_slist_length(list->list);
-       int i ;
-
        GSList *iter = NULL;
-       vc_cmd_s *temp_cmd;
-
        iter = g_slist_nth(list->list, 0);
-
-       for (i = 0; i < count; i++) {
-               if (NULL == iter) {
+       while (NULL != iter) {
+               vc_cmd_s *temp_cmd = NULL;
+               temp_cmd = iter->data;
+               if (NULL == temp_cmd) {
                        SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] No command in list");
                        return VC_ERROR_OPERATION_FAILED;
                }
+               if (false == callback((vc_cmd_h)temp_cmd, user_data))
+                       break;
 
-               temp_cmd = iter->data;
-
-               if (NULL != temp_cmd) {
-                       if (false == callback((vc_cmd_h)temp_cmd, user_data)) {
-                               break;
-                       }
-
-               }
                iter = g_slist_next(iter);
        }
 
-       SLOG(LOG_DEBUG, TAG_VCCMD, "===== Foreach commands Done");
+       SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Foreach commands Done");
 
        return VC_ERROR_NONE;
 }
 
 int vc_cmd_list_filter_by_type(vc_cmd_list_h original, int type, vc_cmd_list_h* filtered)
 {
-       SLOG(LOG_DEBUG, TAG_VCCMD, "===== Filter by type");
+       SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Filter by type");
 
        if (0 != __vc_cmd_get_feature_enabled()) {
                return VC_ERROR_NOT_SUPPORTED;
@@ -433,7 +453,7 @@ int vc_cmd_list_filter_by_type(vc_cmd_list_h original, int type, vc_cmd_list_h*
                return VC_ERROR_PERMISSION_DENIED;
        }
 
-       if (NULL == original) {
+       if (NULL == original || NULL == filtered) {
                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
                return VC_ERROR_INVALID_PARAMETER;
        }
@@ -452,56 +472,45 @@ int vc_cmd_list_filter_by_type(vc_cmd_list_h original, int type, vc_cmd_list_h*
                return VC_ERROR_OPERATION_FAILED;
        }
 
-       int count = g_slist_length(list->list);
-       int i;
-
        GSList *iter = NULL;
-       vc_cmd_s *iter_cmd;
-
        iter = g_slist_nth(list->list, 0);
-
-       for (i = 0; i < count; i++) {
-               if (NULL == iter) {
+       while (NULL != iter) {
+               vc_cmd_s *iter_cmd = NULL;
+               iter_cmd = iter->data;
+               if (NULL == iter_cmd) {
                        SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] No command in list");
                        return VC_ERROR_OPERATION_FAILED;
                }
-               if (NULL != iter->data) {
-                       iter_cmd = iter->data;
-
-                       if (NULL != iter_cmd) {
-                               int iter_type;
-                               if (0 != vc_cmd_get_type((vc_cmd_h)iter_cmd, &iter_type)) {
-                                       SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get command type");
-                                       continue;
-                               }
 
-                               if (iter_type == type) {
-                                       vc_cmd_h temp_cmd;
-                                       if (0 != vc_cmd_create(&temp_cmd)) {
-                                               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to create cmd");
-                                               continue;
-                                       }
-
-                                       memcpy(temp_cmd, iter_cmd, sizeof(vc_cmd_s));
-                                       if (NULL != iter_cmd->command) {
-                                               ((vc_cmd_s*)temp_cmd)->command = strdup(iter_cmd->command);
-                                       }
-                                       if (NULL != iter_cmd->parameter) {
-                                               ((vc_cmd_s*)temp_cmd)->parameter = strdup(iter_cmd->parameter);
-                                       }
-
-                                       if (0 != vc_cmd_list_add(temp_list, temp_cmd)) {
-                                               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to cmd list add");
-                                               vc_cmd_destroy(temp_cmd);
-                                               continue;
-                                       }
-                               }
+               int iter_type = 0;
+               if (0 != vc_cmd_get_type((vc_cmd_h)iter_cmd, &iter_type)) {
+                       SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get command type");
+                       continue;
+               }
+
+               if (iter_type == type) {
+                       vc_cmd_h temp_cmd;
+                       if (0 != vc_cmd_create(&temp_cmd)) {
+                               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to create cmd");
+                               continue;
+                       }
+
+                       memcpy(temp_cmd, iter_cmd, sizeof(vc_cmd_s));
+                       if (NULL != iter_cmd->command)
+                               ((vc_cmd_s *)temp_cmd)->command = strdup(iter_cmd->command);
+                       if (NULL != iter_cmd->parameter)
+                               ((vc_cmd_s *)temp_cmd)->parameter = strdup(iter_cmd->parameter);
+
+                       if (0 != vc_cmd_list_add(temp_list, temp_cmd)) {
+                               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to cmd list add");
+                               vc_cmd_destroy(temp_cmd);
+                               continue;
                        }
                }
                iter = g_slist_next(iter);
        }
 
-       count = 0;
+       int count = 0;
        if (0 != vc_cmd_list_get_count(temp_list, &count)) {
                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get count");
        } else {
@@ -510,7 +519,7 @@ int vc_cmd_list_filter_by_type(vc_cmd_list_h original, int type, vc_cmd_list_h*
 
        *filtered = temp_list;
 
-       SLOG(LOG_DEBUG, TAG_VCCMD, "=====");
+       SLOG(LOG_DEBUG, TAG_VCCMD, "@@@");
 
        return VC_ERROR_NONE;
 }
@@ -590,6 +599,10 @@ int vc_cmd_list_next(vc_cmd_list_h vc_cmd_list)
        list = (vc_cmd_list_s*)vc_cmd_list;
 
        int count = g_slist_length(list->list);
+       if (0 == count) {
+               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] List is empty");
+               return VC_ERROR_EMPTY;
+       }
 
        if (list->index < count - 1) {
                list->index = list->index + 1;
@@ -619,6 +632,11 @@ int vc_cmd_list_prev(vc_cmd_list_h vc_cmd_list)
        vc_cmd_list_s* list = NULL;
        list = (vc_cmd_list_s*)vc_cmd_list;
 
+       if (0 == g_slist_length(list->list)) {
+               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] List is empty");
+               return VC_ERROR_EMPTY;
+       }
+
        if (list->index > 0) {
                list->index = list->index - 1;
                SLOG(LOG_DEBUG, TAG_VCCMD, "[DEBUG] List index : %d", list->index);
@@ -675,8 +693,11 @@ int vc_cmd_create(vc_cmd_h* vc_command)
                return VC_ERROR_PERMISSION_DENIED;
        }
 
+       CMD_MUTEX_LOCK();
+
        if (NULL == vc_command) {
                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
+               CMD_MUTEX_UNLOCK();
                return VC_ERROR_INVALID_PARAMETER;
        }
 
@@ -684,6 +705,7 @@ int vc_cmd_create(vc_cmd_h* vc_command)
 
        if (NULL == command) {
                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Not enough memory");
+               CMD_MUTEX_UNLOCK();
                return VC_ERROR_OUT_OF_MEMORY;
        }
 
@@ -698,11 +720,18 @@ int vc_cmd_create(vc_cmd_h* vc_command)
        command->priority = 0;
        command->key = VC_KEY_NONE;
        command->modifier = VC_MODIFIER_NONE;
+       command->invocation_name = NULL;
+       command->appid = NULL;
+       command->fixed = NULL;
+       command->coordinates = NULL;
 
        *vc_command = (vc_cmd_h)command;
 
+       g_cmd_list = g_list_append(g_cmd_list, command);
+
        SLOG(LOG_DEBUG, TAG_VCCMD, "[Create command][%p]", *vc_command);
 
+       CMD_MUTEX_UNLOCK();
        return VC_ERROR_NONE;
 }
 
@@ -715,8 +744,11 @@ int vc_cmd_destroy(vc_cmd_h vc_command)
                return VC_ERROR_PERMISSION_DENIED;
        }
 
+       CMD_MUTEX_LOCK();
+
        if (NULL == vc_command) {
                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
+               CMD_MUTEX_UNLOCK();
                return VC_ERROR_INVALID_PARAMETER;
        }
 
@@ -725,13 +757,38 @@ int vc_cmd_destroy(vc_cmd_h vc_command)
 
        SLOG(LOG_DEBUG, TAG_VCCMD, "[Destroy command][%p]", command);
 
-       if (NULL != command) {
-               if (NULL != command->command)   free(command->command);
-               if (NULL != command->parameter) free(command->parameter);
-               free(command);
-               command = NULL;
+       GList *iter = NULL;
+       iter = g_list_find(g_cmd_list, command);
+       if (NULL == iter) {
+               SLOG(LOG_ERROR, TAG_VCCMD, "Fail to command destroy : handle is not valid");
+               CMD_MUTEX_UNLOCK();
+               return VC_ERROR_INVALID_PARAMETER;
        }
 
+       g_cmd_list = g_list_delete_link(g_cmd_list, iter);
+
+       if (command->command)
+               free(command->command);
+       command->command = NULL;
+       if (command->parameter)
+               free(command->parameter);
+       command->parameter = NULL;
+       if (command->invocation_name)
+               free(command->invocation_name);
+       command->invocation_name = NULL;
+       if (command->appid)
+               free(command->appid);
+       command->appid = NULL;
+       if (command->fixed)
+               free(command->fixed);
+       command->fixed = NULL;
+       if (command->coordinates)
+               free(command->coordinates);
+       command->coordinates = NULL;
+       free(command);
+       command = NULL;
+
+       CMD_MUTEX_UNLOCK();
        return VC_ERROR_NONE;
 }
 
@@ -752,14 +809,13 @@ int vc_cmd_set_id(vc_cmd_h vc_command, int id)
        vc_cmd_s* cmd = NULL;
        cmd = (vc_cmd_s*)vc_command;
 
-       if (NULL != cmd) {
-               cmd->id = id;
-               SLOG(LOG_DEBUG, TAG_VCCMD, "[Set id][%p] id(%d)", vc_command, cmd->id);
-       }
+       cmd->id = id;
+       SLOG(LOG_DEBUG, TAG_VCCMD, "[Set id][%p] id(%d)", vc_command, cmd->id);
 
-       return 0;
+       return VC_ERROR_NONE;
 }
 
+//LCOV_EXCL_START
 int vc_cmd_get_id(vc_cmd_h vc_command, int* id)
 {
        if (0 != __vc_cmd_get_feature_enabled()) {
@@ -777,13 +833,12 @@ int vc_cmd_get_id(vc_cmd_h vc_command, int* id)
        vc_cmd_s* cmd = NULL;
        cmd = (vc_cmd_s*)vc_command;
 
-       if (NULL != cmd) {
-               *id = cmd->id;
-               SLOG(LOG_DEBUG, TAG_VCCMD, "[Get id][%p] id(%d)", vc_command, *id);
-       }
+       *id = cmd->id;
+       SLOG(LOG_DEBUG, TAG_VCCMD, "[Get id][%p] id(%d)", vc_command, *id);
 
-       return 0;
+       return VC_ERROR_NONE;
 }
+//LCOV_EXCL_STOP
 
 int vc_cmd_set_appid(vc_cmd_h vc_command, const char* appid)
 {
@@ -804,15 +859,13 @@ int vc_cmd_set_appid(vc_cmd_h vc_command, const char* appid)
        vc_cmd_s* cmd = NULL;
        cmd = (vc_cmd_s*)vc_command;
 
-       if (NULL != cmd->appid) {
+       if (cmd->appid)
                free(cmd->appid);
-               cmd->appid = NULL;
-       }
-
+       cmd->appid = NULL;
        cmd->appid = strdup(appid);
 
        SLOG(LOG_DEBUG, TAG_VCCMD, "[Set appid][%p] appid(%s)", vc_command, cmd->appid);
-       return 0;
+       return VC_ERROR_NONE;
 }
 
 int vc_cmd_get_appid(vc_cmd_h vc_command, char** appid)
@@ -829,12 +882,14 @@ int vc_cmd_get_appid(vc_cmd_h vc_command, char** appid)
        vc_cmd_s* cmd = NULL;
        cmd = (vc_cmd_s*)vc_command;
 
-       if (NULL != cmd->appid) {
+       if (cmd->appid)
                *appid = strdup(gettext(cmd->appid));
-       }
+       else
+               *appid = NULL;
 
        SLOG(LOG_DEBUG, TAG_VCCMD, "[Get appid][%p] appid(%s)", vc_command, *appid);
-       return 0;
+
+       return VC_ERROR_NONE;
 }
 
 int vc_cmd_set_command(vc_cmd_h vc_command, const char* command)
@@ -846,7 +901,7 @@ int vc_cmd_set_command(vc_cmd_h vc_command, const char* command)
                return VC_ERROR_PERMISSION_DENIED;
        }
 
-       if (NULL == vc_command) {
+       if (NULL == vc_command || NULL == command) {
                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
                return VC_ERROR_INVALID_PARAMETER;
        }
@@ -854,19 +909,14 @@ int vc_cmd_set_command(vc_cmd_h vc_command, const char* command)
        vc_cmd_s* cmd = NULL;
        cmd = (vc_cmd_s*)vc_command;
 
-       if (NULL != cmd->command) {
+       if (cmd->command)
                free(cmd->command);
-       }
-
        cmd->command = NULL;
-
-       if (NULL != command) {
-               cmd->command = strdup(command);
-       }
+       cmd->command = strdup(command);
 
        SLOG(LOG_DEBUG, TAG_VCCMD, "[Set command][%p] Command(%s)", vc_command, cmd->command);
 
-       return 0;
+       return VC_ERROR_NONE;
 }
 
 int vc_cmd_get_command(vc_cmd_h vc_command, char** command)
@@ -886,13 +936,14 @@ int vc_cmd_get_command(vc_cmd_h vc_command, char** command)
        vc_cmd_s* cmd = NULL;
        cmd = (vc_cmd_s*)vc_command;
 
-       if (NULL != cmd->command) {
+       if (cmd->command)
                *command = strdup(gettext(cmd->command));
-       }
+       else
+               *command = NULL;
 
        SLOG(LOG_DEBUG, TAG_VCCMD, "[Get command][%p] Command(%s)", vc_command, *command);
 
-       return 0;
+       return VC_ERROR_NONE;
 }
 
 int vc_cmd_set_unfixed_command(vc_cmd_h vc_command, const char* command)
@@ -904,7 +955,7 @@ int vc_cmd_set_unfixed_command(vc_cmd_h vc_command, const char* command)
                return VC_ERROR_PERMISSION_DENIED;
        }
 
-       if (NULL == vc_command) {
+       if (NULL == vc_command || NULL == command) {
                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
                return VC_ERROR_INVALID_PARAMETER;
        }
@@ -912,18 +963,13 @@ int vc_cmd_set_unfixed_command(vc_cmd_h vc_command, const char* command)
        vc_cmd_s* cmd = NULL;
        cmd = (vc_cmd_s*)vc_command;
 
-       if (NULL != cmd->parameter) {
+       if (cmd->parameter)
                free(cmd->parameter);
-       }
-
        cmd->parameter = NULL;
+       cmd->parameter = strdup(command);
+       SLOG(LOG_DEBUG, TAG_VCCMD, "[Set unfixed command][%p] unfixed command(%s)", vc_command, cmd->parameter);
 
-       if (NULL != command) {
-               cmd->parameter = strdup(command);
-               SLOG(LOG_DEBUG, TAG_VCCMD, "[Set unfixed command][%p] unfixed command(%s)", vc_command, cmd->parameter);
-       }
-
-       return 0;
+       return VC_ERROR_NONE;
 }
 
 int vc_cmd_get_unfixed_command(vc_cmd_h vc_command, char** command)
@@ -931,9 +977,6 @@ int vc_cmd_get_unfixed_command(vc_cmd_h vc_command, char** command)
        if (0 != __vc_cmd_get_feature_enabled()) {
                return VC_ERROR_NOT_SUPPORTED;
        }
-       if (0 != __vc_cmd_check_privilege()) {
-               return VC_ERROR_PERMISSION_DENIED;
-       }
 
        if (NULL == vc_command || NULL == command) {
                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid handle ");
@@ -943,14 +986,17 @@ int vc_cmd_get_unfixed_command(vc_cmd_h vc_command, char** command)
        vc_cmd_s* cmd = NULL;
        cmd = (vc_cmd_s*)vc_command;
 
-       if (NULL != cmd->parameter) {
+       if (cmd->parameter)
                *command = strdup(gettext(cmd->parameter));
-               SLOG(LOG_DEBUG, TAG_VCCMD, "[Get unfixed command][%p] unfixed command(%s)", vc_command, *command);
-       }
+       else
+               *command = NULL;
+
+       SLOG(LOG_DEBUG, TAG_VCCMD, "[Get unfixed command][%p] unfixed command(%s)", vc_command, *command);
 
-       return 0;
+       return VC_ERROR_NONE;
 }
 
+//LCOV_EXCL_START
 int vc_cmd_set_fixed_command(vc_cmd_h vc_command, const char* fixed)
 {
        if (0 != __vc_cmd_get_feature_enabled()) {
@@ -970,15 +1016,13 @@ int vc_cmd_set_fixed_command(vc_cmd_h vc_command, const char* fixed)
        vc_cmd_s* cmd = NULL;
        cmd = (vc_cmd_s*)vc_command;
 
-       if (NULL != cmd->fixed) {
+       if (cmd->fixed)
                free(cmd->fixed);
-               cmd->fixed = NULL;
-       }
-
+       cmd->fixed = NULL;
        cmd->fixed = strdup(fixed);
 
        SLOG(LOG_DEBUG, TAG_VCCMD, "[Set parameter][%p] fixed command(%s)", vc_command, cmd->fixed);
-       return 0;
+       return VC_ERROR_NONE;
 }
 
 int vc_cmd_get_fixed_command(vc_cmd_h vc_command, char** fixed)
@@ -995,13 +1039,16 @@ int vc_cmd_get_fixed_command(vc_cmd_h vc_command, char** fixed)
        vc_cmd_s* cmd = NULL;
        cmd = (vc_cmd_s*)vc_command;
 
-       if (NULL != cmd->fixed) {
+       if (cmd->fixed)
                *fixed = strdup(gettext(cmd->fixed));
-               SLOG(LOG_DEBUG, TAG_VCCMD, "[Get fixed command][%p] fixed command(%s)", vc_command, *fixed);
-       }
+       else
+               *fixed = NULL;
+
+       SLOG(LOG_DEBUG, TAG_VCCMD, "[Get fixed command][%p] fixed command(%s)", vc_command, *fixed);
 
-       return 0;
+       return VC_ERROR_NONE;
 }
+//LCOV_EXCL_STOP
 
 int vc_cmd_set_invocation_name(vc_cmd_h vc_command, const char* invocation_name)
 {
@@ -1022,17 +1069,16 @@ int vc_cmd_set_invocation_name(vc_cmd_h vc_command, const char* invocation_name)
        vc_cmd_s* cmd = NULL;
        cmd = (vc_cmd_s*)vc_command;
 
-       if (NULL != cmd->invocation_name) {
+       if (cmd->invocation_name)
                free(cmd->invocation_name);
-               cmd->invocation_name = NULL;
-       }
-
+       cmd->invocation_name = NULL;
        cmd->invocation_name = strdup(invocation_name);
 
        SLOG(LOG_DEBUG, TAG_VCCMD, "[Set invocation name][%p] invocation_name(%s)", vc_command, cmd->invocation_name);
-       return 0;
+       return VC_ERROR_NONE;
 }
 
+//LCOV_EXCL_START
 int vc_cmd_get_invocation_name(vc_cmd_h vc_command, char** invocation_name)
 {
        if (0 != __vc_cmd_get_feature_enabled()) {
@@ -1047,13 +1093,15 @@ int vc_cmd_get_invocation_name(vc_cmd_h vc_command, char** invocation_name)
        vc_cmd_s* cmd = NULL;
        cmd = (vc_cmd_s*)vc_command;
 
-       if (NULL != cmd->invocation_name) {
+       if (cmd->invocation_name)
                *invocation_name = strdup(gettext(cmd->invocation_name));
-       }
+       else
+               *invocation_name = NULL;
 
        SLOG(LOG_DEBUG, TAG_VCCMD, "[Get invocation name][%p] invocation_name(%s)", vc_command, *invocation_name);
-       return 0;
+       return VC_ERROR_NONE;
 }
+//LCOV_EXCL_STOP
 
 int vc_cmd_set_type(vc_cmd_h vc_command, int type)
 {
@@ -1069,6 +1117,11 @@ int vc_cmd_set_type(vc_cmd_h vc_command, int type)
                return VC_ERROR_INVALID_PARAMETER;
        }
 
+       if (VC_COMMAND_TYPE_NONE >= type || VC_COMMAND_TYPE_EXCLUSIVE < type) {
+               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid type(%d)", type);
+               return VC_ERROR_INVALID_PARAMETER;
+       }
+
        vc_cmd_s* cmd = NULL;
        cmd = (vc_cmd_s*)vc_command;
 
@@ -1076,7 +1129,7 @@ int vc_cmd_set_type(vc_cmd_h vc_command, int type)
 
        SLOG(LOG_DEBUG, TAG_VCCMD, "[Set type][%p] type(%d)", vc_command, cmd->type);
 
-       return 0;
+       return VC_ERROR_NONE;
 }
 
 int vc_cmd_get_type(vc_cmd_h vc_command, int* type)
@@ -1100,23 +1153,25 @@ int vc_cmd_get_type(vc_cmd_h vc_command, int* type)
 
        SLOG(LOG_DEBUG, TAG_VCCMD, "[Get type][%p] type(%d)", vc_command, *type);
 
-       return 0;
+       return VC_ERROR_NONE;
 }
 
-int vc_cmd_set_format(vc_cmd_h vc_command, vc_cmd_format_e format)
+int vc_cmd_set_format(vc_cmd_h vc_command, int format)
 {
        if (0 != __vc_cmd_get_feature_enabled()) {
                return VC_ERROR_NOT_SUPPORTED;
        }
-       if (0 != __vc_cmd_check_privilege()) {
-               return VC_ERROR_PERMISSION_DENIED;
-       }
 
        if (NULL == vc_command) {
                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
                return VC_ERROR_INVALID_PARAMETER;
        }
 
+       if (VC_COMMAND_FORMAT_FIXED > format || VC_COMMAND_FORMAT_NONFIXED_AND_FIXED < format) {
+               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid format(%d)", format);
+               return VC_ERROR_INVALID_PARAMETER;
+       }
+
        vc_cmd_s* cmd = NULL;
        cmd = (vc_cmd_s*)vc_command;
 
@@ -1124,17 +1179,14 @@ int vc_cmd_set_format(vc_cmd_h vc_command, vc_cmd_format_e format)
 
        SLOG(LOG_DEBUG, TAG_VCCMD, "[Set format][%p] format(%d)", vc_command, format);
 
-       return 0;
+       return VC_ERROR_NONE;
 }
 
-int vc_cmd_get_format(vc_cmd_h vc_command, vc_cmd_format_e* format)
+int vc_cmd_get_format(vc_cmd_h vc_command, int* format)
 {
        if (0 != __vc_cmd_get_feature_enabled()) {
                return VC_ERROR_NOT_SUPPORTED;
        }
-       if (0 != __vc_cmd_check_privilege()) {
-               return VC_ERROR_PERMISSION_DENIED;
-       }
 
        if (NULL == vc_command || NULL == format) {
                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
@@ -1148,7 +1200,7 @@ int vc_cmd_get_format(vc_cmd_h vc_command, vc_cmd_format_e* format)
 
        SLOG(LOG_DEBUG, TAG_VCCMD, "[Get format][%p] format(%d)", vc_command, *format);
 
-       return 0;
+       return VC_ERROR_NONE;
 }
 
 int vc_cmd_set_pid(vc_cmd_h vc_command, int pid)
@@ -1165,6 +1217,11 @@ int vc_cmd_set_pid(vc_cmd_h vc_command, int pid)
                return VC_ERROR_INVALID_PARAMETER;
        }
 
+       if (0 > pid) {
+               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid pid (%d)", pid);
+               return VC_ERROR_INVALID_PARAMETER;
+       }
+
        vc_cmd_s* cmd = NULL;
        cmd = (vc_cmd_s*)vc_command;
 
@@ -1172,7 +1229,7 @@ int vc_cmd_set_pid(vc_cmd_h vc_command, int pid)
 
        SLOG(LOG_DEBUG, TAG_VCCMD, "[Set pid][%p] pid(%d)", vc_command, cmd->pid);
 
-       return 0;
+       return VC_ERROR_NONE;
 }
 
 int vc_cmd_get_pid(vc_cmd_h vc_command, int* pid)
@@ -1196,7 +1253,7 @@ int vc_cmd_get_pid(vc_cmd_h vc_command, int* pid)
 
        SLOG(LOG_DEBUG, TAG_VCCMD, "[Get pid][%p] pid(%d)", vc_command, *pid);
 
-       return 0;
+       return VC_ERROR_NONE;
 }
 
 int vc_cmd_set_domain(vc_cmd_h vc_command, int domain)
@@ -1220,7 +1277,7 @@ int vc_cmd_set_domain(vc_cmd_h vc_command, int domain)
 
        SLOG(LOG_DEBUG, TAG_VCCMD, "[Set domain] domain : %d", domain);
 
-       return 0;
+       return VC_ERROR_NONE;
 }
 
 int vc_cmd_get_domain(vc_cmd_h vc_command, int* domain)
@@ -1244,9 +1301,10 @@ int vc_cmd_get_domain(vc_cmd_h vc_command, int* domain)
 
        SLOG(LOG_DEBUG, TAG_VCCMD, "[Get domain] domain : %d", *domain);
 
-       return 0;
+       return VC_ERROR_NONE;
 }
 
+//LCOV_EXCL_START
 /**
 * @brief Sets key value of command.
 *
@@ -1262,7 +1320,7 @@ int vc_cmd_get_domain(vc_cmd_h vc_command, int* domain)
 */
 int vc_cmd_set_result_key(vc_cmd_h vc_command, int key, int modifier)
 {
-       SLOG(LOG_DEBUG, TAG_VCCMD, "===== Set result key");
+       SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Set result key");
 
        if (NULL == vc_command) {
                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
@@ -1277,10 +1335,9 @@ int vc_cmd_set_result_key(vc_cmd_h vc_command, int key, int modifier)
        cmd->key = key;
        cmd->modifier = modifier;
 
-       SLOG(LOG_DEBUG, TAG_VCCMD, "=====");
-       SLOG(LOG_DEBUG, TAG_VCCMD, " ");
+       SLOG(LOG_DEBUG, TAG_VCCMD, "@@@");
 
-       return 0;
+       return VC_ERROR_NONE;
 }
 
 /**
@@ -1298,7 +1355,7 @@ int vc_cmd_set_result_key(vc_cmd_h vc_command, int key, int modifier)
 */
 int vc_cmd_get_result_key(vc_cmd_h vc_command, int* key, int* modifier)
 {
-       SLOG(LOG_DEBUG, TAG_VCCMD, "===== Get result key");
+       SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Get result key");
 
        if (NULL == vc_command || NULL == key || NULL == modifier) {
                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
@@ -1311,10 +1368,9 @@ int vc_cmd_get_result_key(vc_cmd_h vc_command, int* key, int* modifier)
        *key = cmd->key;
        *modifier = cmd->modifier;
 
-       SLOG(LOG_DEBUG, TAG_VCCMD, "=====");
-       SLOG(LOG_DEBUG, TAG_VCCMD, " ");
+       SLOG(LOG_DEBUG, TAG_VCCMD, "@@@");
 
-       return 0;
+       return VC_ERROR_NONE;
 }
 
 int vc_cmd_print_list(vc_cmd_list_h vc_cmd_list)
@@ -1326,27 +1382,28 @@ int vc_cmd_print_list(vc_cmd_list_h vc_cmd_list)
        vc_cmd_list_s* list = NULL;
        list = (vc_cmd_list_s*)vc_cmd_list;
 
-       SLOG(LOG_DEBUG, TAG_VCCMD, "=== Command List ===");
+       SLOG(LOG_DEBUG, TAG_VCCMD, "@ Command List @");
        SLOG(LOG_DEBUG, TAG_VCCMD, "[List][%p]", list);
 
-       int count = g_slist_length(list->list);
-
-       int i;
-       vc_cmd_s *cmd = NULL;
-
-       for (i = 0; i < count ; i++) {
-               cmd = g_slist_nth_data(list->list, i);
-
-               if (NULL != cmd) {
-                       SLOG(LOG_DEBUG, TAG_VCCMD, "  [%d][%p] PID(%d) ID(%d) Type(%d) Format(%d) Command(%s) Param(%s) Appid(%s) Invocation(%s) Fixed(%s)",
-                        i, cmd, cmd->pid, cmd->index, cmd->type, cmd->format, cmd->command, cmd->parameter, cmd->appid, cmd->invocation_name, cmd->fixed);
+       int i = 0;
+       GSList *iter = NULL;
+       iter = g_slist_nth(list->list, 0);
+       while (NULL != iter) {
+               vc_cmd_s *cmd = NULL;
+               cmd = iter->data;
+               if (NULL == cmd) {
+                       SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] No command in list");
+                       return VC_ERROR_OPERATION_FAILED;
                }
+               SLOG(LOG_DEBUG, TAG_VCCMD, "  [%d][%p] PID(%d) ID(%d) Type(%d) Format(%d) Command(%s) Param(%s) Appid(%s) Invocation(%s) Fixed(%s)",
+                        i++, cmd, cmd->pid, cmd->index, cmd->type, cmd->format, cmd->command, cmd->parameter, cmd->appid, cmd->invocation_name, cmd->fixed);
+
+               iter = g_slist_next(iter);
        }
 
-       SLOG(LOG_DEBUG, TAG_VCCMD, "==================");
-       SLOG(LOG_DEBUG, TAG_VCCMD, " ");
+       SLOG(LOG_DEBUG, TAG_VCCMD, "@@@");
 
-       return 0;
+       return VC_ERROR_NONE;
 }
 
 int vc_cmd_get_nlu_json(vc_cmd_h vc_cmd, char** json)
@@ -1373,25 +1430,24 @@ int vc_cmd_get_nlu_json(vc_cmd_h vc_cmd, char** json)
                return VC_ERROR_OPERATION_FAILED;
        }
 
-       return 0;
+       return VC_ERROR_NONE;
 }
 
 static void __vc_cmd_regex_deinit(int num_regex)
 {
-       SLOG(LOG_DEBUG, TAG_VCCMD, "==== Start Deinitialize regex ====");
+       SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Start Deinitialize regex @@@");
        int i;
 
-       for (i = 0; i < num_regex; i++) {
+       for (i = 0; num_regex > i; i++) {
                regfree(&reg[i]);
        }
 
-       SLOG(LOG_DEBUG, TAG_VCCMD, "====");
-       SLOG(LOG_DEBUG, TAG_VCCMD, "");
+       SLOG(LOG_DEBUG, TAG_VCCMD, "@@@");
 }
 
 static int __vc_cmd_regex_init()
 {
-       SLOG(LOG_DEBUG, TAG_VCCMD, "==== Initialize regular expression ====");
+       SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Initialize regular expression @@@");
 
        int cflags = REG_EXTENDED | REG_ICASE;
        int ret;
@@ -1420,7 +1476,7 @@ static int __vc_cmd_regex_init()
        free(lang);
        lang = NULL;
 
-       SLOG(LOG_DEBUG, TAG_VCCMD, "==== lang type > %d ====", lang_type);
+       SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ lang type > %d @@@", lang_type);
 
        re_syntax_options = RE_SYNTAX_POSIX_EXTENDED;
 
@@ -1543,8 +1599,7 @@ static int __vc_cmd_regex_init()
                return VC_ERROR_OPERATION_FAILED;
        }
 
-       SLOG(LOG_DEBUG, TAG_VCCMD, "====");
-       SLOG(LOG_DEBUG, TAG_VCCMD, "");
+       SLOG(LOG_DEBUG, TAG_VCCMD, "@@@");
 
        return VC_ERROR_NONE;
 }
@@ -1582,7 +1637,7 @@ static void __vc_cmd_add_mday(struct tm *td, int mday)
        for (mon = td->tm_mon; mday >= max_day[mon % 12]; mon++) {
                mday -= max_day[mon % 12];
 
-               if (mon % 12 == 11) {
+               if (11 == mon % 12) {
                        year++;
 
                        if ((0 == year % 4 && 0 != year % 100) || 0 == year % 400) {
@@ -1632,7 +1687,7 @@ static void __vc_cmd_add_min(struct tm *td, int min)
 
 static void __copy_struct_tm(struct tm *des, struct tm *src)
 {
-       SLOG(LOG_DEBUG, TAG_VCCMD, "==== Start to copy struct tm ====");
+       SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Start to copy struct tm @@@");
 
        des->tm_sec     = src->tm_sec;
        des->tm_min     = src->tm_min;
@@ -1650,12 +1705,12 @@ static void __copy_struct_tm(struct tm *des, struct tm *src)
 
 static void __update_data_sidx(int idx)
 {
-       if (g_data_sidx < 0 || g_data_sidx > idx) g_data_sidx = idx;
+       if (0 > g_data_sidx || idx < g_data_sidx) g_data_sidx = idx;
 }
 
 static void __update_data_eidx(int idx)
 {
-       if (g_data_eidx < 0 || g_data_eidx < idx) g_data_eidx = idx;
+       if (0 > g_data_eidx || idx > g_data_eidx) g_data_eidx = idx;
 }
 
 static int __vc_cmd_tphrase_check(const char *str, struct tm *td, int *exist)
@@ -1685,7 +1740,7 @@ static int __vc_cmd_tphrase_check(const char *str, struct tm *td, int *exist)
 
                td->tm_min = 0;
                td->tm_sec = 0;
-               SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[idx].rm_so);
+               SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
 
                __update_data_sidx(pmatch[0].rm_so);
                __update_data_eidx(pmatch[0].rm_eo);
@@ -1708,21 +1763,24 @@ static int __vc_cmd_trelative_check(const char *str, struct tm *td, int *exist)
        int hour = -1;
        int min = -1;
 
-       char *tempstr = NULL;
-
        *exist = 0;
        ret = regexec(&reg[3], str, 1, pmatch, 0);
        if (0 == ret) {
                SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", pmatch[0].rm_eo - pmatch[0].rm_so, str+pmatch[0].rm_so);
                hour = min = -1;
 
-               if (sidx < 0 || sidx > pmatch[0].rm_so) sidx = pmatch[0].rm_so;
-               if (eidx < 0 || eidx < pmatch[0].rm_eo) eidx = pmatch[0].rm_eo;
+               sidx = pmatch[0].rm_so;
+               eidx = pmatch[0].rm_eo;
 
                ret = regexec(&reg[4], str, 2, pmatch, 0);
                if (0 == ret) {
                        len = pmatch[1].rm_eo - pmatch[1].rm_so;
-                       tempstr = strndup(str + pmatch[1].rm_so, len);
+
+                       if (0 > len) {
+                               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length");
+                               return VC_ERROR_OPERATION_FAILED;
+                       }
+                       char *tempstr = strndup(str + pmatch[1].rm_so, (size_t)len);
 
                        if (NULL == tempstr) {
                                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
@@ -1734,16 +1792,21 @@ static int __vc_cmd_trelative_check(const char *str, struct tm *td, int *exist)
                        free(tempstr);
                        tempstr = NULL;
 
-                       SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[1].rm_so);
+                       SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
 
-                       if (sidx < 0 || sidx > pmatch[0].rm_so) sidx = pmatch[0].rm_so;
-                       if (eidx < 0 || eidx < pmatch[0].rm_eo) eidx = pmatch[0].rm_eo;
+                       if (pmatch[0].rm_so < sidx) sidx = pmatch[0].rm_so;
+                       if (pmatch[0].rm_eo > eidx) eidx = pmatch[0].rm_eo;
                }
 
                ret = regexec(&reg[5], str, 2, pmatch, 0);
                if (0 == ret) {
                        len = pmatch[1].rm_eo - pmatch[1].rm_so;
-                       tempstr = strndup(str + pmatch[1].rm_so, len);
+
+                       if (0 > len) {
+                               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length");
+                               return VC_ERROR_OPERATION_FAILED;
+                       }
+                       char *tempstr = strndup(str + pmatch[1].rm_so, (size_t)len);
 
                        if (NULL == tempstr) {
                                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
@@ -1755,10 +1818,10 @@ static int __vc_cmd_trelative_check(const char *str, struct tm *td, int *exist)
                        free(tempstr);
                        tempstr = NULL;
 
-                       SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[1].rm_so);
+                       SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
 
-                       if (sidx < 0 || sidx > pmatch[0].rm_so) sidx = pmatch[0].rm_so;
-                       if (eidx < 0 || eidx < pmatch[0].rm_eo) eidx = pmatch[0].rm_eo;
+                       if (pmatch[0].rm_so < sidx) sidx = pmatch[0].rm_so;
+                       if (pmatch[0].rm_eo > eidx) eidx = pmatch[0].rm_eo;
                }
 
                if (hour < 0 && min < 0) {
@@ -1766,8 +1829,8 @@ static int __vc_cmd_trelative_check(const char *str, struct tm *td, int *exist)
                        return VC_ERROR_NONE;
                }
 
-               hour = hour < 0 ? 0 : hour;
-               min = min < 0 ? 0 : min;
+               hour = 0 > hour ? 0 : hour;
+               min = 0 > min ? 0 : min;
 
                min = min + (hour * 60);
 
@@ -1796,23 +1859,27 @@ static int __vc_cmd_tabsolute_check(const char *str, struct tm *td, int *exist)
        int min = -1;
        int sidx = -1;
        int eidx = -1;
-       char *tempstr = NULL;
 
        *exist = 0;
        ret = regexec(&reg[0], str, 5, pmatch, 0);
        if (0 == ret) {
-               for (idx = 1; idx < 5 && 0 >= pmatch[idx].rm_eo - pmatch[idx].rm_so; idx++);
+               for (idx = 1; 5 > idx && 0 >= pmatch[idx].rm_eo - pmatch[idx].rm_so; idx++);
 
                flag = idx & 1;
 
-               if (sidx < 0 || sidx > pmatch[0].rm_so) sidx = pmatch[0].rm_so;
-               if (eidx < 0 || eidx < pmatch[0].rm_eo) eidx = pmatch[0].rm_eo;
+               sidx = pmatch[0].rm_so;
+               eidx = pmatch[0].rm_eo;
        }
 
        ret = regexec(&reg[1], str, 2, pmatch, 0);
        if (0 == ret) {
                len = pmatch[1].rm_eo - pmatch[1].rm_so;
-               tempstr = strndup(str + pmatch[1].rm_so, len);
+
+               if (0 > len) {
+                       SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length");
+                       return VC_ERROR_OPERATION_FAILED;
+               }
+               char *tempstr = strndup(str + pmatch[1].rm_so, (size_t)len);
 
                if (NULL == tempstr) {
                        SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
@@ -1825,23 +1892,25 @@ static int __vc_cmd_tabsolute_check(const char *str, struct tm *td, int *exist)
                        hour = hour + 12 * flag;
 
                        if (12 == hour) hour = 0;
-                       else if(24 == hour) hour = 12;
+                       else if (24 == hour) hour = 12;
                }
 
                if (0 > hour || 24 <= hour || (0 == flag && 12 < hour)) {
-                       SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incomming sentence is weird");
+                       SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incoming sentence is weird");
+                       free(tempstr);
+                       tempstr = NULL;
                        return VC_ERROR_NONE;
                }
 
                free(tempstr);
                tempstr = NULL;
 
-               SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[1].rm_so);
+               SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
 
-               if (sidx < 0 || sidx > pmatch[0].rm_so) sidx = pmatch[0].rm_so;
-               if (eidx < 0 || eidx < pmatch[0].rm_eo) eidx = pmatch[0].rm_eo;
+               if (0 > sidx || pmatch[0].rm_so < sidx) sidx = pmatch[0].rm_so;
+               if (0 > eidx || pmatch[0].rm_eo > eidx) eidx = pmatch[0].rm_eo;
        } else if (0 < flag) {
-               SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incomming sentence is weird");
+               SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incoming sentence is weird");
                return VC_ERROR_NONE;
        }
 
@@ -1850,7 +1919,7 @@ static int __vc_cmd_tabsolute_check(const char *str, struct tm *td, int *exist)
                idx = 1;
                len = pmatch[idx].rm_eo - pmatch[idx].rm_so;
                if (0 < len) {
-                       tempstr = strndup(str + pmatch[idx].rm_so, len);
+                       char *tempstr = strndup(str + pmatch[idx].rm_so, (size_t)len);
 
                        if (NULL == tempstr) {
                                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
@@ -1860,7 +1929,9 @@ static int __vc_cmd_tabsolute_check(const char *str, struct tm *td, int *exist)
                        min = atoi(tempstr);
 
                        if (0 > min || 60 <= min) {
-                               SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incomming sentence is weird");
+                               SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incoming sentence is weird");
+                               free(tempstr);
+                               tempstr = NULL;
                                return VC_ERROR_NONE;
                        }
 
@@ -1873,22 +1944,22 @@ static int __vc_cmd_tabsolute_check(const char *str, struct tm *td, int *exist)
                        min = 30;
                }
 
-               SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", pmatch[idx].rm_eo - pmatch[idx].rm_so, str + pmatch[idx].rm_so);
-               if (sidx < 0 || sidx > pmatch[0].rm_so) sidx = pmatch[0].rm_so;
-               if (eidx < 0 || eidx < pmatch[0].rm_eo) eidx = pmatch[0].rm_eo;
+               SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", pmatch[0].rm_eo - pmatch[0].rm_so, str + pmatch[0].rm_so);
+               if (0 > sidx || pmatch[0].rm_so < sidx) sidx = pmatch[0].rm_so;
+               if (0 > eidx || pmatch[0].rm_eo > eidx) eidx = pmatch[0].rm_eo;
        }
 
-       if (hour < 0 && min < 0) {
+       if (0 > hour && 0 > min) {
                SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] There is no matched string");
                return VC_ERROR_NONE;
        }
 
-       if (min >= 0 && hour >= 0) {
+       if (0 <= min && 0 <= hour) {
                if (hour < td->tm_hour || (hour == td->tm_hour && min <= td->tm_min)) __vc_cmd_add_mday(td, 1);
 
                td->tm_hour = hour;
                td->tm_min = min;
-       } else if (min >= 0) {
+       } else if (0 <= min) {
                char *lang = NULL;
                vc_config_mgr_get_default_language(&lang);
                if (NULL == lang) {
@@ -1897,7 +1968,7 @@ static int __vc_cmd_tabsolute_check(const char *str, struct tm *td, int *exist)
                }
 
                if (!strcmp("en_US", lang)) {
-                       SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incomming sentence is weird");
+                       SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incoming sentence is weird");
                        free(lang);
                        lang = NULL;
                        return VC_ERROR_NONE;
@@ -1926,7 +1997,7 @@ static int __vc_cmd_tabsolute_check(const char *str, struct tm *td, int *exist)
 
 static int __vc_cmd_dphrase_check(const char *str, struct tm *td, int *exist)
 {
-       regmatch_t pmatch[9];
+       regmatch_t pmatch[10];
        int ret;
        int len;
        int idx;
@@ -1934,17 +2005,17 @@ static int __vc_cmd_dphrase_check(const char *str, struct tm *td, int *exist)
        *exist = 0;
        ret = regexec(&reg[10], str, 5, pmatch, 0);
        if (0 == ret) {
-               for (idx = 1; idx < 5 && 0 >= pmatch[idx].rm_eo - pmatch[idx].rm_so; idx++);
+               for (idx = 1; 5 > idx && 0 >= pmatch[idx].rm_eo - pmatch[idx].rm_so; idx++);
 
                len = pmatch[idx].rm_eo - pmatch[idx].rm_so;
 
-               td->tm_year = td_now->tm_year;
-               td->tm_mon = td_now->tm_mon;
-               td->tm_mday = td_now->tm_mday;
+               td->tm_year = td_now.tm_year;
+               td->tm_mon = td_now.tm_mon;
+               td->tm_mday = td_now.tm_mday;
 
                __vc_cmd_add_mday(td, idx - 1);
 
-               SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[idx].rm_so);
+               SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
 
                __update_data_sidx(pmatch[0].rm_so);
                __update_data_eidx(pmatch[0].rm_eo);
@@ -1953,21 +2024,21 @@ static int __vc_cmd_dphrase_check(const char *str, struct tm *td, int *exist)
                return VC_ERROR_NONE;
        }
 
-       ret = regexec(&reg[11], str, 9, pmatch, 0);
+       ret = regexec(&reg[11], str, 10, pmatch, 0);
        if (0 == ret) {
-               for (idx = 1; idx < 9; idx++) {
+               for (idx = 1; 10 > idx; idx++) {
                        len = pmatch[idx].rm_eo - pmatch[idx].rm_so;
 
                        if (0 < len) break;
                }
 
-               td->tm_year = td_now->tm_year;
-               td->tm_mon = td_now->tm_mon;
-               td->tm_mday = td_now->tm_mday;
+               td->tm_year = td_now.tm_year;
+               td->tm_mon = td_now.tm_mon;
+               td->tm_mday = td_now.tm_mday;
 
                __vc_cmd_add_mday(td, idx + 1);
 
-               SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[idx].rm_so);
+               SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
 
                __update_data_sidx(pmatch[0].rm_so);
                __update_data_eidx(pmatch[0].rm_eo);
@@ -1990,16 +2061,21 @@ static int __vc_cmd_dabsolute_check(const char *str, struct tm *td, int *exist)
        int eidx = -1;
        int y_flag = 0;
        int m_flag = 0;
-       int year = -1;
-       int mon = -1;
-       int day = -1;
+       int year = 0;
+       int mon = 0;
+       int day = 0;
        char *tempstr = NULL;
 
        *exist = 0;
        ret = regexec(&reg[9], str, 2, pmatch, 0);
        if (0 == ret) {
                len = pmatch[1].rm_eo - pmatch[1].rm_so;
-               tempstr = strndup(str + pmatch[1].rm_so, len);
+
+               if (0 > len) {
+                       SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length");
+                       return VC_ERROR_OPERATION_FAILED;
+               }
+               tempstr = strndup(str + pmatch[1].rm_so, (size_t)len);
 
                if (NULL == tempstr) {
                        SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
@@ -2011,18 +2087,18 @@ static int __vc_cmd_dabsolute_check(const char *str, struct tm *td, int *exist)
                free(tempstr);
                tempstr = NULL;
 
-               SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[1].rm_so);
+               SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
 
-               if (sidx < 0 || sidx > pmatch[0].rm_so) sidx = pmatch[0].rm_so;
-               if (eidx < 0 || eidx < pmatch[0].rm_eo) eidx = pmatch[0].rm_eo;
+               sidx = pmatch[0].rm_so;
+               eidx = pmatch[0].rm_eo;
        } else {
-               SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incomming sentence is weird");
+               SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incoming sentence is weird");
                return VC_ERROR_NONE;
        }
 
        ret = regexec(&reg[8], str, 13, pmatch, 0);
        if (0 == ret) {
-               for (idx = 1; idx < 13; idx++) {
+               for (idx = 1; 13 > idx; idx++) {
                        len = pmatch[idx].rm_eo - pmatch[idx].rm_so;
 
                        if (0 < len) {
@@ -2033,10 +2109,10 @@ static int __vc_cmd_dabsolute_check(const char *str, struct tm *td, int *exist)
 
                m_flag = 1;
 
-               SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[idx].rm_so);
+               SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
 
-               if (sidx < 0 || sidx > pmatch[0].rm_so) sidx = pmatch[0].rm_so;
-               if (eidx < 0 || eidx < pmatch[0].rm_eo) eidx = pmatch[0].rm_eo;
+               if (0 > sidx || pmatch[0].rm_so < sidx) sidx = pmatch[0].rm_so;
+               if (0 > eidx || pmatch[0].rm_eo > eidx) eidx = pmatch[0].rm_eo;
        } else {
                char *lang = NULL;
                vc_config_mgr_get_default_language(&lang);
@@ -2046,7 +2122,7 @@ static int __vc_cmd_dabsolute_check(const char *str, struct tm *td, int *exist)
                }
 
                if (!strcmp("en_US", lang)) {
-                       SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incomming sentence is weird");
+                       SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incoming sentence is weird");
                        free(lang);
                        lang = NULL;
                        return VC_ERROR_NONE;
@@ -2063,7 +2139,12 @@ static int __vc_cmd_dabsolute_check(const char *str, struct tm *td, int *exist)
                if (!m_flag) return -1;
 
                len = pmatch[2].rm_eo - pmatch[2].rm_so;
-               tempstr = strndup(str + pmatch[2].rm_so, len);
+
+               if (0 > len) {
+                       SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length");
+                       return VC_ERROR_OPERATION_FAILED;
+               }
+               tempstr = strndup(str + pmatch[2].rm_so, (size_t)len);
 
                if (NULL == tempstr) {
                        SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
@@ -2071,26 +2152,26 @@ static int __vc_cmd_dabsolute_check(const char *str, struct tm *td, int *exist)
                }
 
                year = atoi(tempstr);
-               year = year > 1900 ? year - 1900 : year + 100;
+               year = 1900 < year ? year - 1900 : year + 100;
 
                free(tempstr);
                tempstr = NULL;
 
                y_flag = 1;
-               SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[2].rm_so);
+               SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
 
-               if (sidx < 0 || sidx > pmatch[0].rm_so) sidx = pmatch[0].rm_so;
-               if (eidx < 0 || eidx < pmatch[0].rm_eo) eidx = pmatch[0].rm_eo;
+               if (0 > sidx || pmatch[0].rm_so < sidx) sidx = pmatch[0].rm_so;
+               if (0 > eidx || pmatch[0].rm_eo > eidx) eidx = pmatch[0].rm_eo;
        } else {
                year = td->tm_year;
        }
 
-       if (g_time_flag < 0) {
+       if (0 > g_time_flag) {
                td->tm_hour = 0;
                td->tm_min = 0;
                td->tm_sec = 0;
-       } else if (g_time_flag == 2) {
-               SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incomming sentence is weird");
+       } else if (2 == g_time_flag) {
+               SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incoming sentence is weird");
                return VC_ERROR_NONE;
        }
 
@@ -2098,7 +2179,7 @@ static int __vc_cmd_dabsolute_check(const char *str, struct tm *td, int *exist)
        if ((0 == (year + 1900) % 4 && 0 != (year + 1900) % 100) || 0 == (year + 1900) % 400) max_day[1] = 29;
 
        if (max_day[mon] < day || 1 > day) {
-               SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incomming sentence is weird");
+               SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incoming sentence is weird");
                return VC_ERROR_NONE;
        }
 
@@ -2108,10 +2189,10 @@ static int __vc_cmd_dabsolute_check(const char *str, struct tm *td, int *exist)
 
        if (!y_flag) {
                if (!m_flag) {
-                       if (day < td_now->tm_mday) __vc_cmd_add_mon(td, 1);
+                       if (day < td_now.tm_mday) __vc_cmd_add_mon(td, 1);
                } else {
-                       if (mon < td_now->tm_mon) __vc_cmd_add_year(td, 1);
-                       else if (mon == td_now->tm_mon && day < td_now->tm_mday) __vc_cmd_add_year(td, 1);
+                       if (mon < td_now.tm_mon) __vc_cmd_add_year(td, 1);
+                       else if (mon == td_now.tm_mon && day < td_now.tm_mday) __vc_cmd_add_year(td, 1);
                }
        }
 
@@ -2124,7 +2205,7 @@ static int __vc_cmd_dabsolute_check(const char *str, struct tm *td, int *exist)
 
 static int __vc_cmd_time_check(const char *str, struct tm *td)
 {
-       SLOG(LOG_DEBUG, TAG_VCCMD, "==== Check time value in string \"%s\"", str);
+       SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Check time value in string \"%s\"", str);
 
        vc_error_e ret;
        int exist = 0;
@@ -2133,10 +2214,10 @@ static int __vc_cmd_time_check(const char *str, struct tm *td)
        if (1 == exist) {
                g_time_flag = 1;
 
-               SLOG(LOG_DEBUG, TAG_VCCMD, "==== Time value is exist");
+               SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Time value is exist");
                return ret;
        } else if (VC_ERROR_NONE != ret) {
-               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occured > (%d)", ret);
+               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occurred > (%d)", ret);
                return ret;
        }
 
@@ -2144,10 +2225,10 @@ static int __vc_cmd_time_check(const char *str, struct tm *td)
        if (1 == exist) {
                g_time_flag = 2;
 
-               SLOG(LOG_DEBUG, TAG_VCCMD, "==== Time value is exist");
+               SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Time value is exist");
                return ret;
        } else if (VC_ERROR_NONE != ret) {
-               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occured > (%d)", ret);
+               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occurred > (%d)", ret);
                return ret;
        }
 
@@ -2155,20 +2236,20 @@ static int __vc_cmd_time_check(const char *str, struct tm *td)
        if (1 == exist) {
                g_time_flag = 3;
 
-               SLOG(LOG_DEBUG, TAG_VCCMD, "==== Time value is exist");
+               SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Time value is exist");
                return ret;
        } else if (VC_ERROR_NONE != ret) {
-               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occured > (%d)", ret);
+               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occurred > (%d)", ret);
                return ret;
        }
 
-       SLOG(LOG_DEBUG, TAG_VCCMD, "==== There is no time value");
+       SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ There is no time value");
        return VC_ERROR_NONE;
 }
 
 static int __vc_cmd_date_check(const char *str, struct tm *td)
 {
-       SLOG(LOG_DEBUG, TAG_VCCMD, "==== Check date value in string \"%s\"", str);
+       SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Check date value in string \"%s\"", str);
 
        vc_error_e ret;
        int exist = 0;
@@ -2177,10 +2258,10 @@ static int __vc_cmd_date_check(const char *str, struct tm *td)
        if (1 == exist) {
                g_date_flag = 1;
 
-               SLOG(LOG_DEBUG, TAG_VCCMD, "==== Date value is exist");
+               SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Date value is exist");
                return ret;
        } else if (VC_ERROR_NONE != ret) {
-               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occured > (%d)", ret);
+               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occurred > (%d)", ret);
                return ret;
        }
 
@@ -2188,31 +2269,31 @@ static int __vc_cmd_date_check(const char *str, struct tm *td)
        if (1 == exist) {
                g_date_flag = 1;
 
-               SLOG(LOG_DEBUG, TAG_VCCMD, "==== Date value is exist");
+               SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Date value is exist");
                return ret;
        } else if (VC_ERROR_NONE != ret) {
-               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occured > (%d)", ret);
+               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occurred > (%d)", ret);
                return ret;
        }
 
-       SLOG(LOG_DEBUG, TAG_VCCMD, "==== There is no date value");
+       SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ There is no date value");
        return VC_ERROR_NONE;
 }
 
 int vc_cmd_get_datetime(const char *text, time_t *result, char **remain)
 {
-       SLOG(LOG_DEBUG, TAG_VCCMD, "==== Get timestamp data");
+       SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Get timestamp data");
 
        struct tm td;
        const char *day_name[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
        vc_error_e ret;
 
-       *result = -1;
        if (NULL == text || NULL == result || NULL == remain) {
                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter");
                return VC_ERROR_INVALID_PARAMETER;
        }
 
+       *result = -1;
        ret = __vc_cmd_regex_init();
        if (VC_ERROR_NONE != ret) {
                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] initialize regex failed");
@@ -2222,10 +2303,10 @@ int vc_cmd_get_datetime(const char *text, time_t *result, char **remain)
        g_data_sidx = g_data_eidx = -1;
 
        t_now = time(NULL);
-       td_now = localtime(&t_now);
+       localtime_r(&t_now, &td_now);
        SLOG(LOG_DEBUG, TAG_VCCMD, "Current timestamp = %d", (int)t_now);
 
-       __copy_struct_tm(&td, td_now);
+       __copy_struct_tm(&td, &td_now);
        SLOG(LOG_DEBUG, TAG_VCCMD, "%d-%d-%d (%s),  %d:%d:%d",
                td.tm_year + 1900, td.tm_mon + 1, td.tm_mday, day_name[td.tm_wday], td.tm_hour, td.tm_min, td.tm_sec);
 
@@ -2233,13 +2314,13 @@ int vc_cmd_get_datetime(const char *text, time_t *result, char **remain)
 
        ret = __vc_cmd_time_check(text, &td);
        if (VC_ERROR_NONE != ret) {
-               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occured in the check > (%d)", ret);
+               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occurred in the check > (%d)", ret);
                return ret;
        }
 
        ret = __vc_cmd_date_check(text, &td);
        if (VC_ERROR_NONE != ret) {
-               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occured in the check > (%d)", ret);
+               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occurred in the check > (%d)", ret);
                return ret;
        }
 
@@ -2248,9 +2329,9 @@ int vc_cmd_get_datetime(const char *text, time_t *result, char **remain)
        if (g_time_flag > 0 || g_date_flag > 0) {
                *result = mktime(&td);
 
-               SLOG(LOG_DEBUG, TAG_VCCMD, "Timestamp in the text = %d", *result);
+               SLOG(LOG_DEBUG, TAG_VCCMD, "Timestamp in the text = %ld", *result);
                SLOG(LOG_DEBUG, TAG_VCCMD, "%d-%d-%d (%s),  %d:%d:%d",
-                       td.tm_year + 1900, td.tm_mon + 1, td.tm_mday, day_name[td.tm_wday], td.tm_hour, td.tm_min, td.tm_sec, td.tm_yday);
+                       td.tm_year + 1900, td.tm_mon + 1, td.tm_mday, day_name[td.tm_wday], td.tm_hour, td.tm_min, td.tm_sec);
 
                *remain = (char *)calloc(sizeof(char), (strlen(text) + 1 - g_data_eidx + g_data_sidx));
 
@@ -2265,8 +2346,8 @@ int vc_cmd_get_datetime(const char *text, time_t *result, char **remain)
                SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] There is no data in the text");
        }
 
-       SLOG(LOG_DEBUG, TAG_VCCMD, "====");
-       SLOG(LOG_DEBUG, TAG_VCCMD, "");
+       SLOG(LOG_DEBUG, TAG_VCCMD, "@@@");
 
        return VC_ERROR_NONE;
-}
\ No newline at end of file
+}
+//LCOV_EXCL_STOP