Checking the return value of this function against NULL is mostly
useless because in case of an out-of-bound access the function would
return a pointer value passed the end of the array (junk).
This commit removes NULL checks and `BT_ASSERT()`on the return value of
this function.
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ifea5772d6b9f61487ef7295763f8f8929649b125
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2253
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
const char *suffix;
bool is_default = false;
const char *suffix;
bool is_default = false;
- if (!str_obj) {
- BT_CLI_LOGE_APPEND_CAUSE("Unexpected error.");
- ret = -1;
- goto end;
- }
-
suffix = bt_value_string_get(str_obj);
g_string_assign(tmpstr, prefix);
suffix = bt_value_string_get(str_obj);
g_string_assign(tmpstr, prefix);
arg = bt_value_string_get(arg_value);
BT_ASSERT(arg);
argv[i] = arg;
arg = bt_value_string_get(arg_value);
BT_ASSERT(arg);
argv[i] = arg;
const bt_value *elem;
const char *arg;
const bt_value *elem;
const char *arg;
- elem = bt_value_array_borrow_element_by_index(impl_args->extra_params,
- i);
- if (!elem) {
- goto error;
- }
+ elem = bt_value_array_borrow_element_by_index(
+ impl_args->extra_params, i);
BT_ASSERT(bt_value_is_string(elem));
arg = bt_value_string_get(elem);
BT_ASSERT(bt_value_is_string(elem));
arg = bt_value_string_get(elem);
GString *quoted = NULL;
const char *arg_to_print;
GString *quoted = NULL;
const char *arg_to_print;
arg = bt_value_string_get(arg_value);
if (print_run_args) {
arg = bt_value_string_get(arg_value);
if (print_run_args) {
bt_value_array_borrow_element_by_index_const(
value, i);
bt_value_array_borrow_element_by_index_const(
value, i);
- if (!element) {
- goto error;
- }
print_indent(fp, indent);
fprintf(fp, "- ");
print_indent(fp, indent);
fprintf(fp, "- ");
-error:
- BT_LOGE("Error printing value of type %s.",
- bt_common_value_type_string(bt_value_get_type(value)));
-
end:
if (map_keys) {
g_ptr_array_free(map_keys, TRUE);
end:
if (map_keys) {
g_ptr_array_free(map_keys, TRUE);
int64_t timer_us, streams, clients;
map = bt_value_array_borrow_element_by_index_const(results, i);
int64_t timer_us, streams, clients;
map = bt_value_array_borrow_element_by_index_const(results, i);
- if (!map) {
- BT_CLI_LOGE_APPEND_CAUSE("Unexpected empty array entry.");
- goto error;
- }
if (!bt_value_is_map(map)) {
BT_CLI_LOGE_APPEND_CAUSE("Unexpected entry type.");
goto error;
if (!bt_value_is_map(map)) {
BT_CLI_LOGE_APPEND_CAUSE("Unexpected entry type.");
goto error;
trace_info = bt_value_array_borrow_element_by_index_const(
query_result, trace_idx);
trace_info = bt_value_array_borrow_element_by_index_const(
query_result, trace_idx);
if (!bt_value_is_map(trace_info)) {
ret = -1;
BT_CLI_LOGE_APPEND_CAUSE("`babeltrace.trace-infos` query: expecting element to be a map: "
if (!bt_value_is_map(trace_info)) {
ret = -1;
BT_CLI_LOGE_APPEND_CAUSE("`babeltrace.trace-infos` query: expecting element to be a map: "
stream_info = bt_value_array_borrow_element_by_index_const(
stream_infos, stream_idx);
stream_info = bt_value_array_borrow_element_by_index_const(
stream_infos, stream_idx);
- BT_ASSERT(stream_info);
if (!bt_value_is_map(stream_info)) {
ret = -1;
BT_CLI_LOGE_APPEND_CAUSE("`babeltrace.trace-infos` query: "
if (!bt_value_is_map(stream_info)) {
ret = -1;
BT_CLI_LOGE_APPEND_CAUSE("`babeltrace.trace-infos` query: "
const char *bt_attributes_get_field_name(const struct bt_value *attr_obj,
uint64_t index)
{
const char *bt_attributes_get_field_name(const struct bt_value *attr_obj,
uint64_t index)
{
- const char *ret = NULL;
const struct bt_value *attr_field_obj = NULL;
const struct bt_value *attr_field_name_obj = NULL;
const struct bt_value *attr_field_obj = NULL;
const struct bt_value *attr_field_name_obj = NULL;
BT_ASSERT_DBG(index < bt_value_array_get_length(attr_obj));
attr_field_obj = bt_value_array_borrow_element_by_index_const(
attr_obj, index);
BT_ASSERT_DBG(index < bt_value_array_get_length(attr_obj));
attr_field_obj = bt_value_array_borrow_element_by_index_const(
attr_obj, index);
- if (!attr_field_obj) {
- BT_LIB_LOGE_APPEND_CAUSE(
- "Cannot borrow attributes object's array value's element by index: "
- "%![value-]+v, index=%" PRIu64, attr_obj, index);
- goto end;
- }
attr_field_name_obj =
bt_value_array_borrow_element_by_index_const(attr_field_obj,
BT_ATTR_NAME_INDEX);
attr_field_name_obj =
bt_value_array_borrow_element_by_index_const(attr_field_obj,
BT_ATTR_NAME_INDEX);
- if (!attr_field_name_obj) {
- BT_LIB_LOGE_APPEND_CAUSE(
- "Cannot get attribute array value's element by index: "
- "%![value-]+v, index=%" PRIu64, attr_field_obj,
- (uint64_t) BT_ATTR_NAME_INDEX);
- goto end;
- }
-
- ret = bt_value_string_get(attr_field_name_obj);
+ return bt_value_string_get(attr_field_name_obj);
}
BT_HIDDEN
struct bt_value *bt_attributes_borrow_field_value(
struct bt_value *attr_obj, uint64_t index)
{
}
BT_HIDDEN
struct bt_value *bt_attributes_borrow_field_value(
struct bt_value *attr_obj, uint64_t index)
{
- struct bt_value *value_obj = NULL;
struct bt_value *attr_field_obj = NULL;
BT_ASSERT_DBG(attr_obj);
BT_ASSERT_DBG(index < bt_value_array_get_length(attr_obj));
struct bt_value *attr_field_obj = NULL;
BT_ASSERT_DBG(attr_obj);
BT_ASSERT_DBG(index < bt_value_array_get_length(attr_obj));
attr_field_obj =
bt_value_array_borrow_element_by_index(attr_obj, index);
attr_field_obj =
bt_value_array_borrow_element_by_index(attr_obj, index);
- if (!attr_field_obj) {
- BT_LIB_LOGE_APPEND_CAUSE(
- "Cannot get attributes object's array value's element by index: "
- "%![value-]+v, index=%" PRIu64, attr_obj, index);
- goto end;
- }
- value_obj = bt_value_array_borrow_element_by_index(
- attr_field_obj, BT_ATTR_VALUE_INDEX);
- if (!value_obj) {
- BT_LIB_LOGE_APPEND_CAUSE(
- "Cannot get attribute array value's element by index: "
- "%![value-]+v, index=%" PRIu64, attr_field_obj,
- (uint64_t) BT_ATTR_VALUE_INDEX);
- }
-
-end:
- return value_obj;
+ return bt_value_array_borrow_element_by_index( attr_field_obj,
+ BT_ATTR_VALUE_INDEX);
value_obj = bt_value_array_borrow_element_by_index(
attr_obj, i);
value_obj = bt_value_array_borrow_element_by_index(
attr_obj, i);
- if (!value_obj) {
- BT_LIB_LOGE_APPEND_CAUSE(
- "Cannot get attributes object's array value's element by index: "
- "%![value-]+v, index=%" PRIu64, attr_obj, i);
- goto error;
- }
attr_field_name_obj =
bt_value_array_borrow_element_by_index(
value_obj, BT_ATTR_NAME_INDEX);
attr_field_name_obj =
bt_value_array_borrow_element_by_index(
value_obj, BT_ATTR_NAME_INDEX);
- if (!attr_field_name_obj) {
- BT_LIB_LOGE_APPEND_CAUSE(
- "Cannot get attribute array value's element by index: "
- "%![value-]+v, index=%" PRIu64,
- value_obj, (int64_t) BT_ATTR_NAME_INDEX);
- goto error;
- }
field_name = bt_value_string_get(attr_field_name_obj);
field_name = bt_value_string_get(attr_field_name_obj);
-
-error:
- value_obj = NULL;
- return value_obj;
value_obj = bt_value_array_borrow_element_by_index(
attr_field_obj, BT_ATTR_VALUE_INDEX);
value_obj = bt_value_array_borrow_element_by_index(
attr_field_obj, BT_ATTR_VALUE_INDEX);
- if (!value_obj) {
- BT_LIB_LOGE_APPEND_CAUSE(
- "Cannot get attribute array value's element by index: "
- "%![value-]+v, index=%" PRIu64, attr_field_obj,
- (uint64_t) BT_ATTR_VALUE_INDEX);
- }
bt_value_array_borrow_element_by_index_const(
array_obj, i);
bt_value_array_borrow_element_by_index_const(
array_obj, i);
- BT_ASSERT(element_obj);
BT_LOGD("Copying array value's element: element-addr=%p, "
"index=%d", element_obj, i);
ret = bt_value_copy(element_obj, &element_obj_copy);
BT_LOGD("Copying array value's element: element-addr=%p, "
"index=%d", element_obj, i);
ret = bt_value_copy(element_obj, &element_obj_copy);
const char *session_name_str = NULL;
map = bt_value_array_borrow_element_by_index(results, i);
const char *session_name_str = NULL;
map = bt_value_array_borrow_element_by_index(results, i);
- if (!map) {
- BT_COMP_LOGE_STR("Error borrowing map.");
- ret = -1;
- goto end;
- }
hostname = bt_value_map_borrow_entry_value(map, "target-hostname");
if (!hostname) {
BT_COMP_LOGE_STR("Error borrowing \"target-hostname\" entry.");
hostname = bt_value_map_borrow_entry_value(map, "target-hostname");
if (!hostname) {
BT_COMP_LOGE_STR("Error borrowing \"target-hostname\" entry.");
ok(ret == 0 && results, "bt_query_executor_query() succeeds");
BT_ASSERT(bt_value_is_array(results) && bt_value_array_get_length(results) == 2);
object = bt_value_array_borrow_element_by_index_const(results, 0);
ok(ret == 0 && results, "bt_query_executor_query() succeeds");
BT_ASSERT(bt_value_is_array(results) && bt_value_array_get_length(results) == 2);
object = bt_value_array_borrow_element_by_index_const(results, 0);
- BT_ASSERT(object && bt_value_is_string(object));
+ BT_ASSERT(bt_value_is_string(object));
object_str = bt_value_string_get(object);
ok(strcmp(object_str, "get-something") == 0,
"bt_component_class_query() receives the expected object name");
object_str = bt_value_string_get(object);
ok(strcmp(object_str, "get-something") == 0,
"bt_component_class_query() receives the expected object name");
"appending an element to an array value object increment its size");
obj = bt_value_array_borrow_element_by_index(array_obj, 0);
"appending an element to an array value object increment its size");
obj = bt_value_array_borrow_element_by_index(array_obj, 0);
- ok(obj && bt_value_is_unsigned_integer(obj),
+ ok(bt_value_is_unsigned_integer(obj),
"bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (unsigned integer)");
int_value = bt_value_integer_unsigned_get(obj);
ok(int_value == 345,
"bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (unsigned integer)");
obj = bt_value_array_borrow_element_by_index(array_obj, 1);
"bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (unsigned integer)");
int_value = bt_value_integer_unsigned_get(obj);
ok(int_value == 345,
"bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (unsigned integer)");
obj = bt_value_array_borrow_element_by_index(array_obj, 1);
- ok(obj && bt_value_is_signed_integer(obj),
+ ok(bt_value_is_signed_integer(obj),
"bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (signed integer)");
int_value = bt_value_integer_signed_get(obj);
ok(int_value == -507,
"bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (signed integer)");
obj = bt_value_array_borrow_element_by_index(array_obj, 2);
"bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (signed integer)");
int_value = bt_value_integer_signed_get(obj);
ok(int_value == -507,
"bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (signed integer)");
obj = bt_value_array_borrow_element_by_index(array_obj, 2);
- ok(obj && bt_value_is_real(obj),
+ ok(bt_value_is_real(obj),
"bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (real number)");
real_value = bt_value_real_get(obj);
ok(real_value == -17.45,
"bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (real number)");
obj = bt_value_array_borrow_element_by_index(array_obj, 3);
"bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (real number)");
real_value = bt_value_real_get(obj);
ok(real_value == -17.45,
"bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (real number)");
obj = bt_value_array_borrow_element_by_index(array_obj, 3);
- ok(obj && bt_value_is_bool(obj),
+ ok(bt_value_is_bool(obj),
"bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (boolean)");
bool_value = bt_value_bool_get(obj);
ok(bool_value,
"bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (boolean)");
obj = bt_value_array_borrow_element_by_index(array_obj, 4);
"bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (boolean)");
bool_value = bt_value_bool_get(obj);
ok(bool_value,
"bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (boolean)");
obj = bt_value_array_borrow_element_by_index(array_obj, 4);
- ok(obj == bt_value_null,
"bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (null)");
obj = bt_value_integer_signed_create_init(1001);
"bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (null)");
obj = bt_value_integer_signed_create_init(1001);
"bt_value_array_set_element_by_index() succeeds");
BT_VALUE_PUT_REF_AND_RESET(obj);
obj = bt_value_array_borrow_element_by_index(array_obj, 2);
"bt_value_array_set_element_by_index() succeeds");
BT_VALUE_PUT_REF_AND_RESET(obj);
obj = bt_value_array_borrow_element_by_index(array_obj, 2);
- ok(obj && bt_value_is_signed_integer(obj),
+ ok(bt_value_is_signed_integer(obj),
"bt_value_array_set_element_by_index() inserts an value object with the appropriate type");
int_value = bt_value_integer_signed_get(obj);
BT_ASSERT(!ret);
"bt_value_array_set_element_by_index() inserts an value object with the appropriate type");
int_value = bt_value_integer_signed_get(obj);
BT_ASSERT(!ret);
"map value object is not empty");
obj = bt_value_array_borrow_element_by_index(array_obj, 5);
"map value object is not empty");
obj = bt_value_array_borrow_element_by_index(array_obj, 5);
- ok(obj && bt_value_is_bool(obj),
+ ok(bt_value_is_bool(obj),
"bt_value_array_append_bool_element() appends a boolean value object");
bool_value = bt_value_bool_get(obj);
ok(!bool_value,
"bt_value_array_append_bool_element() appends the appropriate value");
obj = bt_value_array_borrow_element_by_index(array_obj, 6);
"bt_value_array_append_bool_element() appends a boolean value object");
bool_value = bt_value_bool_get(obj);
ok(!bool_value,
"bt_value_array_append_bool_element() appends the appropriate value");
obj = bt_value_array_borrow_element_by_index(array_obj, 6);
- ok(obj && bt_value_is_unsigned_integer(obj),
+ ok(bt_value_is_unsigned_integer(obj),
"bt_value_array_append_unsigned_integer_element() appends an unsigned integer value object");
int_value = bt_value_integer_unsigned_get(obj);
ok(int_value == 98765,
"bt_value_array_append_unsigned_integer_element() appends the appropriate value");
obj = bt_value_array_borrow_element_by_index(array_obj, 7);
"bt_value_array_append_unsigned_integer_element() appends an unsigned integer value object");
int_value = bt_value_integer_unsigned_get(obj);
ok(int_value == 98765,
"bt_value_array_append_unsigned_integer_element() appends the appropriate value");
obj = bt_value_array_borrow_element_by_index(array_obj, 7);
- ok(obj && bt_value_is_signed_integer(obj),
+ ok(bt_value_is_signed_integer(obj),
"bt_value_array_append_signed_integer_element() appends a signed integer value object");
int_value = bt_value_integer_signed_get(obj);
ok(int_value == -10101,
"bt_value_array_append_signed_integer_element() appends the appropriate value");
obj = bt_value_array_borrow_element_by_index(array_obj, 8);
"bt_value_array_append_signed_integer_element() appends a signed integer value object");
int_value = bt_value_integer_signed_get(obj);
ok(int_value == -10101,
"bt_value_array_append_signed_integer_element() appends the appropriate value");
obj = bt_value_array_borrow_element_by_index(array_obj, 8);
- ok(obj && bt_value_is_real(obj),
+ ok(bt_value_is_real(obj),
"bt_value_array_append_real_element() appends a real number value object");
real_value = bt_value_real_get(obj);
ok(real_value == 2.49578,
"bt_value_array_append_real_element() appends the appropriate value");
obj = bt_value_array_borrow_element_by_index(array_obj, 9);
"bt_value_array_append_real_element() appends a real number value object");
real_value = bt_value_real_get(obj);
ok(real_value == 2.49578,
"bt_value_array_append_real_element() appends the appropriate value");
obj = bt_value_array_borrow_element_by_index(array_obj, 9);
- ok(obj && bt_value_is_string(obj),
+ ok(bt_value_is_string(obj),
"bt_value_array_append_string_element() appends a string value object");
string_value = bt_value_string_get(obj);
ok(!ret && string_value && strcmp(string_value, "bt_value") == 0,
"bt_value_array_append_string_element() appends the appropriate value");
obj = bt_value_array_borrow_element_by_index(array_obj, 10);
"bt_value_array_append_string_element() appends a string value object");
string_value = bt_value_string_get(obj);
ok(!ret && string_value && strcmp(string_value, "bt_value") == 0,
"bt_value_array_append_string_element() appends the appropriate value");
obj = bt_value_array_borrow_element_by_index(array_obj, 10);
- ok(obj && bt_value_is_array(obj),
+ ok(bt_value_is_array(obj),
"bt_value_array_append_empty_array_element() appends an array value object");
ok(bt_value_array_is_empty(obj),
"bt_value_array_append_empty_array_element() an empty array value object");
obj = bt_value_array_borrow_element_by_index(array_obj, 11);
"bt_value_array_append_empty_array_element() appends an array value object");
ok(bt_value_array_is_empty(obj),
"bt_value_array_append_empty_array_element() an empty array value object");
obj = bt_value_array_borrow_element_by_index(array_obj, 11);
- ok(obj && bt_value_is_array(obj),
+ ok(bt_value_is_array(obj),
"bt_value_array_append_empty_array_element() appends an array value object");
ok(bt_value_array_is_empty(obj),
"bt_value_array_append_empty_array_element() an empty array value object");
obj = bt_value_array_borrow_element_by_index(array_obj, 12);
"bt_value_array_append_empty_array_element() appends an array value object");
ok(bt_value_array_is_empty(obj),
"bt_value_array_append_empty_array_element() an empty array value object");
obj = bt_value_array_borrow_element_by_index(array_obj, 12);
- ok(obj && bt_value_is_map(obj),
+ ok(bt_value_is_map(obj),
"bt_value_array_append_empty_map_element() appends a map value object");
ok(bt_value_map_is_empty(obj),
"bt_value_array_append_empty_map_element() an empty map value object");
obj = bt_value_array_borrow_element_by_index(array_obj, 13);
"bt_value_array_append_empty_map_element() appends a map value object");
ok(bt_value_map_is_empty(obj),
"bt_value_array_append_empty_map_element() an empty map value object");
obj = bt_value_array_borrow_element_by_index(array_obj, 13);
- ok(obj && bt_value_is_map(obj),
+ ok(bt_value_is_map(obj),
"bt_value_array_append_empty_map_element() appends a map value object");
ok(bt_value_map_is_empty(obj),
"bt_value_array_append_empty_map_element() an empty map value object");
"bt_value_array_append_empty_map_element() appends a map value object");
ok(bt_value_map_is_empty(obj),
"bt_value_array_append_empty_map_element() an empty map value object");