From 2fa3aefcbaf8bb49a433f2b8b840aed4c430b2a8 Mon Sep 17 00:00:00 2001 From: "stom.hwang" Date: Thu, 29 Sep 2016 13:30:13 +0900 Subject: [PATCH] Fix svace issue & typo Change-Id: I6627dd2bd5dbbfefba55a4eb6656097e995a5560 Signed-off-by: stom.hwang --- common/vc_command.c | 124 ++++++++++++++++++++++++------------------------ common/vc_json_parser.c | 9 ++-- 2 files changed, 67 insertions(+), 66 deletions(-) mode change 100644 => 100755 common/vc_json_parser.c diff --git a/common/vc_command.c b/common/vc_command.c index 61053a9..3252b90 100755 --- a/common/vc_command.c +++ b/common/vc_command.c @@ -41,7 +41,7 @@ static cynara *p_cynara = 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; @@ -1381,7 +1381,7 @@ static void __vc_cmd_regex_deinit(int num_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(®[i]); } @@ -1582,7 +1582,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) { @@ -1650,12 +1650,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 +1685,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); @@ -1716,8 +1716,8 @@ static int __vc_cmd_trelative_check(const char *str, struct tm *td, int *exist) 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(®[4], str, 2, pmatch, 0); if (0 == ret) { @@ -1734,10 +1734,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; } ret = regexec(®[5], str, 2, pmatch, 0); @@ -1755,10 +1755,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 +1766,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); @@ -1801,12 +1801,12 @@ static int __vc_cmd_tabsolute_check(const char *str, struct tm *td, int *exist) *exist = 0; ret = regexec(®[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(®[1], str, 2, pmatch, 0); @@ -1836,10 +1836,10 @@ static int __vc_cmd_tabsolute_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 (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"); return VC_ERROR_NONE; @@ -1873,22 +1873,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) { @@ -1926,7 +1926,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 +1934,17 @@ static int __vc_cmd_dphrase_check(const char *str, struct tm *td, int *exist) *exist = 0; ret = regexec(®[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 +1953,21 @@ static int __vc_cmd_dphrase_check(const char *str, struct tm *td, int *exist) return VC_ERROR_NONE; } - ret = regexec(®[11], str, 9, pmatch, 0); + ret = regexec(®[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,9 +1990,9 @@ 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; @@ -2011,10 +2011,10 @@ 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"); return VC_ERROR_NONE; @@ -2022,7 +2022,7 @@ static int __vc_cmd_dabsolute_check(const char *str, struct tm *td, int *exist) ret = regexec(®[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 +2033,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); @@ -2071,25 +2071,25 @@ 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) { + } else if (2 == g_time_flag) { SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incomming sentence is weird"); return VC_ERROR_NONE; } @@ -2108,10 +2108,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); } } @@ -2207,12 +2207,12 @@ int vc_cmd_get_datetime(const char *text, time_t *result, char **remain) 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 +2222,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); diff --git a/common/vc_json_parser.c b/common/vc_json_parser.c old mode 100644 new mode 100755 index 6d50d51..4c99231 --- a/common/vc_json_parser.c +++ b/common/vc_json_parser.c @@ -363,16 +363,17 @@ static int __vc_json_set_commands(JsonObject *root_obj, int type, char* invocati cmd = NULL; } + free(temp_type); + free(prev_appid); + temp_type = NULL; + prev_appid = NULL; + ret = vc_db_commit_transaction(); if (0 != ret) { SLOG(LOG_ERROR, vc_json_tag(), "[ERROR] Fail to commit transaction for db"); return ret; } - free(temp_type); - free(prev_appid); - temp_type = NULL; - prev_appid = NULL; return VC_ERROR_NONE; } -- 2.7.4