#include <babeltrace2/babeltrace.h>
#include <glib.h>
#include <inttypes.h>
+#include <stdbool.h>
#include "common/common.h"
g_string_append_printf(str, "[%" PRIu64 "]", elem->array_index);
break;
default:
- abort();
+ bt_common_abort();
}
}
struct bt_param_validation_context *ctx);
static
-bt_bool validate_map_value_entry(const char *key,
- const bt_value *value, void *v_data)
+bt_value_map_foreach_entry_const_func_status validate_map_value_entry(
+ const char *key, const bt_value *value, void *v_data)
{
struct validate_map_value_data *data = v_data;
- const struct bt_param_validation_map_value_entry_descr *candidate;
+ const struct bt_param_validation_map_value_entry_descr *entry = NULL;
guint i;
/* Check if this key is in the available keys. */
for (i = 0; i < data->available_keys->len; i++) {
- candidate = g_ptr_array_index(data->available_keys, i);
+ const struct bt_param_validation_map_value_entry_descr *candidate =
+ g_ptr_array_index(data->available_keys, i);
if (g_str_equal(key, candidate->key)) {
+ entry = candidate;
break;
}
}
- if (i < data->available_keys->len) {
+ if (entry) {
/* Key was found in available keys. */
g_ptr_array_remove_index_fast(data->available_keys, i);
validate_ctx_push_map_scope(data->ctx, key);
/* Validate the value of the entry. */
- data->status = validate_value(value, &candidate->value_descr,
+ data->status = validate_value(value, &entry->value_descr,
data->ctx);
validate_ctx_pop_scope(data->ctx);
}
/* Continue iterating if everything is good so far. */
- return data->status == BT_PARAM_VALIDATION_STATUS_OK;
+ return data->status == BT_PARAM_VALIDATION_STATUS_OK ?
+ BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_OK :
+ BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_INTERRUPT;
}
static
struct bt_param_validation_map_value_descr map_value_descr;
enum bt_param_validation_status status;
- ctx.error = NULL;
+ memset(&ctx, '\0', sizeof(ctx));
+
ctx.scope_stack = g_array_new(FALSE, FALSE,
sizeof(struct validate_ctx_stack_element));
- g_ptr_array_new_with_free_func(g_free);
if (!ctx.scope_stack) {
status = BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR;
goto end;
*error = ctx.error;
ctx.error = NULL;
+ if (ctx.scope_stack) {
+ g_array_free(ctx.scope_stack, TRUE);
+ }
+
return status;
}