From bce81ff21251e1ce35e186f7b6996268a6943c6f Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Tue, 23 Jul 2019 15:55:12 -0400 Subject: [PATCH] src.ctf.lttng-live: Use SESSION_NOT_FOUND_ACTION_UNKNOWN in place of -1 Seen on clang-3.9, 4.0 and clang-1001.0.46.4. Comparison of constant -1 with expression of type 'enum *****' is always false [-Wtautological-constant-out-of-range-compare] Note that the enum underlying type is implementation defined and left to the choice of the compiler by the standard [1] (6.7.2.2 4). Most compiler default to unsigned int. The use of -1 is not a problem per see since wrap around of unsigned int behaviour is not undefined. Using -1 is the equivalent of assigning UINT_MAX here. This warning was removed for later clang for these specific cases since the effect of always being false is erroneous. Still, it make more sense to use a specific enum for such case instead of relying on the compiler type. Signed-off-by: Jonathan Rajotte Change-Id: I447d04333ae104ea953437b095053f341f87bbb7 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1763 CI-Build: Philippe Proulx Tested-by: jenkins Reviewed-by: Philippe Proulx --- src/plugins/ctf/lttng-live/lttng-live.c | 15 +++++++++++++-- src/plugins/ctf/lttng-live/lttng-live.h | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/plugins/ctf/lttng-live/lttng-live.c b/src/plugins/ctf/lttng-live/lttng-live.c index 62dc28f0..5946f064 100644 --- a/src/plugins/ctf/lttng-live/lttng-live.c +++ b/src/plugins/ctf/lttng-live/lttng-live.c @@ -1372,6 +1372,17 @@ bt_component_class_message_iterator_init_method_status lttng_live_msg_iter_init( SESS_NOT_FOUND_ACTION_END_STR, lttng_live->params.url->str); break; + case SESSION_NOT_FOUND_ACTION_UNKNOWN: + default: + /* Fallthrough */ + BT_COMP_LOGE("Unknown action for session not found" + "error. Fail the message iterator" + "initialization because of %s=\"%s\" " + "component parameter: url =\"%s\"", + SESS_NOT_FOUND_ACTION_PARAM, + SESS_NOT_FOUND_ACTION_FAIL_STR, + lttng_live->params.url->str); + break; } } @@ -1505,7 +1516,7 @@ enum session_not_found_action parse_session_not_found_action_param( } else if (strcmp(no_session_act_str, SESS_NOT_FOUND_ACTION_END_STR) == 0) { action = SESSION_NOT_FOUND_ACTION_END; } else { - action = -1; + action = SESSION_NOT_FOUND_ACTION_UNKNOWN; } return action; @@ -1545,7 +1556,7 @@ struct lttng_live_component *lttng_live_component_create(const bt_value *params, if (value && bt_value_is_string(value)) { lttng_live->params.sess_not_found_act = parse_session_not_found_action_param(value); - if (lttng_live->params.sess_not_found_act == -1) { + if (lttng_live->params.sess_not_found_act == SESSION_NOT_FOUND_ACTION_UNKNOWN) { BT_COMP_LOGE("Unexpected value for `%s` parameter: " "value=\"%s\"", SESS_NOT_FOUND_ACTION_PARAM, bt_value_string_get(value)); diff --git a/src/plugins/ctf/lttng-live/lttng-live.h b/src/plugins/ctf/lttng-live/lttng-live.h index 3ae12082..e5d08613 100644 --- a/src/plugins/ctf/lttng-live/lttng-live.h +++ b/src/plugins/ctf/lttng-live/lttng-live.h @@ -187,6 +187,7 @@ struct lttng_live_session { }; enum session_not_found_action { + SESSION_NOT_FOUND_ACTION_UNKNOWN, SESSION_NOT_FOUND_ACTION_CONTINUE, SESSION_NOT_FOUND_ACTION_FAIL, SESSION_NOT_FOUND_ACTION_END, -- 2.34.1