X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=formats%2Fctf%2Fwriter%2Fevent-fields.c;h=c49bc3fa6dc1bca5b325b1be872480c9e68a1487;hp=aa389fd223051ca604b1ec49b6917cbfb2eda1b4;hb=118f5776fcc9e4dc1e79d96d697825bc95174fcb;hpb=550461940505dbeae425d1b87d145549800a5341 diff --git a/formats/ctf/writer/event-fields.c b/formats/ctf/writer/event-fields.c index aa389fd2..c49bc3fa 100644 --- a/formats/ctf/writer/event-fields.c +++ b/formats/ctf/writer/event-fields.c @@ -30,6 +30,7 @@ #include #include #include +#include #define PACKET_LEN_INCREMENT (getpagesize() * 8 * CHAR_BIT) @@ -179,8 +180,8 @@ struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type) } type_id = bt_ctf_field_type_get_type_id(type); - if (type_id <= CTF_TYPE_UNKNOWN || - type_id >= NR_CTF_TYPES) { + if (type_id <= CTF_TYPE_UNKNOWN || type_id >= NR_CTF_TYPES || + bt_ctf_field_type_validate(type)) { goto error; } @@ -247,13 +248,14 @@ int bt_ctf_field_sequence_set_length(struct bt_ctf_field *field, bt_ctf_field_put(sequence->length); } - sequence->elements = g_ptr_array_new_full((size_t)sequence_length, - (GDestroyNotify)bt_ctf_field_put); + sequence->elements = g_ptr_array_sized_new((size_t)sequence_length); if (!sequence->elements) { ret = -1; goto end; } + g_ptr_array_set_free_func(sequence->elements, + (GDestroyNotify)bt_ctf_field_put); g_ptr_array_set_size(sequence->elements, (size_t)sequence_length); bt_ctf_field_get(length_field); sequence->length = length_field; @@ -444,7 +446,7 @@ struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *field, tag_enum_integer = container_of(tag_enum, struct bt_ctf_field_integer, parent); - if (!bt_ctf_field_validate(variant->tag)) { + if (bt_ctf_field_validate(tag_field) < 0) { goto end; } @@ -768,12 +770,13 @@ struct bt_ctf_field *bt_ctf_field_array_create(struct bt_ctf_field_type *type) array_type = container_of(type, struct bt_ctf_field_type_array, parent); array_length = array_type->length; - array->elements = g_ptr_array_new_full(array_length, - (GDestroyNotify)bt_ctf_field_put); + array->elements = g_ptr_array_sized_new(array_length); if (!array->elements) { goto error; } + g_ptr_array_set_free_func(array->elements, + (GDestroyNotify)bt_ctf_field_put); g_ptr_array_set_size(array->elements, array_length); return &array->parent; error: @@ -939,7 +942,7 @@ void bt_ctf_field_string_destroy(struct bt_ctf_field *field) static int bt_ctf_field_generic_validate(struct bt_ctf_field *field) { - return !(field && field->payload_set); + return (field && field->payload_set) ? 0 : -1; } static @@ -1123,10 +1126,16 @@ int bt_ctf_field_structure_serialize(struct bt_ctf_field *field, while (!ctf_pos_access_ok(pos, offset_align(pos->offset, field->type->declaration->alignment))) { - increase_packet_size(pos); + ret = increase_packet_size(pos); + if (ret) { + goto end; + } } - ctf_align_pos(pos, field->type->declaration->alignment); + if (!ctf_align_pos(pos, field->type->declaration->alignment)) { + ret = -1; + goto end; + } for (i = 0; i < structure->fields->len; i++) { struct bt_ctf_field *field = g_ptr_array_index( @@ -1137,7 +1146,7 @@ int bt_ctf_field_structure_serialize(struct bt_ctf_field *field, break; } } - +end: return ret; } @@ -1233,9 +1242,13 @@ int increase_packet_size(struct ctf_stream_pos *pos) } pos->packet_size += PACKET_LEN_INCREMENT; - ret = posix_fallocate(pos->fd, pos->mmap_offset, - pos->packet_size / CHAR_BIT); + do { + ret = bt_posix_fallocate(pos->fd, pos->mmap_offset, + pos->packet_size / CHAR_BIT); + } while (ret == EINTR); if (ret) { + errno = EINTR; + ret = -1; goto end; }