]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
more code analysis mostly trivial except string formating changes
authorJeff Lenk <jeff@jefflenk.com>
Thu, 2 Jun 2011 03:36:19 +0000 (22:36 -0500)
committerJeff Lenk <jeff@jefflenk.com>
Thu, 2 Jun 2011 03:36:19 +0000 (22:36 -0500)
libs/stfu/stfu.c
libs/stfu/stfu.h
src/switch_channel.c
src/switch_console.c
src/switch_event.c
src/switch_xml.c

index a4c3bb78d35d25d76698574f54a6579f0d540fe3..75a659d8948c351fe9f67e61ebf158ad9b98fbc0 100644 (file)
@@ -231,7 +231,7 @@ void stfu_n_debug(stfu_instance_t *i, const char *name)
 
 void stfu_n_report(stfu_instance_t *i, stfu_report_t *r)
 {
-    assert(i);
+    stfu_assert(i);
        r->qlen = i->qlen;
        r->packet_in_count = i->period_packet_in_count;
        r->clean_count = i->period_clean_count;
@@ -580,7 +580,7 @@ static int stfu_n_find_any_frame(stfu_instance_t *in, stfu_queue_t *queue, stfu_
     uint32_t i = 0;
     stfu_frame_t *frame = NULL;
 
-    assert(r_frame);
+    stfu_assert(r_frame);
     
     *r_frame = NULL;
 
index b802bbaef642b00cfda5ddeb861925213913759b..3e989b0a979837e6b1218f7d9fc826b06a350958 100644 (file)
@@ -40,6 +40,13 @@ extern "C" {
 #include <string.h>
 #include <stdarg.h>
 
+#if (_MSC_VER >= 1400)                 // VC8+
+#define stfu_assert(expr) assert(expr);__analysis_assume( expr )
+#endif
+
+#ifndef stfu_assert
+#define stfu_assert(_x) assert(_x)
+#endif
 
 #ifdef  _MSC_VER
 #ifndef uint32_t
index 6ccaedee3da15691f51c6618e5621bef75e8d1bf..01c29374707a074ba5fb270ee824ab76f7500a85 100644 (file)
@@ -3643,7 +3643,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_set_timestamps(switch_channel_t *
        switch_snprintf(tmp, sizeof(tmp), "%d", billsec);
        switch_channel_set_variable(channel, "billsec", tmp);
 
-       switch_snprintf(tmp, sizeof(tmp), "%d", progresssec);
+       switch_snprintf(tmp, sizeof(tmp), "%"SWITCH_TIME_T_FMT, progresssec);
        switch_channel_set_variable(channel, "progresssec", tmp);
 
        switch_snprintf(tmp, sizeof(tmp), "%d", answersec);
@@ -3652,7 +3652,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_set_timestamps(switch_channel_t *
        switch_snprintf(tmp, sizeof(tmp), "%d", waitsec);
        switch_channel_set_variable(channel, "waitsec", tmp);
 
-       switch_snprintf(tmp, sizeof(tmp), "%d", progress_mediasec);
+       switch_snprintf(tmp, sizeof(tmp), "%"SWITCH_TIME_T_FMT, progress_mediasec);
        switch_channel_set_variable(channel, "progress_mediasec", tmp);
 
        switch_snprintf(tmp, sizeof(tmp), "%d", legbillsec);
index d902af69e71675da63abc82d0ea583f7032f1f88..c54ba643d2238fe0f6e81fc23759105706a18b31 100644 (file)
@@ -105,7 +105,7 @@ static switch_status_t console_xml_config(void)
                for (param = switch_xml_child(settings, "key"); param; param = param->next) {
                        char *var = (char *) switch_xml_attr_soft(param, "name");
                        char *val = (char *) switch_xml_attr_soft(param, "value");
-                       int i = atoi(var);
+                       i = atoi(var);
                        if ((i < 1) || (i > 12)) {
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Keybind %s is invalid, range is from 1 to 12\n", var);
                        } else {
@@ -913,7 +913,7 @@ static unsigned char console_fnkey_pressed(int i)
 {
        char *c, *cmd;
 
-       assert((i > 0) && (i <= 12));
+       switch_assert((i > 0) && (i <= 12));
 
        c = console_fnkeys[i - 1];
 
@@ -1675,6 +1675,7 @@ SWITCH_DECLARE(void) switch_console_sort_matches(switch_console_callback_match_t
                sort[3] = sort[2] ? sort[2]->next : NULL;
 
                for (j = 1; j <= (matches->count - i); j++) {
+                       switch_assert(sort[1] && sort[2]);
                        if (strcmp(sort[1]->val, sort[2]->val) > 0) {
                                sort[1]->next = sort[3];
                                sort[2]->next = sort[1];
index b1f5762887be31a4ec26f2a6fcb2ca61827bb7af..0929be27d9fa06e7621ffdd3ab05e5c5764b0e11 100644 (file)
@@ -1302,11 +1302,10 @@ SWITCH_DECLARE(switch_status_t) switch_event_serialize(switch_event_t *event, ch
                llen = strlen(hp->name) + strlen(encode_buf) + 8;
 
                if ((len + llen) > dlen) {
-                       char *m;
+                       char *m = buf;
                        dlen += (blocksize + (len + llen));
-                       if ((m = realloc(buf, dlen))) {
+                       if (!(buf = realloc(buf, dlen))) {
                                buf = m;
-                       } else {
                                abort();
                        }
                }
@@ -1329,11 +1328,10 @@ SWITCH_DECLARE(switch_status_t) switch_event_serialize(switch_event_t *event, ch
                }
 
                if ((len + llen) > dlen) {
-                       char *m;
+                       char *m = buf;
                        dlen += (blocksize + (len + llen));
-                       if ((m = realloc(buf, dlen))) {
+                       if (!(buf = realloc(buf, dlen))) {
                                buf = m;
-                       } else {
                                abort();
                        }
                }
index 4664c07c71d6f5e80d3528183f7a39cd0f002380..fa534068225d99f772bcbc2e9995a784aa3082ca 100644 (file)
@@ -1125,12 +1125,12 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_fp(FILE * fp)
        do {
                len += (l = fread((s + len), 1, SWITCH_XML_BUFSIZE, fp));
                if (l == SWITCH_XML_BUFSIZE) {
-                       char *tmp = (char *) realloc(s, len + SWITCH_XML_BUFSIZE);
-                       if (!tmp) {
-                               free(s);
+                       char *tmp = s;
+                       s = (char *) realloc(s, len + SWITCH_XML_BUFSIZE);
+                       if (!s) {
+                               free(tmp);
                                return NULL;
                        }
-                       s = tmp;
                }
        } while (s && l == SWITCH_XML_BUFSIZE);
 
@@ -2279,10 +2279,10 @@ static char *switch_xml_toxml_r(switch_xml_t xml, char **s, switch_size_t *len,
        *s = switch_xml_ampencode(txt + start, xml->off - start, s, len, max, 0);
 
        while (*len + strlen(xml->name) + 5 + (strlen(XML_INDENT) * (*count)) + 1 > *max) {     /* reallocate s */
-               char *tmp = (char *) realloc(*s, *max += SWITCH_XML_BUFSIZE);
-               if (!tmp)
-                       return *s;
-               *s = tmp;
+               char *tmp = *s;
+               *s = (char *) realloc(*s, *max += SWITCH_XML_BUFSIZE);
+               if (!*s)
+                       return tmp;
        }
 
        if (*len && *(*s + (*len) - 1) == '>') {
@@ -2335,10 +2335,10 @@ static char *switch_xml_toxml_r(switch_xml_t xml, char **s, switch_size_t *len,
        }
 
        while (*len + strlen(xml->name) + 5 + (strlen(XML_INDENT) * (*count)) > *max) { /* reallocate s */
-               char *tmp = (char *) realloc(*s, *max += SWITCH_XML_BUFSIZE);
-               if (!tmp)
-                       return *s;
-               *s = tmp;
+               char *tmp = *s;
+               *s = (char *) realloc(*s, *max += SWITCH_XML_BUFSIZE);
+               if (!*s)
+                       return tmp;
        }
 
        if (xml->child || xml->txt) {