Replace all assert(false) and assert(0) with abort()
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 26 May 2017 05:02:18 +0000 (01:02 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:45 +0000 (12:57 -0400)
Because assert() statements are not executed with a release/production
build, assert(false) and assert(0) statements are ignored and the
program's execution continues in an unexpected state. This could lead to
very weird and hard-to-debug situations, and potentially to corrupted
output traces.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
18 files changed:
cli/babeltrace-cfg-cli-args-connect.c
cli/babeltrace-cfg-cli-args.c
cli/babeltrace.c
include/babeltrace/ctf-writer/serialize-internal.h
lib/ctf-ir/event-class.c
lib/ctf-ir/resolve.c
lib/ctf-ir/trace.c
lib/ctf-writer/serialize.c
lib/graph/connection.c
lib/graph/iterator.c
lib/plugin/plugin-so.c
plugins/ctf/common/btr/btr.c
plugins/ctf/common/notif-iter/notif-iter.c
plugins/ctf/fs-src/data-stream-file.c
plugins/utils/muxer/muxer.c
tests/lib/test_bt_notification_iterator.c
tests/lib/test_graph_topo.c
tests/plugins/test-utils-muxer.c

index 503e46af4ace2df60de685e051f85874d50693d3..0a29eb7a52f123638047fef21622db1b897d59f3 100644 (file)
@@ -20,6 +20,7 @@
  * SOFTWARE.
  */
 
+#include <stdlib.h>
 #include <babeltrace/values.h>
 #include <babeltrace/common-internal.h>
 #include "babeltrace-cfg.h"
@@ -268,7 +269,7 @@ static struct bt_config_connection *cfg_connection_from_arg(const char *arg)
                        }
                        break;
                default:
-                       assert(false);
+                       abort();
                }
        }
 
index e1208451e9491da73a65dda24648d2c3b02c07a6..64f196e5a668ec494192e97d78853bc781fca846 100644 (file)
@@ -405,7 +405,7 @@ int ini_handle_state(struct ini_parsing_state *state)
                state->expecting = INI_EXPECT_MAP_KEY;
                goto success;
        default:
-               assert(false);
+               abort();
        }
 
 error:
@@ -889,7 +889,7 @@ void bt_config_destroy(struct bt_object *obj)
                }
                break;
        default:
-               assert(false);
+               abort();
        }
 
        g_free(cfg);
@@ -1336,7 +1336,7 @@ void add_run_cfg_comp(struct bt_config *cfg,
                g_ptr_array_add(cfg->cmd_data.run.sinks, cfg_comp);
                break;
        default:
-               assert(false);
+               abort();
        }
 }
 
@@ -1855,7 +1855,7 @@ struct bt_config *bt_config_help_from_args(int argc, const char *argv[],
                                        BT_COMPONENT_CLASS_TYPE_SINK;
                                break;
                        default:
-                               assert(false);
+                               abort();
                        }
                        plug_comp_cls_names = strdup(arg);
                        if (!plug_comp_cls_names) {
@@ -2068,7 +2068,7 @@ struct bt_config *bt_config_query_from_args(int argc, const char *argv[],
                                type = BT_COMPONENT_CLASS_TYPE_SINK;
                                break;
                        default:
-                               assert(false);
+                               abort();
                        }
 
                        cfg->cmd_data.query.cfg_component =
@@ -2536,7 +2536,7 @@ struct bt_config *bt_config_run_from_args(int argc, const char *argv[],
                                opt_name = "--sink";
                                break;
                        default:
-                               assert(false);
+                               abort();
                        }
 
                        if (cur_cfg_comp) {
@@ -3085,7 +3085,7 @@ int append_run_args_for_implicit_component(
                }
                break;
        default:
-               assert(false);
+               abort();
        }
 
        if (bt_value_array_append_string(run_args,
@@ -3322,7 +3322,7 @@ int convert_append_name_param(enum bt_config_component_dest dest,
                        *sink_names = g_list_append(*sink_names, name);
                        break;
                default:
-                       assert(false);
+                       abort();
                }
 
                g_string_assign(cur_name_prefix, "");
@@ -3754,7 +3754,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                                }
                                break;
                        default:
-                               assert(false);
+                               abort();
                        }
 
                        if (bt_value_array_append_string(run_args, arg)) {
@@ -4759,7 +4759,7 @@ struct bt_config *bt_config_cli_args_create(int argc, const char *argv[],
                        force_omit_home_plugin_path, initial_plugin_paths);
                break;
        default:
-               assert(false);
+               abort();
        }
 
        if (config) {
index 27516cd0829c224eda25e4f26e88bdf1238b2e21..3d37d4e01010d941def39933ab403f28aa1ff7eb 100644 (file)
@@ -366,7 +366,7 @@ void print_value_rec(FILE *fp, struct bt_value *value, size_t indent)
                break;
        }
        default:
-               assert(false);
+               abort();
        }
 }
 
@@ -519,7 +519,7 @@ void print_cfg(struct bt_config *cfg)
                print_cfg_print_lttng_live_sessions(cfg);
                break;
        default:
-               assert(false);
+               abort();
        }
 }
 
@@ -1203,7 +1203,7 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component(
                 */
                BT_LOGF("Invalid connection: downstream component is a source: "
                        "conn-arg=\"%s\"", cfg_conn->arg->str);
-               assert(false);
+               abort();
        }
 
        downstream_port_count = port_count_fn(downstream_comp);
@@ -1962,8 +1962,8 @@ int main(int argc, const char **argv)
                ret = cmd_print_lttng_live_sessions(cfg);
                break;
        default:
-               BT_LOGF("Invalid command: cmd=%d", cfg->command);
-               assert(false);
+               BT_LOGF("Invalid/unknown command: cmd=%d", cfg->command);
+               abort();
        }
 
        BT_LOGI("Command completed: cmd=%d, command-name=\"%s\", ret=%d",
index 39cb791361aa47bd818ccf8ea6dbed78023d1b93..5cf8c5bd660a787a54d7f61df37df993dff5371b 100644 (file)
@@ -26,6 +26,7 @@
  * http://www.efficios.com/ctf
  */
 
+#include <stdlib.h>
 #include <stdint.h>
 #include <limits.h>
 #include <sys/mman.h>
@@ -131,7 +132,7 @@ int bt_ctf_stream_pos_init(struct bt_ctf_stream_pos *pos,
                pos->flags = MAP_SHARED;
                break;
        default:
-               assert(BT_FALSE);
+               abort();
        }
 
        return 0;
index 4381d051db7eb2557d6f9baac36b21c3ccf1e2a6..3fc60603103bdda8f4d63e7aaf732b8c294fdbb0 100644 (file)
@@ -45,6 +45,7 @@
 #include <babeltrace/types.h>
 #include <babeltrace/values-internal.h>
 #include <inttypes.h>
+#include <stdlib.h>
 
 static
 void bt_ctf_event_class_destroy(struct bt_object *obj);
@@ -876,7 +877,7 @@ int bt_ctf_event_class_serialize(struct bt_ctf_event_class *event_class,
 
                default:
                        /* should never happen */
-                       assert(BT_FALSE);
+                       abort();
                        break;
                }
 
index 6b4b889a7da322a2aed3552c955f64b0b227c0c1..139ed792c78da60cd47a70857b041522a2f24be2 100644 (file)
@@ -44,6 +44,7 @@
 #include <babeltrace/types.h>
 #include <limits.h>
 #include <inttypes.h>
+#include <stdlib.h>
 #include <glib.h>
 
 typedef GPtrArray type_stack;
@@ -979,7 +980,7 @@ int validate_target_field_path(struct bt_ctf_field_path *target_field_path,
                        goto end;
                }
        } else {
-               assert(BT_FALSE);
+               abort();
        }
 
 end:
@@ -1016,9 +1017,7 @@ int resolve_sequence_or_variant_type(struct bt_ctf_field_type *type,
                        bt_ctf_field_type_variant_get_tag_name(type);
                break;
        default:
-               assert(BT_FALSE);
-               ret = -1;
-               goto end;
+               abort();
        }
 
        /* Get target field path out of path string */
@@ -1084,7 +1083,7 @@ int resolve_sequence_or_variant_type(struct bt_ctf_field_type *type,
                        goto end;
                }
        } else {
-               assert(BT_FALSE);
+               abort();
        }
 
 end:
index 890e12c4d1ad67c01a2fd64cc164d4e4ee938396..bcba9b1dca28cda36e2fd5e2811f8e5afa695c04 100644 (file)
@@ -52,6 +52,7 @@
 #include <inttypes.h>
 #include <stdint.h>
 #include <string.h>
+#include <stdlib.h>
 
 #define DEFAULT_IDENTIFIER_SIZE 128
 #define DEFAULT_METADATA_STRING_SIZE 4096
@@ -1630,7 +1631,7 @@ const char *get_byte_order_string(enum bt_ctf_byte_order byte_order)
                string = "native";
                break;
        default:
-               assert(BT_FALSE);
+               abort();
        }
 
        return string;
index 427c2c5a96fd5c8a03c6c46bcd6b33ad26129911..f20ad405cb99cdcebbb76ac1a4f9ae0c53d9e6a7 100644 (file)
@@ -28,6 +28,7 @@
  * SOFTWARE.
  */
 
+#include <stdlib.h>
 #include <stdio.h>
 #include <stdint.h>
 #include <babeltrace/ctf-ir/field-types.h>
@@ -108,7 +109,7 @@ int aligned_integer_write(struct bt_ctf_stream_pos *pos,
                        break;
                }
                default:
-                       assert(BT_FALSE);
+                       abort();
                }
        } else {
                switch (size) {
@@ -147,7 +148,7 @@ int aligned_integer_write(struct bt_ctf_stream_pos *pos,
                        break;
                }
                default:
-                       assert(BT_FALSE);
+                       abort();
                }
        }
 
@@ -275,7 +276,8 @@ void bt_ctf_stream_pos_packet_seek(struct bt_ctf_stream_pos *pos, size_t index,
                /* unmap old base */
                ret = munmap_align(pos->base_mma);
                if (ret) {
-                       assert(BT_FALSE);
+                       // FIXME: this can legitimately fail?
+                       abort();
                }
                pos->base_mma = NULL;
        }
@@ -294,6 +296,7 @@ void bt_ctf_stream_pos_packet_seek(struct bt_ctf_stream_pos *pos, size_t index,
        pos->base_mma = mmap_align(pos->packet_size / CHAR_BIT, pos->prot,
                pos->flags, pos->fd, pos->mmap_offset);
        if (pos->base_mma == MAP_FAILED) {
-               assert(BT_FALSE);
+               // FIXME: this can legitimately fail?
+               abort();
        }
 }
index 896ce27085700985e086a7af411a14a6606996e4..b0f64aeb871403965c0fbcb88a2235a2a93ca636 100644 (file)
@@ -39,6 +39,7 @@
 #include <babeltrace/graph/port-internal.h>
 #include <babeltrace/object-internal.h>
 #include <babeltrace/compiler-internal.h>
+#include <stdlib.h>
 #include <glib.h>
 
 static
@@ -354,7 +355,7 @@ bt_private_connection_create_notification_iterator(
        }
        default:
                /* Unreachable. */
-               assert(0);
+               abort();
        }
 
        if (init_method) {
index 2428c72b68d4296433b6c201e416b0449d450619..1a295cb3c4f1865cf92dc59267c4ffa1eeb987b1 100644 (file)
@@ -50,6 +50,7 @@
 #include <babeltrace/graph/port.h>
 #include <babeltrace/types.h>
 #include <stdint.h>
+#include <stdlib.h>
 
 struct stream_state {
        struct bt_ctf_stream *stream; /* owned by this */
@@ -149,7 +150,7 @@ void destroy_action(struct action *action)
        case ACTION_TYPE_SET_STREAM_STATE_IS_ENDED:
                break;
        default:
-               assert(BT_FALSE);
+               abort();
        }
 }
 
@@ -261,7 +262,7 @@ void apply_actions(struct bt_notification_iterator *iterator)
                                action->payload.set_stream_state_cur_packet.packet);
                        break;
                default:
-                       assert(BT_FALSE);
+                       abort();
                }
        }
 
@@ -428,7 +429,7 @@ void bt_notification_iterator_finalize(
        }
        default:
                /* Unreachable */
-               assert(0);
+               abort();
        }
 
        if (finalize_method) {
@@ -664,7 +665,7 @@ bt_notification_iterator_notif_type_from_notif_type(
                iter_notif_type = BT_NOTIFICATION_ITERATOR_NOTIF_TYPE_PACKET_END;
                break;
        default:
-               assert(BT_FALSE);
+               abort();
        }
 
        return iter_notif_type;
@@ -1521,8 +1522,7 @@ enum bt_notification_iterator_status ensure_queue_has_notifications(
                break;
        }
        default:
-               assert(BT_FALSE);
-               break;
+               abort();
        }
 
        /*
@@ -1596,7 +1596,7 @@ enum bt_notification_iterator_status ensure_queue_has_notifications(
                        break;
                default:
                        /* Unknown non-error status */
-                       assert(BT_FALSE);
+                       abort();
                }
        }
 
index 4c390b76e53f8d15067876d8c41d6274732d9707..f1fa9f71b2a37a298f773ad234c9d5eae372ad70 100644 (file)
@@ -36,6 +36,7 @@
 #include <babeltrace/graph/component-class-internal.h>
 #include <babeltrace/types.h>
 #include <string.h>
+#include <stdlib.h>
 #include <glib.h>
 #include <gmodule.h>
 
@@ -635,8 +636,7 @@ enum bt_plugin_status bt_plugin_so_init(
                case BT_COMPONENT_CLASS_TYPE_SINK:
                        break;
                default:
-                       assert(BT_FALSE);
-                       break;
+                       abort();
                }
 
                /*
index 7e7cf37b956fb3d524a0863f26ea46d73c81c6a5..0f4c1be1e7d8fa1805b6051e42f28f571d43d607 100644 (file)
@@ -23,6 +23,7 @@
  * SOFTWARE.
  */
 
+#include <stdlib.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stddef.h>
@@ -999,7 +1000,7 @@ enum bt_ctf_btr_status read_basic_begin_state(struct bt_ctf_btr *btr)
                status = read_basic_string_type_and_call(btr, true);
                break;
        default:
-               assert(false);
+               abort();
        }
 
        return status;
@@ -1026,7 +1027,7 @@ enum bt_ctf_btr_status read_basic_continue_state(struct bt_ctf_btr *btr)
                status = read_basic_string_type_and_call(btr, false);
                break;
        default:
-               assert(false);
+               abort();
        }
 
        return status;
index acb349380c3fa626328b9805300bb38d2f97a4d0..b2aa08e44333eaf9dc2be5d77d889ed38d310a8c 100644 (file)
@@ -44,6 +44,7 @@
 #include <babeltrace/graph/clock-class-priority-map.h>
 #include <babeltrace/ref.h>
 #include <glib.h>
+#include <stdlib.h>
 
 #define PRINT_ERR_STREAM       notit->err_stream
 #define PRINT_PREFIX           "ctf-notif-iter"
@@ -1397,8 +1398,7 @@ struct bt_ctf_field *get_next_field(struct bt_ctf_notif_iter *notit)
                next_field = bt_ctf_field_variant_get_current_field(base_field);
                break;
        default:
-               assert(false);
-               break;
+               abort();
        }
 
 end:
@@ -1541,9 +1541,7 @@ enum bt_ctf_btr_status btr_unsigned_int_common(uint64_t value,
                type = bt_ctf_field_get_type(int_field);
                break;
        default:
-               assert(0);
-               type = NULL;
-               break;
+               abort();
        }
 
        if (!int_field) {
@@ -1636,9 +1634,7 @@ enum bt_ctf_btr_status btr_signed_int_cb(int64_t value,
                type = bt_ctf_field_get_type(int_field);
                break;
        default:
-               assert(0);
-               type = NULL;
-               break;
+               abort();
        }
 
        if (!int_field) {
@@ -2500,7 +2496,7 @@ enum bt_ctf_notif_iter_status bt_ctf_notif_iter_get_packet_header_context_fields
                         * We should never get past the
                         * STATE_EMIT_NOTIF_NEW_PACKET state.
                         */
-                       assert(false);
+                       abort();
                }
        }
 
index bf3dda60839051fa614f900196e1cda1d32a8964..2859ffbe2bd9d01e7ce62b4548922cbe9fec4b04 100644 (file)
@@ -22,6 +22,7 @@
  * SOFTWARE.
  */
 
+#include <stdlib.h>
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
@@ -465,7 +466,7 @@ struct bt_notification_iterator_next_return ctf_fs_ds_file_next(
                 * medium-specific; there is nothing for the user to do
                 * and it should have been handled upstream.
                 */
-               assert(false);
+               abort();
        case BT_CTF_NOTIF_ITER_STATUS_INVAL:
        case BT_CTF_NOTIF_ITER_STATUS_ERROR:
        default:
@@ -498,7 +499,7 @@ int ctf_fs_ds_file_get_packet_header_context_fields(
        case BT_CTF_NOTIF_ITER_STATUS_OK:
                break;
        case BT_CTF_NOTIF_ITER_STATUS_AGAIN:
-               assert(false);
+               abort();
        case BT_CTF_NOTIF_ITER_STATUS_INVAL:
        case BT_CTF_NOTIF_ITER_STATUS_ERROR:
        default:
index e0553423a927ead2e2d0cf6a13bd06e24e349b82..533ccfaa5f937b4a5341b4b66b8d84b8134caf1d 100644 (file)
@@ -41,6 +41,7 @@
 #include <glib.h>
 #include <stdbool.h>
 #include <assert.h>
+#include <stdlib.h>
 
 #define IGNORE_ABSOLUTE_PARAM_NAME     "ignore-absolute"
 
@@ -566,7 +567,7 @@ int get_notif_ts_ns(struct muxer_comp *muxer_comp,
                        notif, clock_class);
                break;
        default:
-               assert(false);
+               abort();
        }
 
        if (!clock_value) {
index 656d84ac7d965ef234f9974354b9a4f44b3e5ca0..5ee5915bb7a4a23ca0ee132ddf4a5cb6547ff764 100644 (file)
@@ -548,7 +548,7 @@ enum bt_notification_iterator_status src_iter_init(
                user_data->seq = seq_multiple_auto_packet_end_stream_end_from_end;
                break;
        default:
-               assert(false);
+               abort();
        }
 
        return BT_NOTIFICATION_ITERATOR_STATUS_OK;
@@ -662,7 +662,7 @@ struct bt_notification_iterator_next_return src_iter_next_seq(
                event_packet = src_stream2_packet2;
                break;
        default:
-               assert(false);
+               abort();
        }
 
        if (event_packet) {
@@ -745,7 +745,7 @@ enum bt_component_status sink_consume(
                BT_PUT(user_data->notif_iter);
                goto end;
        case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN:
-               assert(false);
+               abort();
        default:
                break;
        }
index 058da9e8ce6783e85abfa3bf58d1ce1c8ce81431..0d6d6edb28d22f1b7fd016ce07d106aee509f6f8 100644 (file)
@@ -245,7 +245,7 @@ bool compare_events(struct event *ev_a, struct event *ev_b)
                        }
                        break;
                default:
-                       assert(false);
+                       abort();
        }
 
        return true;
index f5eac77c29b831e04ae84d7967c8ef56c5b1815b..64a58d811499cd811dad2122cdd0f586b8c61442 100644 (file)
@@ -462,7 +462,7 @@ enum bt_notification_iterator_status src_iter_init(
                user_data->packet = src_packet3;
                break;
        default:
-               assert(false);
+               abort();
        }
 
        switch (current_test) {
@@ -504,7 +504,7 @@ enum bt_notification_iterator_status src_iter_init(
                }
                break;
        default:
-               assert(false);
+               abort();
        }
 
        return BT_NOTIFICATION_ITERATOR_STATUS_OK;
@@ -674,7 +674,7 @@ struct bt_notification_iterator_next_return src_iter_next(
                }
                break;
        default:
-               assert(false);
+               abort();
        }
 
        bt_put(private_component);
This page took 0.038438 seconds and 4 git commands to generate.