From 5923f71a842797942ac4259a4b563656ecb711e9 Mon Sep 17 00:00:00 2001 From: Jeff Lenk Date: Wed, 1 Jun 2011 22:36:19 -0500 Subject: [PATCH] more code analysis mostly trivial except string formating changes --- libs/stfu/stfu.c | 4 ++-- libs/stfu/stfu.h | 7 +++++++ src/switch_channel.c | 4 ++-- src/switch_console.c | 5 +++-- src/switch_event.c | 10 ++++------ src/switch_xml.c | 24 ++++++++++++------------ 6 files changed, 30 insertions(+), 24 deletions(-) diff --git a/libs/stfu/stfu.c b/libs/stfu/stfu.c index a4c3bb78d3..75a659d894 100644 --- a/libs/stfu/stfu.c +++ b/libs/stfu/stfu.c @@ -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; diff --git a/libs/stfu/stfu.h b/libs/stfu/stfu.h index b802bbaef6..3e989b0a97 100644 --- a/libs/stfu/stfu.h +++ b/libs/stfu/stfu.h @@ -40,6 +40,13 @@ extern "C" { #include #include +#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 diff --git a/src/switch_channel.c b/src/switch_channel.c index 6ccaedee3d..01c2937470 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -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); diff --git a/src/switch_console.c b/src/switch_console.c index d902af69e7..c54ba643d2 100644 --- a/src/switch_console.c +++ b/src/switch_console.c @@ -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]; diff --git a/src/switch_event.c b/src/switch_event.c index b1f5762887..0929be27d9 100644 --- a/src/switch_event.c +++ b/src/switch_event.c @@ -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(); } } diff --git a/src/switch_xml.c b/src/switch_xml.c index 4664c07c71..fa53406822 100644 --- a/src/switch_xml.c +++ b/src/switch_xml.c @@ -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) {