From 4722697645cf033de8cf4f34e4214af750746365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9sz=C3=A1ros=20Mih=C3=A1ly?= Date: Tue, 3 Mar 2020 15:11:29 +0100 Subject: [PATCH] Fix compiler warnings * Changed type from int to size_t to avoid warning warning: comparison between signed and unsigned integer expressions * Fixed string truncation warning --- ChangeLog | 2 ++ src/apps/common/ns_turn_utils.c | 13 +++++++++---- src/client/ns_turn_msg.c | 4 ++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index e5e4239..a5a43eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -49,6 +49,8 @@ Version 4.5.1.2 'dan Eider': - merge PR #475 Update README.docker (by raksonibs) - merge PR #471 Fix a memory leak when an SHATYPE isn't supported (by bobsayshilol) - merge PR #488 Fix typos about INSTALL filenames (by raccoonback) + - fix compiler warning comparison between signed and unsigned integer expressions + - fix compiler warning string truncation 02/03/2019 Oleg Moskalenko Mihály Mészáros Version 4.5.1.1 'dan Eider': diff --git a/src/apps/common/ns_turn_utils.c b/src/apps/common/ns_turn_utils.c index a4b46a2..04b180c 100644 --- a/src/apps/common/ns_turn_utils.c +++ b/src/apps/common/ns_turn_utils.c @@ -393,7 +393,8 @@ static void set_rtpfile(void) else snprintf(logtail, FILE_STR_LEN, "turn_%d_", (int)getpid()); - snprintf(logbase, FILE_STR_LEN, "/var/log/turnserver/%s", logtail); + if (snprintf(logbase, FILE_STR_LEN, "/var/log/turnserver/%s", logtail)<0) + TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "String truncation occured.\n"); set_log_file_name(logbase, logf); @@ -401,20 +402,24 @@ static void set_rtpfile(void) if(_rtpfile) TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "log file opened: %s\n", logf); else { - snprintf(logbase, FILE_STR_LEN, "/var/log/%s", logtail); + if (snprintf(logbase, FILE_STR_LEN, "/var/log/%s", logtail)<0) + TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "String truncation occured.\n"); set_log_file_name(logbase, logf); _rtpfile = fopen(logf, "a"); if(_rtpfile) TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "log file opened: %s\n", logf); else { - snprintf(logbase, FILE_STR_LEN, "/var/tmp/%s", logtail); + if (snprintf(logbase, FILE_STR_LEN, "/var/tmp/%s", logtail)<0) + TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "String truncation occured.\n"); + set_log_file_name(logbase, logf); _rtpfile = fopen(logf, "a"); if(_rtpfile) TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "log file opened: %s\n", logf); else { - snprintf(logbase, FILE_STR_LEN, "/tmp/%s", logtail); + if (snprintf(logbase, FILE_STR_LEN, "/tmp/%s", logtail)<0) + TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "String truncation occured.\n"); set_log_file_name(logbase, logf); _rtpfile = fopen(logf, "a"); if(_rtpfile) diff --git a/src/client/ns_turn_msg.c b/src/client/ns_turn_msg.c index c992e5c..2a4008d 100644 --- a/src/client/ns_turn_msg.c +++ b/src/client/ns_turn_msg.c @@ -386,7 +386,7 @@ int stun_get_command_message_len_str(const uint8_t* buf, size_t len) return -1; /* Validate the size the buffer claims to be */ - int bufLen = (int) (nswap16(((const uint16_t*)(buf))[1]) + STUN_HEADER_LENGTH); + size_t bufLen = (size_t) (nswap16(((const uint16_t*)(buf))[1]) + STUN_HEADER_LENGTH); if (bufLen > len) { return -1; } @@ -1386,7 +1386,7 @@ static stun_attr_ref stun_attr_check_valid(stun_attr_ref attr, size_t remaining) if(remaining >= 4) { /* Read the size of the attribute */ - int attrlen = stun_attr_get_len(attr); + size_t attrlen = stun_attr_get_len(attr); remaining -= 4; /* Round to boundary */