From 5084732e40a7925d22f741e4ed08f19d36078fbe Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Tue, 23 Jul 2019 12:23:35 -0400 Subject: [PATCH] Standardize `!ptr` i/o `ptr == NULL`, `ptr` i/o `ptr != NULL` Signed-off-by: Philippe Proulx Change-Id: I3e47fe9ca121cf3fc4f71e6292b9fa9efc6df341 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1746 Tested-by: jenkins --- .../bt2/bt2/native_bt_component_class.i | 2 +- src/bindings/python/bt2/bt2/native_bt_trace.i | 2 +- .../python/bt2/bt2/native_bt_trace_class.i | 2 +- src/cli/babeltrace2-cfg-cli-args.c | 8 +++---- src/cli/babeltrace2-cfg-cli-params-arg.c | 2 +- src/cli/babeltrace2-cfg-src-auto-disc.c | 2 +- src/compat/memstream.h | 4 ++-- src/compat/mman.c | 4 ++-- src/compat/stdio.h | 6 ++--- src/ctf-writer/assert-pre.h | 2 +- src/ctf-writer/fields.h | 2 +- src/ctf-writer/stream.c | 4 ++-- src/lib/assert-pre.h | 2 +- src/lib/graph/message/event.c | 2 +- src/lib/plugin/plugin-so.c | 8 +++---- src/lib/plugin/plugin.c | 2 +- src/lib/trace-ir/field.c | 2 +- src/lib/trace-ir/trace-class.c | 2 +- src/lib/trace-ir/trace.c | 4 ++-- .../decoder-packetized-file-stream-to-buf.c | 2 +- src/plugins/ctf/common/metadata/parser.y | 2 +- .../ctf/common/metadata/visitor-generate-ir.c | 16 +++++++------- .../metadata/visitor-semantic-validator.c | 2 +- src/plugins/ctf/fs-src/fs.c | 2 +- src/plugins/ctf/lttng-live/lttng-live.c | 4 ++-- .../ctf/lttng-live/viewer-connection.c | 8 +++---- .../lttng-utils/debug-info/debug-info.c | 2 +- src/plugins/text/details/obj-lifetime-mgmt.c | 4 ++-- src/py-common/py-common.c | 4 ++-- tests/ctf-writer/ctf_writer.c | 12 +++++----- .../test_bin_info.c | 22 +++++++++---------- .../flt.lttng-utils.debug-info/test_dwarf.c | 14 ++++++------ 32 files changed, 78 insertions(+), 78 deletions(-) diff --git a/src/bindings/python/bt2/bt2/native_bt_component_class.i b/src/bindings/python/bt2/bt2/native_bt_component_class.i index 42feccf5..4b718015 100644 --- a/src/bindings/python/bt2/bt2/native_bt_component_class.i +++ b/src/bindings/python/bt2/bt2/native_bt_component_class.i @@ -181,7 +181,7 @@ void log_exception_and_maybe_append_error(int log_level, { GString *gstr; - BT_ASSERT(PyErr_Occurred() != NULL); + BT_ASSERT(PyErr_Occurred()); gstr = bt_py_common_format_exception(BT_LOG_OUTPUT_LEVEL); if (!gstr) { /* bt_py_common_format_exception() logs errors */ diff --git a/src/bindings/python/bt2/bt2/native_bt_trace.i b/src/bindings/python/bt2/bt2/native_bt_trace.i index 3e27a368..3448f646 100644 --- a/src/bindings/python/bt2/bt2/native_bt_trace.i +++ b/src/bindings/python/bt2/bt2/native_bt_trace.i @@ -40,7 +40,7 @@ trace_destroyed_listener(const bt_trace *trace, void *py_callable) } py_res = PyObject_CallFunction(py_callable, "(O)", py_trace_ptr); - if (py_res != NULL) { + if (py_res) { BT_ASSERT(py_res == Py_None); } else { loge_exception(); diff --git a/src/bindings/python/bt2/bt2/native_bt_trace_class.i b/src/bindings/python/bt2/bt2/native_bt_trace_class.i index 57166bc9..fd48deeb 100644 --- a/src/bindings/python/bt2/bt2/native_bt_trace_class.i +++ b/src/bindings/python/bt2/bt2/native_bt_trace_class.i @@ -41,7 +41,7 @@ trace_class_destroyed_listener(const bt_trace_class *trace_class, void *py_calla } py_res = PyObject_CallFunction(py_callable, "(O)", py_trace_class_ptr); - if (py_res != NULL) { + if (py_res) { BT_ASSERT(py_res == Py_None); } else { loge_exception(); diff --git a/src/cli/babeltrace2-cfg-cli-args.c b/src/cli/babeltrace2-cfg-cli-args.c index 7fc04884..a16fbfce 100644 --- a/src/cli/babeltrace2-cfg-cli-args.c +++ b/src/cli/babeltrace2-cfg-cli-args.c @@ -506,7 +506,7 @@ void destroy_glist_of_gstring(GList *list) return; } - for (at = list; at != NULL; at = g_list_next(at)) { + for (at = list; at; at = g_list_next(at)) { g_string_free(at->data, TRUE); } @@ -3162,7 +3162,7 @@ int convert_auto_connect(bt_value *run_args, BT_ASSERT(sink_names); /* Connect all sources to the first filter */ - for (source_at = source_names; source_at != NULL; source_at = g_list_next(source_at)) { + for (source_at = source_names; source_at; source_at = g_list_next(source_at)) { GString *source_name = source_at->data; GString *filter_name = filter_at->data; @@ -3177,7 +3177,7 @@ int convert_auto_connect(bt_value *run_args, filter_at = g_list_next(filter_at); /* Connect remaining filters */ - for (; filter_at != NULL; filter_prev = filter_at, filter_at = g_list_next(filter_at)) { + for (; filter_at; filter_prev = filter_at, filter_at = g_list_next(filter_at)) { GString *filter_name = filter_at->data; GString *filter_prev_name = filter_prev->data; @@ -3189,7 +3189,7 @@ int convert_auto_connect(bt_value *run_args, } /* Connect last filter to all sinks */ - for (sink_at = sink_names; sink_at != NULL; sink_at = g_list_next(sink_at)) { + for (sink_at = sink_names; sink_at; sink_at = g_list_next(sink_at)) { GString *filter_name = filter_prev->data; GString *sink_name = sink_at->data; diff --git a/src/cli/babeltrace2-cfg-cli-params-arg.c b/src/cli/babeltrace2-cfg-cli-params-arg.c index d69ee822..b13172d0 100644 --- a/src/cli/babeltrace2-cfg-cli-params-arg.c +++ b/src/cli/babeltrace2-cfg-cli-params-arg.c @@ -87,7 +87,7 @@ void ini_append_error_expecting(struct ini_parsing_state *state, g_string_append_printf(state->ini_error, "Expecting %s:\n", expecting); /* Only append error if there's one line */ - if (strchr(state->arg, '\n') != NULL || strlen(state->arg) == 0) { + if (strchr(state->arg, '\n') || strlen(state->arg) == 0) { return; } diff --git a/src/cli/babeltrace2-cfg-src-auto-disc.c b/src/cli/babeltrace2-cfg-src-auto-disc.c index 505a265f..6dcb9e2c 100644 --- a/src/cli/babeltrace2-cfg-src-auto-disc.c +++ b/src/cli/babeltrace2-cfg-src-auto-disc.c @@ -562,7 +562,7 @@ int auto_discover_source_for_input_as_dir_or_file_rec(GString *input, BT_LOGW_ERRNO("Failed to read directory entry", ": dir=%s", input->str); goto error; } - } while (dirent != NULL); + } while (dirent); status = dir_status; diff --git a/src/compat/memstream.h b/src/compat/memstream.h index 8dea7a44..7ca3168a 100644 --- a/src/compat/memstream.h +++ b/src/compat/memstream.h @@ -69,7 +69,7 @@ FILE *bt_fmemopen(void *buf, size_t size, const char *mode) /* Build a temporary filename */ tmpname = g_build_filename(g_get_tmp_dir(), "babeltrace-tmp-XXXXXX", NULL); - if (_mktemp(tmpname) == NULL) { + if (!_mktemp(tmpname)) { goto error_free; } @@ -217,7 +217,7 @@ FILE *bt_open_memstream(char **ptr, size_t *sizeloc) tmpname = g_build_filename(g_get_tmp_dir(), "babeltrace-tmp-XXXXXX", NULL); - if (_mktemp(tmpname) == NULL) { + if (!_mktemp(tmpname)) { goto error_free; } diff --git a/src/compat/mman.c b/src/compat/mman.c index 72c4cc28..1a7638c9 100644 --- a/src/compat/mman.c +++ b/src/compat/mman.c @@ -75,7 +75,7 @@ struct mmap_mapping *mapping_create(int log_level) struct mmap_mapping *mapping; mapping = malloc(sizeof(struct mmap_mapping)); - if (mapping != NULL) { + if (mapping) { mapping->file_handle = NULL; mapping->map_handle = NULL; mapping->log_level = log_level; @@ -283,7 +283,7 @@ int bt_munmap(void *addr, size_t length) mmap_lock(log_level); /* Check if the mapping exists in the hashtable. */ - if (g_hash_table_lookup(mmap_mappings, addr) == NULL) { + if (!g_hash_table_lookup(mmap_mappings, addr)) { _set_errno(EINVAL); ret = -1; goto end; diff --git a/src/compat/stdio.h b/src/compat/stdio.h index 906e695d..a484ed29 100644 --- a/src/compat/stdio.h +++ b/src/compat/stdio.h @@ -37,10 +37,10 @@ char * _bt_getline_bufalloc(char **lineptr, size_t *n, size_t linelen) size_t buflen = *n; char *buf = *lineptr; - if (buflen >= linelen && buf != NULL) { + if (buflen >= linelen && buf) { return buf; } - if (buf == NULL) { + if (!buf) { buflen = BT_GETLINE_MINBUFLEN; } else { buflen = buflen << 1; @@ -80,7 +80,7 @@ ssize_t bt_getline(char **lineptr, size_t *n, FILE *stream) char *buf; int found_eof = 0; - if (lineptr == NULL || n == NULL) { + if (!lineptr || !n) { errno = EINVAL; return -1; } diff --git a/src/ctf-writer/assert-pre.h b/src/ctf-writer/assert-pre.h index c0a24614..fbff4a7b 100644 --- a/src/ctf-writer/assert-pre.h +++ b/src/ctf-writer/assert-pre.h @@ -139,7 +139,7 @@ * Developer mode: asserts that a given variable is not NULL. */ #define BT_CTF_ASSERT_PRE_NON_NULL(_obj, _obj_name) \ - BT_CTF_ASSERT_PRE((_obj) != NULL, "%s is NULL: ", _obj_name) + BT_CTF_ASSERT_PRE((_obj), "%s is NULL: ", _obj_name) /* * Developer mode: asserts that a given object is NOT frozen. This macro diff --git a/src/ctf-writer/fields.h b/src/ctf-writer/fields.h index 87063fe2..ecf7e914 100644 --- a/src/ctf-writer/fields.h +++ b/src/ctf-writer/fields.h @@ -650,7 +650,7 @@ int bt_ctf_field_common_string_append_len(struct bt_ctf_field_common *field, BT_CTF_FIELD_TYPE_ID_STRING, "Field"); /* Make sure no null bytes are appended */ - BT_CTF_ASSERT_PRE(memchr(value, '\0', length) == NULL, + BT_CTF_ASSERT_PRE(!memchr(value, '\0', length), "String value to append contains a null character: " "partial-value=\"%.32s\", length=%u", value, length); diff --git a/src/ctf-writer/stream.c b/src/ctf-writer/stream.c index 1bf60df1..3f5e6100 100644 --- a/src/ctf-writer/stream.c +++ b/src/ctf-writer/stream.c @@ -1021,7 +1021,7 @@ append_ids: stream_class_id, stream->common.id); file_path = g_build_filename(writer->path->str, filename->str, NULL); - if (file_path == NULL) { + if (!file_path) { ret = -1; goto end; } @@ -1627,7 +1627,7 @@ int bt_ctf_stream_flush(struct bt_ctf_stream *stream) packet_size_field = bt_ctf_field_structure_get_field_by_name( stream->packet_context, "packet_size"); - has_packet_size = (packet_size_field != NULL); + has_packet_size = packet_size_field; bt_ctf_object_put_ref(packet_size_field); } diff --git a/src/lib/assert-pre.h b/src/lib/assert-pre.h index a470a63b..39472a44 100644 --- a/src/lib/assert-pre.h +++ b/src/lib/assert-pre.h @@ -103,7 +103,7 @@ * is not `NULL`. */ #define BT_ASSERT_PRE_NON_NULL(_obj, _obj_name) \ - BT_ASSERT_PRE((_obj) != NULL, "%s is NULL: ", _obj_name) + BT_ASSERT_PRE((_obj), "%s is NULL: ", _obj_name) /* * Asserts that a given index `_index` is less than a given length diff --git a/src/lib/graph/message/event.c b/src/lib/graph/message/event.c index 285bf8aa..4222a5a0 100644 --- a/src/lib/graph/message/event.c +++ b/src/lib/graph/message/event.c @@ -50,7 +50,7 @@ static inline bool event_class_has_trace(struct bt_event_class *event_class) stream_class = bt_event_class_borrow_stream_class_inline(event_class); BT_ASSERT(stream_class); - return bt_stream_class_borrow_trace_class(stream_class) != NULL; + return bt_stream_class_borrow_trace_class(stream_class); } BT_HIDDEN diff --git a/src/lib/plugin/plugin-so.c b/src/lib/plugin/plugin-so.c index 319988be..b9ef8005 100644 --- a/src/lib/plugin/plugin-so.c +++ b/src/lib/plugin/plugin-so.c @@ -364,7 +364,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin, const struct __bt_plugin_descriptor_attribute *cur_attr = *cur_attr_ptr; - if (cur_attr == NULL) { + if (!cur_attr) { continue; } @@ -434,7 +434,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin, *cur_cc_descr_ptr; struct comp_class_full_descriptor full_descriptor = {0}; - if (cur_cc_descr == NULL) { + if (!cur_cc_descr) { continue; } @@ -457,7 +457,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin, *cur_cc_descr_attr_ptr; enum bt_component_class_type cc_type; - if (cur_cc_descr_attr == NULL) { + if (!cur_cc_descr_attr) { continue; } @@ -1319,7 +1319,7 @@ int bt_plugin_so_create_all_from_sections( descriptors_begin[i]; struct bt_plugin *plugin; - if (descriptor == NULL) { + if (!descriptor) { continue; } diff --git a/src/lib/plugin/plugin.c b/src/lib/plugin/plugin.c index 8f2f6da3..5537cb0d 100644 --- a/src/lib/plugin/plugin.c +++ b/src/lib/plugin/plugin.c @@ -84,7 +84,7 @@ int init_python_plugin_provider(void) { static const char * const provider_dir_envvar_name = "LIBBABELTRACE2_PLUGIN_PROVIDER_DIR"; char *provider_path = NULL; - if (bt_plugin_python_create_all_from_file_sym != NULL) { + if (bt_plugin_python_create_all_from_file_sym) { goto end; } diff --git a/src/lib/trace-ir/field.c b/src/lib/trace-ir/field.c index e200c153..26160c20 100644 --- a/src/lib/trace-ir/field.c +++ b/src/lib/trace-ir/field.c @@ -674,7 +674,7 @@ enum bt_field_string_append_status bt_field_string_append_with_length( BT_FIELD_CLASS_TYPE_STRING, "Field"); /* Make sure no null bytes are appended */ - BT_ASSERT_PRE_DEV(memchr(value, '\0', length) == NULL, + BT_ASSERT_PRE_DEV(!memchr(value, '\0', length), "String value to append contains a null character: " "partial-value=\"%.32s\", length=%" PRIu64, value, length); diff --git a/src/lib/trace-ir/trace-class.c b/src/lib/trace-ir/trace-class.c index 620e8f6d..d968ddfe 100644 --- a/src/lib/trace-ir/trace-class.c +++ b/src/lib/trace-ir/trace-class.c @@ -204,7 +204,7 @@ bool has_listener_id(const struct bt_trace_class *tc, uint64_t listener_id) BT_ASSERT(listener_id < tc->destruction_listeners->len); return (&g_array_index(tc->destruction_listeners, struct bt_trace_class_destruction_listener_elem, - listener_id))->func != NULL; + listener_id))->func; } enum bt_trace_class_remove_listener_status bt_trace_class_remove_destruction_listener( diff --git a/src/lib/trace-ir/trace.c b/src/lib/trace-ir/trace.c index e884c72a..0f683fb4 100644 --- a/src/lib/trace-ir/trace.c +++ b/src/lib/trace-ir/trace.c @@ -239,7 +239,7 @@ bool trace_has_environment_entry(const struct bt_trace *trace, const char *name) BT_ASSERT(trace); return bt_attributes_borrow_field_value_by_name( - trace->environment, name) != NULL; + trace->environment, name); } static @@ -450,7 +450,7 @@ bool has_listener_id(const struct bt_trace *trace, uint64_t listener_id) BT_ASSERT(listener_id < trace->destruction_listeners->len); return (&g_array_index(trace->destruction_listeners, struct bt_trace_destruction_listener_elem, - listener_id))->func != NULL; + listener_id))->func; } enum bt_trace_remove_listener_status bt_trace_remove_destruction_listener( diff --git a/src/plugins/ctf/common/metadata/decoder-packetized-file-stream-to-buf.c b/src/plugins/ctf/common/metadata/decoder-packetized-file-stream-to-buf.c index e14c54d7..bf735827 100644 --- a/src/plugins/ctf/common/metadata/decoder-packetized-file-stream-to-buf.c +++ b/src/plugins/ctf/common/metadata/decoder-packetized-file-stream-to-buf.c @@ -212,7 +212,7 @@ int ctf_metadata_decoder_packetized_file_stream_to_buf(FILE *fp, size_t packet_index = 0; out_fp = bt_open_memstream(buf, &size); - if (out_fp == NULL) { + if (!out_fp) { BT_COMP_LOGE("Cannot open memory stream: %s.", strerror(errno)); goto error; diff --git a/src/plugins/ctf/common/metadata/parser.y b/src/plugins/ctf/common/metadata/parser.y index b6f5b7a3..ae5a9f98 100644 --- a/src/plugins/ctf/common/metadata/parser.y +++ b/src/plugins/ctf/common/metadata/parser.y @@ -351,7 +351,7 @@ int is_type(struct ctf_scanner *scanner, const char *id) struct ctf_scanner_scope *it; int ret = 0; - for (it = scanner->cs; it != NULL; it = it->parent) { + for (it = scanner->cs; it; it = it->parent) { if (lookup_type(it, id)) { ret = 1; break; diff --git a/src/plugins/ctf/common/metadata/visitor-generate-ir.c b/src/plugins/ctf/common/metadata/visitor-generate-ir.c index 3413ac17..26e11290 100644 --- a/src/plugins/ctf/common/metadata/visitor-generate-ir.c +++ b/src/plugins/ctf/common/metadata/visitor-generate-ir.c @@ -4810,7 +4810,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, BT_ASSERT(ctx->ctf_tc->default_byte_order == CTF_BYTE_ORDER_LITTLE || ctx->ctf_tc->default_byte_order == CTF_BYTE_ORDER_BIG); BT_ASSERT(ctx->current_scope && - ctx->current_scope->parent_scope == NULL); + !ctx->current_scope->parent_scope); /* Environment */ bt_list_for_each_entry(iter, &node->u.root.env, siblings) { @@ -4824,7 +4824,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } BT_ASSERT(ctx->current_scope && - ctx->current_scope->parent_scope == NULL); + !ctx->current_scope->parent_scope); /* * Visit clock blocks. @@ -4840,7 +4840,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } BT_ASSERT(ctx->current_scope && - ctx->current_scope->parent_scope == NULL); + !ctx->current_scope->parent_scope); /* * Visit root declarations next, as they can be used by any @@ -4858,7 +4858,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } BT_ASSERT(ctx->current_scope && - ctx->current_scope->parent_scope == NULL); + !ctx->current_scope->parent_scope); /* Callsite blocks are not supported */ bt_list_for_each_entry(iter, &node->u.root.callsite, siblings) { @@ -4867,7 +4867,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } BT_ASSERT(ctx->current_scope && - ctx->current_scope->parent_scope == NULL); + !ctx->current_scope->parent_scope); /* Trace */ bt_list_for_each_entry(iter, &node->u.root.trace, siblings) { @@ -4881,7 +4881,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } BT_ASSERT(ctx->current_scope && - ctx->current_scope->parent_scope == NULL); + !ctx->current_scope->parent_scope); /* Streams */ bt_list_for_each_entry(iter, &node->u.root.stream, siblings) { @@ -4895,7 +4895,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } BT_ASSERT(ctx->current_scope && - ctx->current_scope->parent_scope == NULL); + !ctx->current_scope->parent_scope); /* Events */ bt_list_for_each_entry(iter, &node->u.root.event, siblings) { @@ -4909,7 +4909,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } BT_ASSERT(ctx->current_scope && - ctx->current_scope->parent_scope == NULL); + !ctx->current_scope->parent_scope); break; } default: diff --git a/src/plugins/ctf/common/metadata/visitor-semantic-validator.c b/src/plugins/ctf/common/metadata/visitor-semantic-validator.c index 17f63ac9..8e732997 100644 --- a/src/plugins/ctf/common/metadata/visitor-semantic-validator.c +++ b/src/plugins/ctf/common/metadata/visitor-semantic-validator.c @@ -358,7 +358,7 @@ int ctf_visitor_field_class_declarator(int depth, struct ctf_node *node, } } if (node->u.field_class_declarator.type == TYPEDEC_ID && - node->u.field_class_declarator.u.id != NULL) + node->u.field_class_declarator.u.id) goto errperm; break; /* OK */ case NODE_TYPEDEF: diff --git a/src/plugins/ctf/fs-src/fs.c b/src/plugins/ctf/fs-src/fs.c index 375ca0f3..e4eb3852 100644 --- a/src/plugins/ctf/fs-src/fs.c +++ b/src/plugins/ctf/fs-src/fs.c @@ -1683,7 +1683,7 @@ int merge_traces_with_same_uuid(struct ctf_fs_component *ctf_fs) /* Clear any NULL slot (traces that got merged in another one) in the array. */ for (i = 0; i < traces->len;) { - if (g_ptr_array_index(traces, i) == NULL) { + if (!g_ptr_array_index(traces, i)) { g_ptr_array_remove_index_fast(traces, i); } else { i++; diff --git a/src/plugins/ctf/lttng-live/lttng-live.c b/src/plugins/ctf/lttng-live/lttng-live.c index 93ff89bd..0cabf25d 100644 --- a/src/plugins/ctf/lttng-live/lttng-live.c +++ b/src/plugins/ctf/lttng-live/lttng-live.c @@ -868,7 +868,7 @@ retry: live_status = lttng_live_iterator_next_handle_one_quiescent_stream( lttng_live_msg_iter, stream_iter, curr_msg); if (live_status != LTTNG_LIVE_ITERATOR_STATUS_OK) { - BT_ASSERT(*curr_msg == NULL); + BT_ASSERT(!*curr_msg); goto end; } if (*curr_msg) { @@ -877,7 +877,7 @@ retry: live_status = lttng_live_iterator_next_handle_one_active_data_stream( lttng_live_msg_iter, stream_iter, curr_msg); if (live_status != LTTNG_LIVE_ITERATOR_STATUS_OK) { - BT_ASSERT(*curr_msg == NULL); + BT_ASSERT(!*curr_msg); } end: diff --git a/src/plugins/ctf/lttng-live/viewer-connection.c b/src/plugins/ctf/lttng-live/viewer-connection.c index 44e80cc0..ac335427 100644 --- a/src/plugins/ctf/lttng-live/viewer-connection.c +++ b/src/plugins/ctf/lttng-live/viewer-connection.c @@ -149,10 +149,10 @@ int parse_url(struct live_viewer_connection *viewer_connection) "proto : %s", viewer_connection->relay_hostname->str, viewer_connection->port, - viewer_connection->target_hostname == NULL ? - "" : viewer_connection->target_hostname->str, - viewer_connection->session_name == NULL ? - "" : viewer_connection->session_name->str, + !viewer_connection->target_hostname ? + "" : viewer_connection->target_hostname->str, + !viewer_connection->session_name ? + "" : viewer_connection->session_name->str, lttng_live_url_parts.proto->str); ret = 0; diff --git a/src/plugins/lttng-utils/debug-info/debug-info.c b/src/plugins/lttng-utils/debug-info/debug-info.c index f330f1be..10e5a7de 100644 --- a/src/plugins/lttng-utils/debug-info/debug-info.c +++ b/src/plugins/lttng-utils/debug-info/debug-info.c @@ -443,7 +443,7 @@ static inline bool event_has_payload_field(const bt_event *event, const char *field_name) { - return event_borrow_payload_field(event, field_name) != NULL; + return event_borrow_payload_field(event, field_name); } static diff --git a/src/plugins/text/details/obj-lifetime-mgmt.c b/src/plugins/text/details/obj-lifetime-mgmt.c index 9547d609..8da5cf16 100644 --- a/src/plugins/text/details/obj-lifetime-mgmt.c +++ b/src/plugins/text/details/obj-lifetime-mgmt.c @@ -97,7 +97,7 @@ bool details_need_to_write_meta_object(struct details_write_ctx *ctx, details_tc_meta = g_hash_table_lookup(ctx->details_comp->meta, tc); BT_ASSERT(details_tc_meta); need_to_write = - g_hash_table_lookup(details_tc_meta->objects, obj) == NULL; + !g_hash_table_lookup(details_tc_meta->objects, obj); end: return need_to_write; @@ -130,7 +130,7 @@ bool details_need_to_write_trace_class(struct details_write_ctx *ctx, BT_ASSERT(ctx->details_comp->meta); details_tc_meta = g_hash_table_lookup(ctx->details_comp->meta, tc); - need_to_write = details_tc_meta == NULL; + need_to_write = !details_tc_meta; end: return need_to_write; diff --git a/src/py-common/py-common.c b/src/py-common/py-common.c index ac780034..4fea4d27 100644 --- a/src/py-common/py-common.c +++ b/src/py-common/py-common.c @@ -44,9 +44,9 @@ GString *bt_py_common_format_exception(int log_level) const char *format_exc_func_name; Py_ssize_t i; - BT_ASSERT(PyErr_Occurred() != NULL); + BT_ASSERT(PyErr_Occurred()); PyErr_Fetch(&type, &value, &traceback); - BT_ASSERT(type != NULL); + BT_ASSERT(type); /* Make sure `value` is what we expected: an instance of `type` */ PyErr_NormalizeException(&type, &value, &traceback); diff --git a/tests/ctf-writer/ctf_writer.c b/tests/ctf-writer/ctf_writer.c index 91b2e633..fe811960 100644 --- a/tests/ctf-writer/ctf_writer.c +++ b/tests/ctf-writer/ctf_writer.c @@ -681,7 +681,7 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class, "bt_ctf_event_class_get_stream_class returns the correct stream class"); bt_ctf_object_put_ref(ret_stream_class); - ok(bt_ctf_event_class_get_field_by_name(event_class, "truie") == NULL, + ok(!bt_ctf_event_class_get_field_by_name(event_class, "truie"), "bt_ctf_event_class_get_field_by_name handles an invalid field name correctly"); ret_field_type = bt_ctf_event_class_get_field_by_name(event_class, "complex_structure"); @@ -1217,7 +1217,7 @@ void test_empty_stream(struct bt_ctf_writer *writer) ret = bt_ctf_stream_class_set_event_header_type(stream_class, NULL); BT_ASSERT(ret == 0); - ok(bt_ctf_stream_class_get_trace(stream_class) == NULL, + ok(!bt_ctf_stream_class_get_trace(stream_class), "bt_ctf_stream_class_get_trace returns NULL when stream class is orphaned"); stream = bt_ctf_writer_create_stream(writer, stream_class); @@ -1711,7 +1711,7 @@ int main(int argc, char **argv) name.machine); /* Define a clock and add it to the trace */ - ok(bt_ctf_clock_create("signed") == NULL, + ok(!bt_ctf_clock_create("signed"), "Illegal clock name rejected"); clock = bt_ctf_clock_create(clock_name); ok(clock, "Clock created sucessfully"); @@ -1798,9 +1798,9 @@ int main(int argc, char **argv) ok(ret_string && strcmp(ret_string, "test_stream") == 0, "bt_ctf_stream_class_get_name returns a correct stream class name"); - ok(bt_ctf_stream_class_get_clock(stream_class) == NULL, + ok(!bt_ctf_stream_class_get_clock(stream_class), "bt_ctf_stream_class_get_clock returns NULL when a clock was not set"); - ok(bt_ctf_stream_class_get_clock(NULL) == NULL, + ok(!bt_ctf_stream_class_get_clock(NULL), "bt_ctf_stream_class_get_clock handles NULL correctly"); ok(stream_class, "Create stream class"); @@ -2001,7 +2001,7 @@ int main(int argc, char **argv) "Changes to a stream class that was already instantiated fail"); /* Populate the custom packet header field only once for all tests */ - ok(bt_ctf_stream_get_packet_header(NULL) == NULL, + ok(!bt_ctf_stream_get_packet_header(NULL), "bt_ctf_stream_get_packet_header handles NULL correctly"); packet_header = bt_ctf_stream_get_packet_header(stream1); ok(packet_header, diff --git a/tests/plugins/flt.lttng-utils.debug-info/test_bin_info.c b/tests/plugins/flt.lttng-utils.debug-info/test_bin_info.c index 6d293224..b9ee32e0 100644 --- a/tests/plugins/flt.lttng-utils.debug-info/test_bin_info.c +++ b/tests/plugins/flt.lttng-utils.debug-info/test_bin_info.c @@ -97,7 +97,7 @@ int build_id_to_bin(void) { int ret, len, i; - if (opt_build_id == NULL) { + if (!opt_build_id) { goto error; } @@ -165,7 +165,7 @@ void subtest_lookup_function_name(struct bin_info *bin, uint64_t addr, /* Test function name lookup - erroneous address */ ret = bin_info_lookup_function_name(bin, SO_INV_ADDR, &_func_name); - ok(ret == -1 && _func_name == NULL, + ok(ret == -1 && !_func_name, "bin_info_lookup_function_name - fail on invalid addr"); free(_func_name); } @@ -196,7 +196,7 @@ void subtest_lookup_source_location(struct bin_info *bin, uint64_t addr, /* Test source location lookup - erroneous address */ ret = bin_info_lookup_source_location(bin, SO_INV_ADDR, &src_loc); - ok(ret == -1 && src_loc == NULL, + ok(ret == -1 && !src_loc, "bin_info_lookup_source_location - fail on invalid addr"); if (src_loc) { source_location_destroy(src_loc); @@ -221,7 +221,7 @@ void test_bin_info_build_id(const char *bin_info_dir) bin_path = g_build_filename(bin_info_dir, BUILDID_DIR_NAME, SO_NAME, NULL); - if (data_dir == NULL || bin_path == NULL) { + if (!data_dir || !bin_path) { exit(EXIT_FAILURE); } @@ -233,7 +233,7 @@ void test_bin_info_build_id(const char *bin_info_dir) bin = bin_info_create(&fdc, bin_path, SO_LOW_ADDR, SO_MEMSZ, true, data_dir, NULL, BT_LOG_OUTPUT_LEVEL, NULL); - ok(bin != NULL, "bin_info_create successful (%s)", bin_path); + ok(bin, "bin_info_create successful (%s)", bin_path); /* Test setting invalid build_id */ ret = bin_info_set_build_id(bin, invalid_build_id, BUILD_ID_HEX_LEN); @@ -275,7 +275,7 @@ void test_bin_info_debug_link(const char *bin_info_dir) bin_path = g_build_filename(bin_info_dir, DEBUGLINK_DIR_NAME, SO_NAME, NULL); - if (data_dir == NULL || bin_path == NULL) { + if (!data_dir || !bin_path) { exit(EXIT_FAILURE); } @@ -287,7 +287,7 @@ void test_bin_info_debug_link(const char *bin_info_dir) bin = bin_info_create(&fdc, bin_path, SO_LOW_ADDR, SO_MEMSZ, true, data_dir, NULL, BT_LOG_OUTPUT_LEVEL, NULL); - ok(bin != NULL, "bin_info_create successful (%s)", bin_path); + ok(bin, "bin_info_create successful (%s)", bin_path); /* Test setting debug link */ ret = bin_info_set_debug_link(bin, DEBUG_NAME, opt_debug_link_crc); @@ -325,7 +325,7 @@ void test_bin_info_elf(const char *bin_info_dir) data_dir = g_build_filename(bin_info_dir, ELF_DIR_NAME, NULL); bin_path = g_build_filename(bin_info_dir, ELF_DIR_NAME, SO_NAME, NULL); - if (data_dir == NULL || bin_path == NULL) { + if (!data_dir || !bin_path) { exit(EXIT_FAILURE); } @@ -337,7 +337,7 @@ void test_bin_info_elf(const char *bin_info_dir) bin = bin_info_create(&fdc, bin_path, SO_LOW_ADDR, SO_MEMSZ, true, data_dir, NULL, BT_LOG_OUTPUT_LEVEL, NULL); - ok(bin != NULL, "bin_info_create successful (%s)", bin_path); + ok(bin, "bin_info_create successful (%s)", bin_path); /* Test bin_info_has_address */ subtest_has_address(bin, func_foo_printf_addr); @@ -373,7 +373,7 @@ void test_bin_info_bundled(const char *bin_info_dir) bin_path = g_build_filename(bin_info_dir, DWARF_DIR_NAME, SO_NAME, NULL); - if (data_dir == NULL || bin_path == NULL) { + if (!data_dir || !bin_path) { exit(EXIT_FAILURE); } @@ -385,7 +385,7 @@ void test_bin_info_bundled(const char *bin_info_dir) bin = bin_info_create(&fdc, bin_path, SO_LOW_ADDR, SO_MEMSZ, true, data_dir, NULL, BT_LOG_OUTPUT_LEVEL, NULL); - ok(bin != NULL, "bin_info_create successful (%s)", bin_path); + ok(bin, "bin_info_create successful (%s)", bin_path); /* Test bin_info_has_address */ subtest_has_address(bin, func_foo_printf_addr); diff --git a/tests/plugins/flt.lttng-utils.debug-info/test_dwarf.c b/tests/plugins/flt.lttng-utils.debug-info/test_dwarf.c index abb72bba..953556c4 100644 --- a/tests/plugins/flt.lttng-utils.debug-info/test_dwarf.c +++ b/tests/plugins/flt.lttng-utils.debug-info/test_dwarf.c @@ -46,7 +46,7 @@ void test_bt_no_dwarf(const char *data_dir) Dwarf *dwarf_info = NULL; path = g_build_filename(data_dir, ELF_DIR_NAME, SO_NAME, NULL); - if (path == NULL) { + if (!path) { diag("Failed to allocate memory for path"); exit(EXIT_FAILURE); } @@ -57,10 +57,10 @@ void test_bt_no_dwarf(const char *data_dir) skip(1, "dwarf_begin failed as expected"); } else { dwarf_info = dwarf_begin(fd, DWARF_C_READ); - ok(dwarf_info == NULL, "dwarf_begin failed as expected"); + ok(!dwarf_info, "dwarf_begin failed as expected"); } - if (dwarf_info != NULL) { + if (dwarf_info) { dwarf_end(dwarf_info); } close(fd); @@ -81,7 +81,7 @@ void test_bt_dwarf(const char *data_dir) Dwarf *dwarf_info = NULL; path = g_build_filename(data_dir, DWARF_DIR_NAME, SO_NAME, NULL); - if (path == NULL) { + if (!path) { diag("Failed to allocate memory for path"); exit(EXIT_FAILURE); } @@ -92,13 +92,13 @@ void test_bt_dwarf(const char *data_dir) exit(EXIT_FAILURE); } dwarf_info = dwarf_begin(fd, DWARF_C_READ); - ok(dwarf_info != NULL, "dwarf_begin successful"); + ok(dwarf_info, "dwarf_begin successful"); cu = bt_dwarf_cu_create(dwarf_info); - ok(cu != NULL, "bt_dwarf_cu_create successful"); + ok(cu, "bt_dwarf_cu_create successful"); ret = bt_dwarf_cu_next(cu); ok(ret == 0, "bt_dwarf_cu_next successful"); die = bt_dwarf_die_create(cu); - ok(die != NULL, "bt_dwarf_die_create successful"); + ok(die, "bt_dwarf_die_create successful"); if (!die) { exit(EXIT_FAILURE); } -- 2.34.1