Browse Source

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
Mészáros Mihály 5 years ago
parent
commit
4722697645
3 changed files with 13 additions and 6 deletions
  1. 2 0
      ChangeLog
  2. 9 4
      src/apps/common/ns_turn_utils.c
  3. 2 2
      src/client/ns_turn_msg.c

+ 2 - 0
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 <[email protected]> Mihály Mészáros <[email protected]>
 Version 4.5.1.1 'dan Eider':

+ 9 - 4
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)

+ 2 - 2
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 */