]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Clang: Fix some more tautological-compare warnings. 60/160/8
authorDiederik de Groot <ddegroot@talon.nl>
Wed, 22 Apr 2015 09:17:56 +0000 (11:17 +0200)
committerDiederik de Groot <ddegroot@talon.nl>
Wed, 22 Apr 2015 16:09:23 +0000 (18:09 +0200)
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

channels/chan_skinny.c
main/security_events.c
res/res_security_log.c

index a089c65d82c4d4af6ab3ca9c6a152598896ef434..e875a66ee416caa0d9f520088f35b55c446ee43c 100644 (file)
@@ -7488,6 +7488,7 @@ static void *skinny_session(void *data)
        struct skinnysession *s = data;
 
        int dlen = 0;
+       int eventmessage = 0;
        struct pollfd fds[1];
 
        if (!s) {
@@ -7544,7 +7545,8 @@ static void *skinny_session(void *data)
                                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;
                        }
index 5a8df66d1188f951d6ca72cd51d7aa6c28d7e834..1d8295265158a1f4943fad6df7620d5db0d7dade 100644 (file)
@@ -428,7 +428,7 @@ static struct ast_manager_event_blob *security_event_to_ami_blob(struct ast_json
        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_create(SECURITY_EVENT_BUF_INIT_LEN))) {
                return NULL;
index e56f7f76fc09bb7a5f579efeef94b2a5d4d47913..78ca1218cd7552eb4465d98353c0d384b3ec47d1 100644 (file)
@@ -98,7 +98,7 @@ static void security_event_stasis_cb(struct ast_json *json)
        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))) {