From 5e2855aa3dbbd6fc130f92d5a9d8e45746fc61c0 Mon Sep 17 00:00:00 2001 From: Semun Lee Date: Wed, 8 Jan 2020 14:17:04 +0900 Subject: [PATCH] Fix build error in emulator for gcc 9 Change-Id: I5526b46843edb2651e3462ce5c75ed01cf7be7a3 Signed-off-by: Semun Lee --- common/src/libraries/bt-util.c | 13 ++++++------- emulator/src/libraries/bt-util.c | 11 +++++++---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/common/src/libraries/bt-util.c b/common/src/libraries/bt-util.c index 9c11c11..61430e8 100644 --- a/common/src/libraries/bt-util.c +++ b/common/src/libraries/bt-util.c @@ -417,6 +417,9 @@ void _bt_util_convert_time_to_string(unsigned int remain_time, FN_START; int minute; int second; + int ret; + char min_part[BT_BUFFER_LEN] = { 0, }; + char sec_part[BT_BUFFER_LEN] = { 0, }; ret_if(remain_time > BT_TIMEOUT_MAX); @@ -430,8 +433,6 @@ void _bt_util_convert_time_to_string(unsigned int remain_time, snprintf(text_display, size_display, "%d:%02d", minute, second); if (size_read == BT_BUFFER_LEN && text_read != NULL) { - char min_part[BT_BUFFER_LEN] = { 0, }; - char sec_part[BT_BUFFER_LEN] = { 0, }; /*Set minute Text*/ if (minute == 1) @@ -449,11 +450,9 @@ void _bt_util_convert_time_to_string(unsigned int remain_time, snprintf(sec_part, BT_BUFFER_LEN, "%d %s", second, BT_STR_SECONDS); - int ret = snprintf(text_read, size_read, "%s %s", min_part, sec_part); - if (ret < 0) { - BT_ERR("snprintf error"); - return; - } + ret = snprintf(text_read, size_read, "%s %s", min_part, sec_part); + if (ret < 0 || ret >= size_read) + BT_ERR("snprintf error: truncated or error. ret(%d)", ret); } FN_END; } diff --git a/emulator/src/libraries/bt-util.c b/emulator/src/libraries/bt-util.c index 0acdf73..9ae630e 100644 --- a/emulator/src/libraries/bt-util.c +++ b/emulator/src/libraries/bt-util.c @@ -26,7 +26,6 @@ #include #include #include -# #include "bt-main-ug.h" #include "bt-util.h" #include "bt-debug.h" @@ -373,6 +372,9 @@ void _bt_util_convert_time_to_string(unsigned int remain_time, FN_START; int minute; int second; + int ret; + char min_part[BT_BUFFER_LEN] = { 0, }; + char sec_part[BT_BUFFER_LEN] = { 0, }; ret_if(remain_time > BT_TIMEOUT_MAX); @@ -386,8 +388,6 @@ void _bt_util_convert_time_to_string(unsigned int remain_time, snprintf(text_display, size_display, "%d:%02d", minute, second); if (size_read == BT_BUFFER_LEN && text_read != NULL) { - char min_part[BT_BUFFER_LEN] = { 0, }; - char sec_part[BT_BUFFER_LEN] = { 0, }; /*Set minute Text*/ if (minute == 1) @@ -405,7 +405,10 @@ void _bt_util_convert_time_to_string(unsigned int remain_time, snprintf(sec_part, BT_BUFFER_LEN, "%d %s", second, BT_STR_SECONDS); - snprintf(text_read, size_read, "%s %s", min_part, sec_part); + ret = snprintf(text_read, size_read, "%s %s", min_part, sec_part); + if (ret < 0 || ret >= size_read) + BT_ERR("snprintf error: truncated or error. ret(%d)", ret); + } FN_END; } -- 2.7.4