`ctf` plugin: Use CTF_BYTE_ORDER_UNKNOWN in place of -1
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Tue, 23 Jul 2019 21:58:29 +0000 (17:58 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 30 Jul 2019 13:01:56 +0000 (09:01 -0400)
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 <jonathan.rajotte-julien@efficios.com>
Change-Id: I5dcbaa2066cbab8c429ff54e8d8b8b295fc8baf1
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1764
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/plugins/ctf/common/bfcr/bfcr.c
src/plugins/ctf/common/metadata/ctf-meta.h
src/plugins/ctf/common/metadata/visitor-generate-ir.c

index fc9b6699797f3e9719b8c4cfd64ceaa85d74d7c3..89e83ca479eeb03f71e6a0ede2a5226bbd8b3251 100644 (file)
@@ -116,8 +116,8 @@ struct bt_bfcr {
         * classes for which the common boundary is not the boundary of
         * a byte cannot have different byte orders.
         *
-        * This is set to -1 on reset and when the last basic field class
-        * was a string class.
+        * This is set to CTF_BYTE_ORDER_UNKNOWN on reset and when the last
+        * basic field class was a string class.
         */
        enum ctf_byte_order last_bo;
 
@@ -517,12 +517,12 @@ enum bt_bfcr_status validate_contiguous_bo(struct bt_bfcr *bfcr,
        }
 
        /* Always valid if last byte order is unknown */
-       if (bfcr->last_bo == -1) {
+       if (bfcr->last_bo == CTF_BYTE_ORDER_UNKNOWN) {
                goto end;
        }
 
        /* Always valid if next byte order is unknown */
-       if (next_bo == -1) {
+       if (next_bo == CTF_BYTE_ORDER_UNKNOWN) {
                goto end;
        }
 
@@ -1241,7 +1241,7 @@ void reset(struct bt_bfcr *bfcr)
        stack_clear(bfcr->stack);
        stitch_reset(bfcr);
        bfcr->buf.addr = NULL;
-       bfcr->last_bo = -1;
+       bfcr->last_bo = CTF_BYTE_ORDER_UNKNOWN;
 }
 
 static
index 8db2dee4ea6588a94d2f47834d06930793125ed4..5924346d7e30c1fccba5b0a3769b6c349fad1ef1 100644 (file)
@@ -50,6 +50,7 @@ enum ctf_field_class_meaning {
 };
 
 enum ctf_byte_order {
+       CTF_BYTE_ORDER_UNKNOWN,
        CTF_BYTE_ORDER_DEFAULT,
        CTF_BYTE_ORDER_LITTLE,
        CTF_BYTE_ORDER_BIG,
@@ -1636,7 +1637,7 @@ struct ctf_trace_class *ctf_trace_class_create(void)
        struct ctf_trace_class *tc = g_new0(struct ctf_trace_class, 1);
 
        BT_ASSERT(tc);
-       tc->default_byte_order = -1;
+       tc->default_byte_order = CTF_BYTE_ORDER_UNKNOWN;
        tc->clock_classes = g_ptr_array_new_with_free_func(
                (GDestroyNotify) ctf_clock_class_destroy);
        BT_ASSERT(tc->clock_classes);
index 9b0f16e674406ba319c698b660665395d5b4d613..0799ba19d2e5dedad760d31dba2cd61fc7853331 100644 (file)
@@ -1009,7 +1009,7 @@ enum ctf_byte_order byte_order_from_unary_expr(struct ctx *ctx,
                struct ctf_node *unary_expr)
 {
        const char *str;
-       enum ctf_byte_order bo = -1;
+       enum ctf_byte_order bo = CTF_BYTE_ORDER_UNKNOWN;
 
        if (unary_expr->u.unary_expression.type != UNARY_STRING) {
                _BT_COMP_LOGE_NODE(unary_expr,
@@ -2329,7 +2329,7 @@ int visit_integer_decl(struct ctx *ctx,
                        }
 
                        byte_order = get_real_byte_order(ctx, right);
-                       if (byte_order == -1) {
+                       if (byte_order == CTF_BYTE_ORDER_UNKNOWN) {
                                _BT_COMP_LOGE_NODE(right,
                                        "Invalid `byte_order` attribute in integer field class: "
                                        "ret=%d", ret);
@@ -2676,7 +2676,7 @@ int visit_floating_point_number_decl(struct ctx *ctx,
                        }
 
                        byte_order = get_real_byte_order(ctx, right);
-                       if (byte_order == -1) {
+                       if (byte_order == CTF_BYTE_ORDER_UNKNOWN) {
                                _BT_COMP_LOGE_NODE(right,
                                        "Invalid `byte_order` attribute in floating point number field class: "
                                        "ret=%d", ret);
@@ -3986,7 +3986,7 @@ int visit_trace_decl_entry(struct ctx *ctx, struct ctf_node *node, int *set)
                                goto error;
                        }
 
-                       BT_ASSERT(ctx->ctf_tc->default_byte_order != -1);
+                       BT_ASSERT(ctx->ctf_tc->default_byte_order != CTF_BYTE_ORDER_UNKNOWN);
                        _SET(set, _TRACE_BYTE_ORDER_SET);
                } else if (strcmp(left, "packet.header") == 0) {
                        if (_IS_SET(set, _TRACE_PACKET_HEADER_SET)) {
@@ -4232,7 +4232,7 @@ int set_trace_byte_order(struct ctx *ctx, struct ctf_node *trace_node)
                                        struct ctf_node, siblings);
                                bo = byte_order_from_unary_expr(ctx,
                                        right_node);
-                               if (bo == -1) {
+                               if (bo == CTF_BYTE_ORDER_UNKNOWN) {
                                        _BT_COMP_LOGE_NODE(node,
                                                "Invalid `byte_order` attribute in trace (`trace` block): "
                                                "expecting `le`, `be`, or `network`.");
@@ -4782,7 +4782,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
                 * have the native byte order yet, and we don't have any
                 * trace block yet, then fail with EINCOMPLETE.
                 */
-               if (ctx->ctf_tc->default_byte_order == -1) {
+               if (ctx->ctf_tc->default_byte_order == CTF_BYTE_ORDER_UNKNOWN) {
                        bt_list_for_each_entry(iter, &node->u.root.trace, siblings) {
                                if (got_trace_decl) {
                                        _BT_COMP_LOGE_NODE(node,
This page took 0.02995 seconds and 4 git commands to generate.