From d7fd29385b85f38cfbef2849c850951cff681b20 Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Tue, 23 Jul 2019 15:36:30 -0400 Subject: [PATCH] `ctf` plugin: Use CTF_SCOPE_PACKET_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. get_root_scope_from_absolute_pathstr depends on the fact that CTF_SCOPE_PACKET_HEADER is 0 to work. Signed-off-by: Jonathan Rajotte Change-Id: Ie13f6c4dbab5038eb7a7fea6d58ce4451bc551d1 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1762 CI-Build: Philippe Proulx Tested-by: jenkins Reviewed-by: Philippe Proulx --- src/plugins/ctf/common/metadata/ctf-meta-resolve.c | 6 +++--- src/plugins/ctf/common/metadata/ctf-meta.h | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/plugins/ctf/common/metadata/ctf-meta-resolve.c b/src/plugins/ctf/common/metadata/ctf-meta-resolve.c index e2e5b3f2..630f14ed 100644 --- a/src/plugins/ctf/common/metadata/ctf-meta-resolve.c +++ b/src/plugins/ctf/common/metadata/ctf-meta-resolve.c @@ -265,14 +265,14 @@ enum ctf_scope get_root_scope_from_absolute_pathstr(const char *pathstr, struct resolve_context *ctx) { enum ctf_scope scope; - enum ctf_scope ret = -1; + enum ctf_scope ret = CTF_SCOPE_PACKET_UNKNOWN; const size_t prefixes_count = sizeof(absolute_path_prefixes) / sizeof(*absolute_path_prefixes); for (scope = CTF_SCOPE_PACKET_HEADER; scope < CTF_SCOPE_PACKET_HEADER + prefixes_count; scope++) { /* - * Chech if path string starts with a known absolute + * Check if path string starts with a known absolute * path prefix. * * Refer to CTF 7.3.2 STATIC AND DYNAMIC SCOPES. @@ -661,7 +661,7 @@ int pathstr_to_field_path(const char *pathstr, /* Absolute or relative path? */ root_scope = get_root_scope_from_absolute_pathstr(pathstr, ctx); - if (root_scope == -1) { + if (root_scope == CTF_SCOPE_PACKET_UNKNOWN) { /* Relative path: start with current root scope */ field_path->root = ctx->root_scope; BT_COMP_LOGD("Detected relative path: starting with current root scope: " diff --git a/src/plugins/ctf/common/metadata/ctf-meta.h b/src/plugins/ctf/common/metadata/ctf-meta.h index c5874ad1..8db2dee4 100644 --- a/src/plugins/ctf/common/metadata/ctf-meta.h +++ b/src/plugins/ctf/common/metadata/ctf-meta.h @@ -61,7 +61,8 @@ enum ctf_encoding { }; enum ctf_scope { - CTF_SCOPE_PACKET_HEADER, + CTF_SCOPE_PACKET_UNKNOWN = -1, + CTF_SCOPE_PACKET_HEADER = 0, CTF_SCOPE_PACKET_CONTEXT, CTF_SCOPE_EVENT_HEADER, CTF_SCOPE_EVENT_COMMON_CONTEXT, -- 2.34.1