[asterisk-commits] Clang: Fix some more tautological-compare warnings. (asterisk[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Apr 26 15:53:58 CDT 2015


Matt Jordan has submitted this change and it was merged.

Change subject: Clang: Fix some more tautological-compare warnings.
......................................................................


Clang: Fix some more tautological-compare warnings.

clang can warn about a so called tautological-compare, when it finds
comparisons which are logically always true, and are therefor deemed
unnecessary.

Exanple:
unsigned int x = 4;
if (x > 0)    // x is always going to be bigger than 0

Enum Case:
Each enumeration is its own type. Enums are an integer type but they
do not have to be *signed*. C leaves it up to the compiler as an
implementation option what to consider the integer type of a particu-
lar enumeration is. Gcc treats an enum without negative values as
an int while clang treats this enum as an unsigned int.

rmudgett & mmichelson: cast the enum to (unsigned int) in assert.
The cast does have an effect. For gcc, which seems to treat all enums
as int, the cast to unsigned int will eliminate the possibility of
negative values being allowed. For clang, which seems to treat enums
without any negative members as unsigned int, the cast will have no
effect. If for some reason in the future a negative value is ever
added to the enum the assert will still catch the negative value.

ASTERISK-24917
Change-Id: Ief23ef68916192b9b72dabe702b543ecfeca0b62
---
M channels/chan_skinny.c
M res/res_security_log.c
2 files changed, 4 insertions(+), 2 deletions(-)

Approvals:
  Diederik de Groot: Looks good to me, but someone else must approve
  Matt Jordan: Looks good to me, approved; Verified
  Joshua Colp: Looks good to me, but someone else must approve



diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c
index 06878fb..8f6f2eb 100644
--- a/channels/chan_skinny.c
+++ b/channels/chan_skinny.c
@@ -7488,6 +7488,7 @@
 	struct skinnysession *s = data;
 
 	int dlen = 0;
+	int eventmessage = 0;
 	struct pollfd fds[1];
 
 	if (!s) {
@@ -7544,7 +7545,8 @@
 				break;
 			}
 
-			if (letohl(req->e) < 0) {
+			eventmessage = letohl(req-e);
+			if (eventmessage < 0) {
 				ast_log(LOG_ERROR, "Event Message is NULL from socket %d, This is bad\n", s->fd);
 				break;
 			}
diff --git a/res/res_security_log.c b/res/res_security_log.c
index e147616..d32b32c 100644
--- a/res/res_security_log.c
+++ b/res/res_security_log.c
@@ -98,7 +98,7 @@
 	event_type_json = ast_json_object_get(json, "SecurityEvent");
 	event_type = ast_json_integer_get(event_type_json);
 
-	ast_assert(event_type >= 0 && event_type < AST_SECURITY_EVENT_NUM_TYPES);
+	ast_assert((unsigned int)event_type < AST_SECURITY_EVENT_NUM_TYPES);
 
 	if (!(str = ast_str_thread_get(&security_event_buf,
 			SECURITY_EVENT_BUF_INIT_LEN))) {

-- 
To view, visit https://gerrit.asterisk.org/252
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ief23ef68916192b9b72dabe702b543ecfeca0b62
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Matt Jordan <mjordan at digium.com>
Gerrit-Reviewer: Diederik de Groot <dkgroot at talon.nl>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Matt Jordan <mjordan at digium.com>



More information about the asterisk-commits mailing list