diff options
author | Diederik de Groot <ddegroot@talon.nl> | 2015-04-23 15:00:42 +0200 |
---|---|---|
committer | Diederik de Groot <ddegroot@talon.nl> | 2015-04-23 18:26:55 +0200 |
commit | 1bb16bedc72d5cf6fc95cda3bd60c440285575d7 (patch) | |
tree | 3b5d7f82d6103c7c10c8f02393f7126ae0b7e481 | |
parent | d08446ec36600348090eb2451c5a9a7aadd633de (diff) |
Clang: change previous tautological-compare fixes.
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: I0557ae0154a0b7de68883848a609309cdf0aee6a
-rw-r--r-- | main/event.c | 2 | ||||
-rw-r--r-- | main/security_events.c | 6 | ||||
-rw-r--r-- | res/res_stasis_playback.c | 2 | ||||
-rw-r--r-- | res/res_stasis_recording.c | 4 |
4 files changed, 7 insertions, 7 deletions
diff --git a/main/event.c b/main/event.c index 8880b9699..019dfcac0 100644 --- a/main/event.c +++ b/main/event.c @@ -199,7 +199,7 @@ const char *ast_event_get_type_name(const struct ast_event *event) type = ast_event_get_type(event); - if (type >= ARRAY_LEN(event_names)) { + if ((unsigned int)type >= ARRAY_LEN(event_names)) { ast_log(LOG_ERROR, "Invalid event type - '%u'\n", type); return ""; } diff --git a/main/security_events.c b/main/security_events.c index 5a8df66d1..d549d6201 100644 --- a/main/security_events.c +++ b/main/security_events.c @@ -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; @@ -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 >= AST_SECURITY_EVENT_NUM_TYPES) { + if ((unsigned int)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 >= AST_SECURITY_EVENT_NUM_TYPES) { + if ((unsigned int)sec->event_type >= AST_SECURITY_EVENT_NUM_TYPES) { ast_log(LOG_ERROR, "Invalid security event type\n"); return -1; } diff --git a/res/res_stasis_playback.c b/res/res_stasis_playback.c index 2eac55f19..dc6e8f2b8 100644 --- a/res/res_stasis_playback.c +++ b/res/res_stasis_playback.c @@ -629,7 +629,7 @@ enum stasis_playback_oper_results stasis_app_playback_operation( playback_opreation_cb cb; SCOPED_AO2LOCK(lock, playback); - ast_assert(playback->state < STASIS_PLAYBACK_STATE_MAX); + ast_assert((unsigned int)playback->state < STASIS_PLAYBACK_STATE_MAX); if (operation >= STASIS_PLAYBACK_MEDIA_OP_MAX) { ast_log(LOG_ERROR, "Invalid playback operation %u\n", operation); diff --git a/res/res_stasis_recording.c b/res/res_stasis_recording.c index df7f8b33a..50e0697b1 100644 --- a/res/res_stasis_recording.c +++ b/res/res_stasis_recording.c @@ -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 >= STASIS_APP_RECORDING_STATE_MAX) { + if ((unsigned int)recording->state >= STASIS_APP_RECORDING_STATE_MAX) { ast_log(LOG_WARNING, "Invalid recording state %u\n", recording->state); return -1; } - if (operation >= STASIS_APP_RECORDING_OPER_MAX) { + if ((unsigned int)operation >= STASIS_APP_RECORDING_OPER_MAX) { ast_log(LOG_WARNING, "Invalid recording operation %u\n", operation); return -1; |