mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-14 00:24:05 +00:00
clang compiler warnings: Fix autological comparisons
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. * res_pjsip_exten_state: Use a temporary value to cache the return of ast_hint_presence_state * res_stasis_playback: Fix enum comparisons where the enum can never be negative * res_stasis_recording: Add an enum value for the case where the recording operation is in error; fix enum comparisons * resource_bridges: Use enum value as opposed to -1 * resource_channels: Use enum value as opposed to -1 Review: https://reviewboard.asterisk.org/r/4533 ASTERISK-24917 Reported by: dkdegroot patches: rb4533.patch submitted by dkdegroot (License 6600) ........ Merged revisions 434469 from http://svn.asterisk.org/svn/asterisk/branches/11 ........ Merged revisions 434470 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@434471 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -2374,6 +2374,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");
|
||||
@@ -2382,7 +2383,10 @@ 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 (%u) is out of bounds (%d)\n", letohl(req->len), SKINNY_MAX_PACKET);
|
||||
ast_mutex_unlock(&s->lock);
|
||||
return -1;
|
||||
|
@@ -866,11 +866,11 @@ static int media_offer_read_av(struct ast_sip_session *session, char *buf,
|
||||
|
||||
/* add one since we'll include a comma */
|
||||
size = strlen(ast_format_get_name(fmt)) + 1;
|
||||
len -= size;
|
||||
if ((len) < 0) {
|
||||
if (len < size) {
|
||||
ao2_ref(fmt, -1);
|
||||
break;
|
||||
}
|
||||
len -= size;
|
||||
|
||||
/* no reason to use strncat here since we have already ensured buf has
|
||||
enough space, so strcat can be safely used */
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -985,6 +985,8 @@ int ast_play_and_wait(struct ast_channel *chan, const char *fn);
|
||||
* \since 12
|
||||
*/
|
||||
enum ast_record_if_exists {
|
||||
/*! Return an Error State for IF_Exists */
|
||||
AST_RECORD_IF_EXISTS_ERROR = -1,
|
||||
/*! Fail the recording. */
|
||||
AST_RECORD_IF_EXISTS_FAIL,
|
||||
/*! Overwrite the existing recording. */
|
||||
|
@@ -39,6 +39,8 @@ extern "C" {
|
||||
* \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 */
|
||||
|
@@ -371,7 +371,7 @@ void ast_callid_strnprint(char *buffer, size_t buffer_size, ast_callid callid);
|
||||
|
||||
#define DEBUG_ATLEAST(level) \
|
||||
(option_debug >= (level) \
|
||||
|| (ast_opt_dbg_module && ast_debug_get_by_module(AST_MODULE) >= (level)))
|
||||
|| (ast_opt_dbg_module && (int)ast_debug_get_by_module(AST_MODULE) >= (level)))
|
||||
|
||||
/*!
|
||||
* \brief Log a DEBUG message
|
||||
|
@@ -816,7 +816,7 @@ int ast_safe_mkdir(const char *base_path, const char *path, int mode);
|
||||
* \param a the array to bound check
|
||||
* \return 0 if value out of bounds, otherwise true (non-zero)
|
||||
*/
|
||||
#define ARRAY_IN_BOUNDS(v, a) IN_BOUNDS(v, 0, ARRAY_LEN(a) - 1)
|
||||
#define ARRAY_IN_BOUNDS(v, a) IN_BOUNDS((int) (v), 0, ARRAY_LEN(a) - 1)
|
||||
|
||||
/* Definition for Digest authorization */
|
||||
struct ast_http_digest {
|
||||
|
@@ -1515,6 +1515,9 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile,
|
||||
case AST_RECORD_IF_EXISTS_APPEND:
|
||||
ioflags |= O_APPEND;
|
||||
break;
|
||||
case AST_RECORD_IF_EXISTS_ERROR:
|
||||
ast_assert(0);
|
||||
break;
|
||||
}
|
||||
|
||||
if (silencethreshold < 0) {
|
||||
|
16
main/cel.c
16
main/cel.c
@@ -284,7 +284,7 @@ static struct aco_type *general_options[] = ACO_TYPES(&general_option);
|
||||
* \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",
|
||||
@@ -524,16 +524,13 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
ast_log(LOG_ERROR, "Unknown event name '%s'\n", name);
|
||||
return AST_CEL_INVALID_VALUE;
|
||||
}
|
||||
|
||||
static int ast_cel_track_event(enum ast_cel_event_type et)
|
||||
@@ -563,11 +560,10 @@ static int events_handler(const struct aco_option *opt, struct ast_variable *var
|
||||
|
||||
event_type = ast_cel_str_to_event_type(cur_event);
|
||||
|
||||
if (event_type == 0) {
|
||||
if (event_type == AST_CEL_ALL) {
|
||||
/* All events */
|
||||
cfg->events = (int64_t) -1;
|
||||
} else if (event_type == -1) {
|
||||
ast_log(LOG_ERROR, "Unknown event name '%s'\n", cur_event);
|
||||
} else if (event_type == AST_CEL_INVALID_VALUE) {
|
||||
return -1;
|
||||
} else {
|
||||
cfg->events |= ((int64_t) 1 << event_type);
|
||||
|
@@ -257,7 +257,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;
|
||||
|
@@ -199,7 +199,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 "";
|
||||
}
|
||||
|
@@ -359,14 +359,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;
|
||||
|
@@ -323,7 +323,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;
|
||||
}
|
||||
|
||||
|
@@ -886,7 +886,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;
|
||||
}
|
||||
@@ -1172,7 +1172,7 @@ return_error:
|
||||
|
||||
int ast_security_event_report(const struct ast_security_event_common *sec)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
@@ -362,8 +362,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);
|
||||
@@ -646,8 +645,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 */
|
||||
@@ -658,8 +656,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;
|
||||
|
@@ -692,7 +692,7 @@ void ast_ari_bridges_record(struct ast_variable *headers,
|
||||
return;
|
||||
}
|
||||
|
||||
if (options->if_exists == -1) {
|
||||
if (options->if_exists == AST_RECORD_IF_EXISTS_ERROR) {
|
||||
ast_ari_response_error(
|
||||
response, 400, "Bad Request",
|
||||
"ifExists invalid");
|
||||
|
@@ -626,7 +626,7 @@ void ast_ari_channels_record(struct ast_variable *headers,
|
||||
return;
|
||||
}
|
||||
|
||||
if (options->if_exists == -1) {
|
||||
if (options->if_exists == AST_RECORD_IF_EXISTS_ERROR) {
|
||||
ast_ari_response_error(
|
||||
response, 400, "Bad Request",
|
||||
"ifExists invalid");
|
||||
|
@@ -401,6 +401,7 @@ static struct ast_sip_exten_state_data *exten_state_data_alloc(struct ast_sip_su
|
||||
struct ast_sip_exten_state_data *exten_state_data;
|
||||
char *subtype = NULL;
|
||||
char *message = NULL;
|
||||
int presence_state;
|
||||
|
||||
exten_state_data = ao2_alloc(sizeof(*exten_state_data), exten_state_data_destructor);
|
||||
if (!exten_state_data) {
|
||||
@@ -408,11 +409,12 @@ static struct ast_sip_exten_state_data *exten_state_data_alloc(struct ast_sip_su
|
||||
}
|
||||
|
||||
exten_state_data->exten = exten_state_sub->exten;
|
||||
if ((exten_state_data->presence_state = ast_hint_presence_state(NULL, exten_state_sub->context,
|
||||
exten_state_sub->exten, &subtype, &message)) == -1) {
|
||||
presence_state = ast_hint_presence_state(NULL, exten_state_sub->context, exten_state_sub->exten, &subtype, &message);
|
||||
if (presence_state == -1 || presence_state == AST_PRESENCE_INVALID) {
|
||||
ao2_cleanup(exten_state_data);
|
||||
return NULL;
|
||||
}
|
||||
exten_state_data->presence_state = presence_state;
|
||||
exten_state_data->presence_subtype = subtype;
|
||||
exten_state_data->presence_message = message;
|
||||
exten_state_data->user_agent = exten_state_sub->user_agent;
|
||||
|
@@ -629,9 +629,9 @@ enum stasis_playback_oper_results stasis_app_playback_operation(
|
||||
playback_opreation_cb cb;
|
||||
SCOPED_AO2LOCK(lock, playback);
|
||||
|
||||
ast_assert(playback->state >= 0 && playback->state < STASIS_PLAYBACK_STATE_MAX);
|
||||
ast_assert(playback->state < STASIS_PLAYBACK_STATE_MAX);
|
||||
|
||||
if (operation < 0 || operation >= STASIS_PLAYBACK_MEDIA_OP_MAX) {
|
||||
if (operation >= STASIS_PLAYBACK_MEDIA_OP_MAX) {
|
||||
ast_log(LOG_ERROR, "Invalid playback operation %u\n", operation);
|
||||
return -1;
|
||||
}
|
||||
|
@@ -212,7 +212,7 @@ enum ast_record_if_exists stasis_app_recording_if_exists_parse(
|
||||
return AST_RECORD_IF_EXISTS_APPEND;
|
||||
}
|
||||
|
||||
return -1;
|
||||
return AST_RECORD_IF_EXISTS_ERROR;
|
||||
}
|
||||
|
||||
static void recording_publish(struct stasis_app_recording *recording, const char *cause)
|
||||
@@ -595,13 +595,13 @@ enum stasis_app_recording_oper_results stasis_app_recording_operation(
|
||||
recording_operation_cb cb;
|
||||
SCOPED_AO2LOCK(lock, recording);
|
||||
|
||||
if (recording->state < 0 || recording->state >= STASIS_APP_RECORDING_STATE_MAX) {
|
||||
if (recording->state >= STASIS_APP_RECORDING_STATE_MAX) {
|
||||
ast_log(LOG_WARNING, "Invalid recording state %u\n",
|
||||
recording->state);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (operation < 0 || operation >= STASIS_APP_RECORDING_OPER_MAX) {
|
||||
if (operation >= STASIS_APP_RECORDING_OPER_MAX) {
|
||||
ast_log(LOG_WARNING, "Invalid recording operation %u\n",
|
||||
operation);
|
||||
return -1;
|
||||
|
Reference in New Issue
Block a user