[Asterisk-code-review] Clang: Fix some more tautological-compare warnings. (asterisk[11])

Matt Jordan asteriskteam at digium.com
Fri Apr 24 10:25:50 CDT 2015


Matt Jordan has uploaded a new change for review.

  https://gerrit.asterisk.org/253

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 therefore deemed
unnecessary.

Example:
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 particular 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 res/res_security_log.c
1 file changed, 1 insertion(+), 1 deletion(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/53/253/1

diff --git a/res/res_security_log.c b/res/res_security_log.c
index 8611e3f..bea4609 100644
--- a/res/res_security_log.c
+++ b/res/res_security_log.c
@@ -120,7 +120,7 @@
 
 	/* Note that the event type is guaranteed to be valid here. */
 	event_type = ast_event_get_ie_uint(event, AST_EVENT_IE_SECURITY_EVENT);
-	ast_assert(event_type >= 0 && event_type < AST_SECURITY_EVENT_NUM_TYPES);
+	ast_assert((unsigned int)event_type >= 0 && event_type < AST_SECURITY_EVENT_NUM_TYPES);
 
 	ast_str_set(&str, 0, "%s=\"%s\"",
 			ast_event_get_ie_type_name(AST_EVENT_IE_SECURITY_EVENT),

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ief23ef68916192b9b72dabe702b543ecfeca0b62
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 11
Gerrit-Owner: Matt Jordan <mjordan at digium.com>



More information about the asterisk-code-review mailing list