]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
clang compiler warnings: Fix autological comparisons
authorMatthew Jordan <mjordan@digium.com>
Thu, 9 Apr 2015 12:47:09 +0000 (12:47 +0000)
committerMatthew Jordan <mjordan@digium.com>
Thu, 9 Apr 2015 12:47:09 +0000 (12:47 +0000)
This fixes autological comparison warnings in the following:
 * chan_skinny: letohl may return a signed or unsigned value, depending on the
   macro chosen
 * func_curl: Provide a specific cast to CURLoption to prevent mismatch
 * cel: Fix enum comparisons where the enum can never be negative
 * enum: Fix comparison of return result of dn_expand, which returns a signed
   int value
 * event: Fix enum comparisons where the enum can never be negative
 * indications: tone_data.freq1 and freq2 are unsigned, and hence can never be
   negative
 * presencestate: Use the actual enum value for INVALID state
 * security_events: Fix enum comparisons where the enum can never be negative
 * udptl: Don't bother to check if the return value from encode_length is less
   than 0, as it returns an unsigned int
 * translate: Since the parameters are unsigned int, don't bother checking
   to see if they are negative. The cast to unsigned int would already blow
   past the matrix bounds.

Review: https://reviewboard.asterisk.org/r/4533
ASTERISK-24917
Reported by: dkdegroot
patches:
  rb4533.patch submitted by dkdegroot (License 6600)

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/11@434469 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_skinny.c
funcs/func_curl.c
include/asterisk/cel.h
main/cel.c
main/enum.c
main/event.c
main/indications.c
main/presencestate.c
main/security_events.c
main/translate.c
main/udptl.c

index e5f2afb973df1c2bfe9411cdaf9258c87a39b082..58cb564723395c92f3543c1bb9727a8665c991bc 100644 (file)
@@ -2229,6 +2229,7 @@ static char *callstate2str(int ind)
 static int transmit_response_bysession(struct skinnysession *s, struct skinny_req *req)
 {
        int res = 0;
+       unsigned long len;
 
        if (!s) {
                ast_log(LOG_WARNING, "Asked to transmit to a non-existent session!\n");
@@ -2237,7 +2238,13 @@ static int transmit_response_bysession(struct skinnysession *s, struct skinny_re
 
        ast_mutex_lock(&s->lock);
 
-       if ((letohl(req->len) > SKINNY_MAX_PACKET) || (letohl(req->len) < 0)) {
+       /* Don't optimize out assigning letohl() to len. It is necessary to guarantee that
+        * the comparison will always catch invalid values.
+         * letohl() may or may not return a signed value depending upon which definition
+        * is used.
+        */
+       len = letohl(req->len);
+       if (SKINNY_MAX_PACKET < len) {
                ast_log(LOG_WARNING, "transmit_response: the length of the request (%d) is out of bounds (%d)\n", letohl(req->len), SKINNY_MAX_PACKET);
                ast_mutex_unlock(&s->lock);
                return -1;
index 5d7c3a550e0dfd086acb975e2dae1fe9ee3879b3..1795a8128bc74c6cb8418c3e8fd77734b9598f2c 100644 (file)
@@ -171,7 +171,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #define CURLVERSION_ATLEAST(a,b,c) \
        ((LIBCURL_VERSION_MAJOR > (a)) || ((LIBCURL_VERSION_MAJOR == (a)) && (LIBCURL_VERSION_MINOR > (b))) || ((LIBCURL_VERSION_MAJOR == (a)) && (LIBCURL_VERSION_MINOR == (b)) && (LIBCURL_VERSION_PATCH >= (c))))
 
-#define CURLOPT_SPECIAL_HASHCOMPAT -500
+#define CURLOPT_SPECIAL_HASHCOMPAT ((CURLoption) -500)
 
 static void curlds_free(void *data);
 
index 25a3a4af1d4773003cbe80db2fb5311a22375622..883e250f311926a7f824ff1fe80da5ee90a77ca5 100644 (file)
@@ -53,6 +53,8 @@ enum ast_cel_ama_flag {
  * \brief CEL event types
  */
 enum ast_cel_event_type {
+       AST_CEL_INVALID_VALUE = -1,
+       AST_CEL_ALL = 0,
        /*! \brief channel birth */
        AST_CEL_CHANNEL_START = 1,
        /*! \brief channel end */
@@ -105,7 +107,7 @@ enum ast_cel_event_type {
        AST_CEL_FORWARD = 25,
 };
 
-/*! 
+/*!
  * \brief Check to see if CEL is enabled
  *
  * \since 1.8
index ca7186694cb4e952474c6131f6049008a453cf1c..59a5b7ff78e8c7a4dda203ce397e814321fec0cb 100644 (file)
@@ -123,7 +123,7 @@ static char cel_dateformat[256];
  * \brief Map of ast_cel_event_type to strings
  */
 static const char * const cel_event_types[CEL_MAX_EVENT_IDS] = {
-       [0]                        = "ALL",
+       [AST_CEL_ALL]              = "ALL",
        [AST_CEL_CHANNEL_START]    = "CHAN_START",
        [AST_CEL_CHANNEL_END]      = "CHAN_END",
        [AST_CEL_ANSWER]           = "ANSWER",
@@ -256,15 +256,12 @@ enum ast_cel_event_type ast_cel_str_to_event_type(const char *name)
        unsigned int i;
 
        for (i = 0; i < ARRAY_LEN(cel_event_types); i++) {
-               if (!cel_event_types[i]) {
-                       continue;
-               }
-
-               if (!strcasecmp(name, cel_event_types[i])) {
+               if (cel_event_types[i] && !strcasecmp(name, cel_event_types[i])) {
                        return i;
                }
        }
 
+       ast_log(LOG_ERROR, "Unknown event name '%s'\n", name);
        return -1;
 }
 
@@ -288,10 +285,10 @@ static void parse_events(const char *val)
 
                event_type = ast_cel_str_to_event_type(cur_event);
 
-               if (event_type == 0) {
+               if (event_type == AST_CEL_ALL) {
                        /* All events */
                        eventset = (int64_t) -1;
-               } else if (event_type == -1) {
+               } else if (event_type == AST_CEL_INVALID_VALUE) {
                        ast_log(LOG_WARNING, "Unknown event name '%s'\n",
                                        cur_event);
                } else {
@@ -416,7 +413,7 @@ const char *ast_cel_get_type_name(enum ast_cel_event_type type)
 
 const char *ast_cel_get_ama_flag_name(enum ast_cel_ama_flag flag)
 {
-       if (flag < 0 || flag >= ARRAY_LEN(cel_ama_flags)) {
+       if (flag >= ARRAY_LEN(cel_ama_flags)) {
                ast_log(LOG_WARNING, "Invalid AMA flag: %u\n", flag);
                return "Unknown";
        }
index 4c6dbcce47bb94da21639f55d4be89f6d0239054..3b49486076de13106dc167e400374fdd69beb6b1 100644 (file)
@@ -250,7 +250,7 @@ struct ebl_context {
 static int ebl_callback(void *context, unsigned char *answer, int len, unsigned char *fullanswer)
 {
        struct ebl_context *c = context;
-       unsigned int i;
+       int i;
 
        c->pos = 0;     /* default to empty */
        c->separator[0] = 0;
index 4b2844be2c35825bc57d64cd53eb69fee2b381ce..617f28a6df302fcf3d7f12e3975b73896fc17f6c 100644 (file)
@@ -295,7 +295,7 @@ const char *ast_event_get_type_name(const struct ast_event *event)
 
        type = ast_event_get_type(event);
 
-       if (type < 0 || type >= ARRAY_LEN(event_names)) {
+       if (type >= ARRAY_LEN(event_names)) {
                ast_log(LOG_ERROR, "Invalid event type - '%u'\n", type);
                return "";
        }
@@ -725,6 +725,7 @@ void ast_event_report_subs(const struct ast_event_sub *event_sub)
        struct ast_event *event;
        struct ast_event_sub *sub;
        enum ast_event_type event_type = -1;
+       int found = 0;
        struct ast_event_ie_val *ie_val;
 
        if (event_sub->type != AST_EVENT_SUB)
@@ -733,12 +734,14 @@ void ast_event_report_subs(const struct ast_event_sub *event_sub)
        AST_LIST_TRAVERSE(&event_sub->ie_vals, ie_val, entry) {
                if (ie_val->ie_type == AST_EVENT_IE_EVENTTYPE) {
                        event_type = ie_val->payload.uint;
+                       found = 1;
                        break;
                }
        }
 
-       if (event_type == -1)
+       if (!found) {
                return;
+       }
 
        AST_RWDLLIST_RDLOCK(&ast_event_subs[event_type]);
        AST_RWDLLIST_TRAVERSE(&ast_event_subs[event_type], sub, entry) {
@@ -763,7 +766,7 @@ struct ast_event_sub *ast_event_subscribe_new(enum ast_event_type type,
 {
        struct ast_event_sub *sub;
 
-       if (type < 0 || type >= AST_EVENT_TOTAL) {
+       if (type >= AST_EVENT_TOTAL) {
                ast_log(LOG_ERROR, "%u is an invalid type!\n", type);
                return NULL;
        }
index 967cae98cfd5b4842739c5cb4e3bab10d248350a..a453feadf87f8369e0084865f0742a637053d421 100644 (file)
@@ -360,14 +360,13 @@ int ast_playtones_start(struct ast_channel *chan, int vol, const char *playlst,
 
                if (tone_data.midinote) {
                        /* midi notes must be between 0 and 127 */
-
-                       if (tone_data.freq1 >= 0 && tone_data.freq1 <= 127) {
+                       if (tone_data.freq1 <= 127) {
                                tone_data.freq1 = midi_tohz[tone_data.freq1];
                        } else {
                                tone_data.freq1 = 0;
                        }
 
-                       if (tone_data.freq2 >= 0 && tone_data.freq2 <= 127) {
+                       if (tone_data.freq2 <= 127) {
                                tone_data.freq2 = midi_tohz[tone_data.freq2];
                        } else {
                                tone_data.freq2 = 0;
index b87b09242c62e76c4d02424262edc412dae64fd0..09a73e6f900724bd60b222ea9c0f0f55037fd2da 100644 (file)
@@ -240,7 +240,7 @@ static void do_presence_state_change(const char *provider)
 
        state = ast_presence_state_helper(provider, &subtype, &message, 0);
 
-       if (state < 0) {
+       if (state == AST_PRESENCE_INVALID) {
                return;
        }
 
index 6d4d9776cf3ada521814ed6376f4f8ca4df73453..ca24921bacb562549873fcb6bf52600d188dd791 100644 (file)
@@ -427,7 +427,7 @@ const char *ast_security_event_severity_get_name(
 
 static int check_event_type(const enum ast_security_event_type event_type)
 {
-       if (event_type < 0 || event_type >= AST_SECURITY_EVENT_NUM_TYPES) {
+       if (event_type >= AST_SECURITY_EVENT_NUM_TYPES) {
                ast_log(LOG_ERROR, "Invalid security event type %u\n", event_type);
                return -1;
        }
@@ -680,7 +680,7 @@ int ast_security_event_report(const struct ast_security_event_common *sec)
 {
        int res;
 
-       if (sec->event_type < 0 || sec->event_type >= AST_SECURITY_EVENT_NUM_TYPES) {
+       if (sec->event_type >= AST_SECURITY_EVENT_NUM_TYPES) {
                ast_log(LOG_ERROR, "Invalid security event type\n");
                return -1;
        }
index d12925709ccf9c6ddf280325a3ac6ad594bf437b..224bcb73583f0056999af02fdbf6d5e9ec2e5ce2 100644 (file)
@@ -263,9 +263,6 @@ static void matrix_clear(void)
  */
 static struct translator_path *matrix_get(unsigned int x, unsigned int y)
 {
-       if (!(x >= 0 && y >= 0)) {
-               return NULL;
-       }
        return __matrix[x] + y;
 }
 
index b7abb17e141061e58e268d798e0706d7aeb10430..76fc2fbdeb758c294b99bd2d8e197f0bd0aa6c20 100644 (file)
@@ -320,8 +320,7 @@ static int encode_open_type(const struct ast_udptl *udptl, uint8_t *buf, unsigne
        }
        /* Encode the open type */
        for (octet_idx = 0; ; num_octets -= enclen, octet_idx += enclen) {
-               if ((enclen = encode_length(buf, len, num_octets)) < 0)
-                       return -1;
+               enclen = encode_length(buf, len, num_octets);
                if (enclen + *len > buflen) {
                        ast_log(LOG_ERROR, "UDPTL (%s): Buffer overflow detected (%u + %u > %u)\n",
                                LOG_TAG(udptl), enclen, *len, buflen);
@@ -604,8 +603,7 @@ static int udptl_build_packet(struct ast_udptl *s, uint8_t *buf, unsigned int bu
                buf[len++] = 0x00;
                /* The number of entries will always be zero, so it is pointless allowing
                   for the fragmented case here. */
-               if (encode_length(buf, &len, 0) < 0)
-                       return -1;
+               encode_length(buf, &len, 0);
                break;
        case UDPTL_ERROR_CORRECTION_REDUNDANCY:
                /* Encode the error recovery type */
@@ -616,8 +614,7 @@ static int udptl_build_packet(struct ast_udptl *s, uint8_t *buf, unsigned int bu
                        entries = s->tx_seq_no;
                /* The number of entries will always be small, so it is pointless allowing
                   for the fragmented case here. */
-               if (encode_length(buf, &len, entries) < 0)
-                       return -1;
+               encode_length(buf, &len, entries);
                /* Encode the elements */
                for (i = 0; i < entries; i++) {
                        j = (entry - i - 1) & UDPTL_BUF_MASK;