From 0fbb9a9fffe22e0d5211a47118102fa0ba4a766a Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Fri, 26 May 2017 01:02:18 -0400 Subject: [PATCH] Replace all assert(false) and assert(0) with abort() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Jérémie Galarneau --- cli/babeltrace-cfg-cli-args-connect.c | 3 ++- cli/babeltrace-cfg-cli-args.c | 20 +++++++++---------- cli/babeltrace.c | 10 +++++----- .../ctf-writer/serialize-internal.h | 3 ++- lib/ctf-ir/event-class.c | 3 ++- lib/ctf-ir/resolve.c | 9 ++++----- lib/ctf-ir/trace.c | 3 ++- lib/ctf-writer/serialize.c | 11 ++++++---- lib/graph/connection.c | 3 ++- lib/graph/iterator.c | 14 ++++++------- lib/plugin/plugin-so.c | 4 ++-- plugins/ctf/common/btr/btr.c | 5 +++-- plugins/ctf/common/notif-iter/notif-iter.c | 14 +++++-------- plugins/ctf/fs-src/data-stream-file.c | 5 +++-- plugins/utils/muxer/muxer.c | 3 ++- tests/lib/test_bt_notification_iterator.c | 6 +++--- tests/lib/test_graph_topo.c | 2 +- tests/plugins/test-utils-muxer.c | 6 +++--- 18 files changed, 65 insertions(+), 59 deletions(-) diff --git a/cli/babeltrace-cfg-cli-args-connect.c b/cli/babeltrace-cfg-cli-args-connect.c index 503e46af..0a29eb7a 100644 --- a/cli/babeltrace-cfg-cli-args-connect.c +++ b/cli/babeltrace-cfg-cli-args-connect.c @@ -20,6 +20,7 @@ * SOFTWARE. */ +#include #include #include #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(); } } diff --git a/cli/babeltrace-cfg-cli-args.c b/cli/babeltrace-cfg-cli-args.c index e1208451..64f196e5 100644 --- a/cli/babeltrace-cfg-cli-args.c +++ b/cli/babeltrace-cfg-cli-args.c @@ -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) { diff --git a/cli/babeltrace.c b/cli/babeltrace.c index 27516cd0..3d37d4e0 100644 --- a/cli/babeltrace.c +++ b/cli/babeltrace.c @@ -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", diff --git a/include/babeltrace/ctf-writer/serialize-internal.h b/include/babeltrace/ctf-writer/serialize-internal.h index 39cb7913..5cf8c5bd 100644 --- a/include/babeltrace/ctf-writer/serialize-internal.h +++ b/include/babeltrace/ctf-writer/serialize-internal.h @@ -26,6 +26,7 @@ * http://www.efficios.com/ctf */ +#include #include #include #include @@ -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; diff --git a/lib/ctf-ir/event-class.c b/lib/ctf-ir/event-class.c index 4381d051..3fc60603 100644 --- a/lib/ctf-ir/event-class.c +++ b/lib/ctf-ir/event-class.c @@ -45,6 +45,7 @@ #include #include #include +#include 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; } diff --git a/lib/ctf-ir/resolve.c b/lib/ctf-ir/resolve.c index 6b4b889a..139ed792 100644 --- a/lib/ctf-ir/resolve.c +++ b/lib/ctf-ir/resolve.c @@ -44,6 +44,7 @@ #include #include #include +#include #include 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: diff --git a/lib/ctf-ir/trace.c b/lib/ctf-ir/trace.c index 890e12c4..bcba9b1d 100644 --- a/lib/ctf-ir/trace.c +++ b/lib/ctf-ir/trace.c @@ -52,6 +52,7 @@ #include #include #include +#include #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; diff --git a/lib/ctf-writer/serialize.c b/lib/ctf-writer/serialize.c index 427c2c5a..f20ad405 100644 --- a/lib/ctf-writer/serialize.c +++ b/lib/ctf-writer/serialize.c @@ -28,6 +28,7 @@ * SOFTWARE. */ +#include #include #include #include @@ -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(); } } diff --git a/lib/graph/connection.c b/lib/graph/connection.c index 896ce270..b0f64aeb 100644 --- a/lib/graph/connection.c +++ b/lib/graph/connection.c @@ -39,6 +39,7 @@ #include #include #include +#include #include static @@ -354,7 +355,7 @@ bt_private_connection_create_notification_iterator( } default: /* Unreachable. */ - assert(0); + abort(); } if (init_method) { diff --git a/lib/graph/iterator.c b/lib/graph/iterator.c index 2428c72b..1a295cb3 100644 --- a/lib/graph/iterator.c +++ b/lib/graph/iterator.c @@ -50,6 +50,7 @@ #include #include #include +#include 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(); } } diff --git a/lib/plugin/plugin-so.c b/lib/plugin/plugin-so.c index 4c390b76..f1fa9f71 100644 --- a/lib/plugin/plugin-so.c +++ b/lib/plugin/plugin-so.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -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(); } /* diff --git a/plugins/ctf/common/btr/btr.c b/plugins/ctf/common/btr/btr.c index 7e7cf37b..0f4c1be1 100644 --- a/plugins/ctf/common/btr/btr.c +++ b/plugins/ctf/common/btr/btr.c @@ -23,6 +23,7 @@ * SOFTWARE. */ +#include #include #include #include @@ -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; diff --git a/plugins/ctf/common/notif-iter/notif-iter.c b/plugins/ctf/common/notif-iter/notif-iter.c index acb34938..b2aa08e4 100644 --- a/plugins/ctf/common/notif-iter/notif-iter.c +++ b/plugins/ctf/common/notif-iter/notif-iter.c @@ -44,6 +44,7 @@ #include #include #include +#include #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(); } } diff --git a/plugins/ctf/fs-src/data-stream-file.c b/plugins/ctf/fs-src/data-stream-file.c index bf3dda60..2859ffbe 100644 --- a/plugins/ctf/fs-src/data-stream-file.c +++ b/plugins/ctf/fs-src/data-stream-file.c @@ -22,6 +22,7 @@ * SOFTWARE. */ +#include #include #include #include @@ -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: diff --git a/plugins/utils/muxer/muxer.c b/plugins/utils/muxer/muxer.c index e0553423..533ccfaa 100644 --- a/plugins/utils/muxer/muxer.c +++ b/plugins/utils/muxer/muxer.c @@ -41,6 +41,7 @@ #include #include #include +#include #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) { diff --git a/tests/lib/test_bt_notification_iterator.c b/tests/lib/test_bt_notification_iterator.c index 656d84ac..5ee5915b 100644 --- a/tests/lib/test_bt_notification_iterator.c +++ b/tests/lib/test_bt_notification_iterator.c @@ -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; } diff --git a/tests/lib/test_graph_topo.c b/tests/lib/test_graph_topo.c index 058da9e8..0d6d6edb 100644 --- a/tests/lib/test_graph_topo.c +++ b/tests/lib/test_graph_topo.c @@ -245,7 +245,7 @@ bool compare_events(struct event *ev_a, struct event *ev_b) } break; default: - assert(false); + abort(); } return true; diff --git a/tests/plugins/test-utils-muxer.c b/tests/plugins/test-utils-muxer.c index f5eac77c..64a58d81 100644 --- a/tests/plugins/test-utils-muxer.c +++ b/tests/plugins/test-utils-muxer.c @@ -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); -- 2.34.1