From: mk5004.lee Date: Tue, 7 Jul 2020 04:45:52 +0000 (+0900) Subject: Fix build warning X-Git-Tag: submit/tizen/20200710.064112~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cbe7ad85c594bb4cf8d0286e8a3a4a090c552b60;p=platform%2Fcore%2Fapi%2Fnotification.git Fix build warning warning: '__builtin___strncat_chk' output may be truncated copying between 0 and 4095 bytes from a string of length 4095 [-Wstringop-truncation] Change-Id: Iaaff9cfa80149ad6d428443c9d2257281c5e7042 Signed-off-by: mk5004.lee --- diff --git a/notification/src/notification.c b/notification/src/notification.c index 870e8703..6a841500 100644 --- a/notification/src/notification.c +++ b/notification/src/notification.c @@ -440,7 +440,7 @@ EXPORT_API int notification_get_text(notification_h noti, char **text) { char result_str[NOTI_TEXT_RESULT_LEN] = { 0, }; - char buf_str[NOTI_TEXT_RESULT_LEN] = { 0, }; + char buf_str[32] = { 0, }; char buf_key[32] = { 0, }; char *ret_val = NULL; char *get_str = NULL; @@ -448,8 +448,6 @@ EXPORT_API int notification_get_text(notification_h noti, char *translated_str = NULL; bundle *b = NULL; int num_args = 0; - int src_len = 0; - int max_len = 0; int ret_variable_int = 0; double ret_variable_double = 0.0; notification_text_type_e text_type = NOTIFICATION_TEXT_TYPE_NONE; @@ -546,12 +544,9 @@ EXPORT_API int notification_get_text(notification_h noti, noti->group_id, noti->priv_id, &ret_variable_int); - snprintf(buf_str, sizeof(buf_str), - "%d ", ret_variable_int); + snprintf(buf_str, sizeof(buf_str), "%d ", ret_variable_int); + strncat(result_str, buf_str, sizeof(result_str) - strlen(result_str) - 1); - src_len = strlen(result_str); - max_len = sizeof(result_str) - src_len - 1; - strncat(result_str, buf_str, max_len); num_args++; } } @@ -602,12 +597,8 @@ EXPORT_API int notification_get_text(notification_h noti, ret_variable_int = atoi(ret_val); } - snprintf(buf_str, sizeof(buf_str), "%d", - ret_variable_int); - - src_len = strlen(result_str); - max_len = sizeof(result_str) - src_len - 1; - strncat(result_str, buf_str, max_len); + snprintf(buf_str, sizeof(buf_str), "%d", ret_variable_int); + strncat(result_str, buf_str, sizeof(result_str) - strlen(result_str) - 1); temp_str++; num_args++; @@ -634,14 +625,8 @@ EXPORT_API int notification_get_text(notification_h noti, translated_str = NULL; } - if (translated_str != NULL) { - strncpy(buf_str, translated_str, - sizeof(buf_str) - 1); - - src_len = strlen(result_str); - max_len = sizeof(result_str) - src_len - 1; - strncat(result_str, buf_str, max_len); - } + if (translated_str != NULL) + strncat(result_str, translated_str, sizeof(result_str) - strlen(result_str) - 1); temp_str++; num_args++; @@ -654,12 +639,8 @@ EXPORT_API int notification_get_text(notification_h noti, if (ret_val != NULL) ret_variable_double = atof(ret_val); - snprintf(buf_str, sizeof(buf_str), "%.2f", - ret_variable_double); - - src_len = strlen(result_str); - max_len = sizeof(result_str) - src_len - 1; - strncat(result_str, buf_str, max_len); + snprintf(buf_str, sizeof(buf_str), "%.2f", ret_variable_double); + strncat(result_str, buf_str, sizeof(result_str) - strlen(result_str) - 1); temp_str++; num_args++; @@ -695,12 +676,8 @@ EXPORT_API int notification_get_text(notification_h noti, ret_variable_int = atoi(ret_val); } - snprintf(buf_str, sizeof(buf_str), "%d", - ret_variable_int); - - src_len = strlen(result_str); - max_len = sizeof(result_str) - src_len - 1; - strncat(result_str, buf_str, max_len); + snprintf(buf_str, sizeof(buf_str), "%d", ret_variable_int); + strncat(result_str, buf_str, sizeof(result_str) - strlen(result_str) - 1); temp_str += 3; } else if (*(temp_str + 3) == 's') { @@ -710,13 +687,8 @@ EXPORT_API int notification_get_text(notification_h noti, num_args + *(temp_str + 1) - 49); bundle_get_str(b, buf_key, &ret_val); - - snprintf(buf_str, sizeof(buf_str), "%s", - ret_val); - - src_len = strlen(result_str); - max_len = sizeof(result_str) - src_len - 1; - strncat(result_str, buf_str, max_len); + if (ret_val != NULL) + strncat(result_str, ret_val, sizeof(result_str) - strlen(result_str) - 1); temp_str += 3; } else if (*(temp_str + 3) == 'f') { @@ -729,12 +701,8 @@ EXPORT_API int notification_get_text(notification_h noti, if (ret_val != NULL) ret_variable_double = atof(ret_val); - snprintf(buf_str, sizeof(buf_str), - "%.2f", ret_variable_double); - - src_len = strlen(result_str); - max_len = sizeof(result_str) - src_len - 1; - strncat(result_str, buf_str, max_len); + snprintf(buf_str, sizeof(buf_str), "%.2f", ret_variable_double); + strncat(result_str, buf_str, sizeof(result_str) - strlen(result_str) - 1); temp_str += 3; } else { @@ -780,12 +748,8 @@ EXPORT_API int notification_get_text(notification_h noti, noti->group_id, noti->priv_id, &ret_variable_int); - snprintf(buf_str, sizeof(buf_str), " %d", - ret_variable_int); - - src_len = strlen(result_str); - max_len = sizeof(result_str) - src_len - 1; - strncat(result_str, buf_str, max_len); + snprintf(buf_str, sizeof(buf_str), " %d", ret_variable_int); + strncat(result_str, buf_str, sizeof(result_str) - strlen(result_str) - 1); num_args++; }