struct ctf_event *event_class;
uint64_t id = 0;
int len_index;
+ int ret;
if (sin->pos.offset == -EOF)
return -EOF;
/* Read and print event header */
if (stream_class->event_header) {
- generic_rw(&sin->pos.parent, &stream_class->event_header->p);
-
+ ret = generic_rw(&sin->pos.parent, &stream_class->event_header->p);
+ if (ret)
+ return ret;
/* lookup event id */
len_index = struct_declaration_lookup_field_index(stream_class->event_header_decl,
g_quark_from_static_string("id"));
id = defint->value._unsigned; /* set id */
}
- generic_rw(&sout->parent, &stream_class->event_header->p);
+ ret = generic_rw(&sout->parent, &stream_class->event_header->p);
+ if (ret)
+ return ret;
}
/* Read and print stream-declared event context */
if (stream_class->event_context) {
- generic_rw(&sin->pos.parent, &stream_class->event_context->p);
- generic_rw(&sout->parent, &stream_class->event_context->p);
+ ret = generic_rw(&sin->pos.parent, &stream_class->event_context->p);
+ if (ret)
+ return ret;
+ ret = generic_rw(&sout->parent, &stream_class->event_context->p);
+ if (ret)
+ return ret;
}
if (id >= stream_class->events_by_id->len) {
/* Read and print event-declared event context */
if (event_class->context) {
- generic_rw(&sin->pos.parent, &event_class->context->p);
- generic_rw(&sout->parent, &event_class->context->p);
+ ret = generic_rw(&sin->pos.parent, &event_class->context->p);
+ if (ret)
+ return ret;
+ ret = generic_rw(&sout->parent, &event_class->context->p);
+ if (ret)
+ return ret;
}
/* Read and print event payload */
if (event_class->fields) {
- generic_rw(&sin->pos.parent, &event_class->fields->p);
- generic_rw(&sout->parent, &event_class->fields->p);
+ ret = generic_rw(&sin->pos.parent, &event_class->fields->p);
+ if (ret)
+ return ret;
+ ret = generic_rw(&sout->parent, &event_class->fields->p);
+ if (ret)
+ return ret;
}
return 0;
#include <babeltrace/ctf-text/types.h>
#include <stdio.h>
-void ctf_text_array_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_text_array_write(struct stream_pos *ppos, struct definition *definition)
{
struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
+ int ret;
if (!pos->dummy) {
print_pos_tabs(pos);
fprintf(pos->fp, "[\n");
pos->depth++;
}
- array_rw(ppos, definition);
+ ret = array_rw(ppos, definition);
if (!pos->dummy) {
pos->depth--;
print_pos_tabs(pos);
fprintf(pos->fp, "]\n");
}
+ return ret;
}
#include <stdio.h>
#include <stdint.h>
-void ctf_text_enum_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_text_enum_write(struct stream_pos *ppos, struct definition *definition)
{
struct definition_enum *enum_definition =
container_of(definition, struct definition_enum, p);
enum_definition->integer;
struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
GArray *qs;
- int i;
+ int i, ret;
if (pos->dummy)
- return;
+ return 0;
print_pos_tabs(pos);
fprintf(pos->fp, "(");
pos->depth++;
- generic_rw(ppos, &integer_definition->p);
+ ret = generic_rw(ppos, &integer_definition->p);
print_pos_tabs(pos);
qs = enum_definition->value;
pos->depth--;
print_pos_tabs(pos);
fprintf(pos->fp, ")");
+ return ret;
}
#include <babeltrace/ctf-text/types.h>
#include <stdio.h>
-void ctf_text_float_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_text_float_write(struct stream_pos *ppos, struct definition *definition)
{
struct definition_float *float_definition =
container_of(definition, struct definition_float, p);
struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
if (pos->dummy)
- return;
+ return 0;
print_pos_tabs(pos);
fprintf(pos->fp, "%Lg\n", float_definition->value);
+ return 0;
}
#include <inttypes.h>
#include <stdint.h>
-void ctf_text_integer_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_text_integer_write(struct stream_pos *ppos, struct definition *definition)
{
struct definition_integer *integer_definition =
container_of(definition, struct definition_integer, p);
struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
if (pos->dummy)
- return;
+ return 0;
print_pos_tabs(pos);
if (!integer_declaration->signedness) {
fprintf(pos->fp, "%" PRIu64" (0x%" PRIX64 ")\n",
integer_definition->value._signed,
integer_definition->value._signed);
}
+ return 0;
}
#include <babeltrace/ctf-text/types.h>
#include <stdio.h>
-void ctf_text_sequence_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_text_sequence_write(struct stream_pos *ppos, struct definition *definition)
{
struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
+ int ret;
if (!pos->dummy) {
print_pos_tabs(pos);
fprintf(pos->fp, "[\n");
pos->depth++;
}
- sequence_rw(ppos, definition);
+ ret = sequence_rw(ppos, definition);
if (!pos->dummy) {
pos->depth--;
print_pos_tabs(pos);
fprintf(pos->fp, "]\n");
}
+ return ret;
}
#include <limits.h> /* C99 limits */
#include <string.h>
-void ctf_text_string_write(struct stream_pos *ppos,
- struct definition *definition)
+int ctf_text_string_write(struct stream_pos *ppos,
+ struct definition *definition)
{
struct definition_string *string_definition =
container_of(definition, struct definition_string, p);
assert(string_definition->value != NULL);
if (pos->dummy)
- return;
+ return 0;
print_pos_tabs(pos);
fprintf(pos->fp, "%s\n", string_definition->value);
+ return 0;
}
#include <babeltrace/ctf-text/types.h>
#include <stdio.h>
-void ctf_text_struct_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_text_struct_write(struct stream_pos *ppos, struct definition *definition)
{
struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
+ int ret;
if (!pos->dummy) {
if (pos->depth >= 0) {
}
pos->depth++;
}
- struct_rw(ppos, definition);
+ ret = struct_rw(ppos, definition);
if (!pos->dummy) {
pos->depth--;
if (pos->depth >= 0) {
fprintf(pos->fp, "}\n");
}
}
+ return ret;
}
#include <babeltrace/ctf-text/types.h>
#include <stdio.h>
-void ctf_text_variant_write(struct stream_pos *pos, struct definition *definition)
+int ctf_text_variant_write(struct stream_pos *pos, struct definition *definition)
{
- variant_rw(pos, definition);
+ return variant_rw(pos, definition);
}
/* read and check header, set stream id (and check) */
if (td->packet_header) {
/* Read packet header */
- generic_rw(&pos->parent, &td->packet_header->p);
-
+ ret = generic_rw(&pos->parent, &td->packet_header->p);
+ if (ret)
+ return ret;
len_index = struct_declaration_lookup_field_index(td->packet_header->declaration, g_quark_from_static_string("magic"));
if (len_index >= 0) {
struct definition_integer *defint;
if (stream->packet_context) {
/* Read packet context */
- generic_rw(&pos->parent, &stream->packet_context->p);
-
+ ret = generic_rw(&pos->parent, &stream->packet_context->p);
+ if (ret)
+ return ret;
/* read content size from header */
len_index = struct_declaration_lookup_field_index(stream->packet_context->declaration, g_quark_from_static_string("content_size"));
if (len_index >= 0) {
#include <babeltrace/ctf/types.h>
-void ctf_array_rw(struct stream_pos *pos, struct definition *definition)
+int ctf_array_rw(struct stream_pos *pos, struct definition *definition)
{
- array_rw(pos, definition);
+ return array_rw(pos, definition);
}
#include <stdint.h>
#include <glib.h>
-void ctf_enum_read(struct stream_pos *ppos, struct definition *definition)
+int ctf_enum_read(struct stream_pos *ppos, struct definition *definition)
{
struct definition_enum *enum_definition =
container_of(definition, struct definition_enum, p);
const struct declaration_integer *integer_declaration =
integer_definition->declaration;
GArray *qs;
+ int ret;
- ctf_integer_read(ppos, &integer_definition->p);
+ ret = ctf_integer_read(ppos, &integer_definition->p);
+ if (ret)
+ return ret;
if (!integer_declaration->signedness)
qs = enum_uint_to_quark_set(enum_declaration,
integer_definition->value._unsigned);
if (enum_definition->value)
g_array_unref(enum_definition->value);
enum_definition->value = qs;
+ return 0;
}
-void ctf_enum_write(struct stream_pos *pos, struct definition *definition)
+int ctf_enum_write(struct stream_pos *pos, struct definition *definition)
{
struct definition_enum *enum_definition =
container_of(definition, struct definition_enum, p);
struct definition_integer *integer_definition =
enum_definition->integer;
- ctf_integer_write(pos, &integer_definition->p);
+ return ctf_integer_write(pos, &integer_definition->p);
}
size_t sign_start, exp_start, mantissa_start, len;
};
-void _ctf_float_copy(struct stream_pos *destp,
- struct definition_float *dest_definition,
- struct stream_pos *srcp,
- const struct definition_float *src_definition)
+int _ctf_float_copy(struct stream_pos *destp,
+ struct definition_float *dest_definition,
+ struct stream_pos *srcp,
+ const struct definition_float *src_definition)
{
+ int ret;
+
/* Read */
if (src_definition->declaration->byte_order == LITTLE_ENDIAN) {
- ctf_integer_read(srcp, &src_definition->mantissa->p);
- ctf_integer_read(srcp, &src_definition->exp->p);
- ctf_integer_read(srcp, &src_definition->sign->p);
+ ret = ctf_integer_read(srcp, &src_definition->mantissa->p);
+ if (ret)
+ return ret;
+ ret = ctf_integer_read(srcp, &src_definition->exp->p);
+ if (ret)
+ return ret;
+ ret = ctf_integer_read(srcp, &src_definition->sign->p);
+ if (ret)
+ return ret;
} else {
- ctf_integer_read(srcp, &src_definition->sign->p);
- ctf_integer_read(srcp, &src_definition->exp->p);
- ctf_integer_read(srcp, &src_definition->mantissa->p);
+ ret = ctf_integer_read(srcp, &src_definition->sign->p);
+ if (ret)
+ return ret;
+ ret = ctf_integer_read(srcp, &src_definition->exp->p);
+ if (ret)
+ return ret;
+ ret = ctf_integer_read(srcp, &src_definition->mantissa->p);
+ if (ret)
+ return ret;
}
dest_definition->mantissa->value._unsigned =
/* Write */
if (dest_definition->declaration->byte_order == LITTLE_ENDIAN) {
- ctf_integer_write(destp, &dest_definition->mantissa->p);
- ctf_integer_write(destp, &dest_definition->exp->p);
- ctf_integer_write(destp, &dest_definition->sign->p);
+ ret = ctf_integer_write(destp, &dest_definition->mantissa->p);
+ if (ret)
+ return ret;
+ ret = ctf_integer_write(destp, &dest_definition->exp->p);
+ if (ret)
+ return ret;
+ ret = ctf_integer_write(destp, &dest_definition->sign->p);
+ if (ret)
+ return ret;
} else {
- ctf_integer_write(destp, &dest_definition->sign->p);
- ctf_integer_write(destp, &dest_definition->exp->p);
- ctf_integer_write(destp, &dest_definition->mantissa->p);
+ ret = ctf_integer_write(destp, &dest_definition->sign->p);
+ if (ret)
+ return ret;
+ ret = ctf_integer_write(destp, &dest_definition->exp->p);
+ if (ret)
+ return ret;
+ ret = ctf_integer_write(destp, &dest_definition->mantissa->p);
+ if (ret)
+ return ret;
}
+ return 0;
}
-void ctf_float_read(struct stream_pos *ppos, struct definition *definition)
+int ctf_float_read(struct stream_pos *ppos, struct definition *definition)
{
struct definition_float *float_definition =
container_of(definition, struct definition_float, p);
struct definition_float *tmpfloat =
container_of(tmpdef, struct definition_float, p);
struct ctf_stream_pos destp;
+ int ret;
ctf_init_pos(&destp, -1, O_WRONLY);
destp.base = (char *) u.bits;
ctf_align_pos(pos, float_declaration->p.alignment);
- _ctf_float_copy(&destp.parent, tmpfloat, ppos, float_definition);
+ ret = _ctf_float_copy(&destp.parent, tmpfloat, ppos, float_definition);
float_definition->value = u.v;
definition_unref(tmpdef);
+ return ret;
}
-void ctf_float_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_float_write(struct stream_pos *ppos, struct definition *definition)
{
struct definition_float *float_definition =
container_of(definition, struct definition_float, p);
struct definition_float *tmpfloat =
container_of(tmpdef, struct definition_float, p);
struct ctf_stream_pos srcp;
+ int ret;
ctf_init_pos(&srcp, -1, O_RDONLY);
srcp.base = (char *) u.bits;
u.v = float_definition->value;
ctf_align_pos(pos, float_declaration->p.alignment);
- _ctf_float_copy(ppos, float_definition, &srcp.parent, tmpfloat);
+ ret = _ctf_float_copy(ppos, float_definition, &srcp.parent, tmpfloat);
definition_unref(tmpdef);
+ return ret;
}
void __attribute__((constructor)) ctf_float_init(void)
*/
static
-void _aligned_integer_read(struct stream_pos *ppos,
- struct definition *definition)
+int _aligned_integer_read(struct stream_pos *ppos,
+ struct definition *definition)
{
struct definition_integer *integer_definition =
container_of(definition, struct definition_integer, p);
ctf_align_pos(pos, integer_declaration->p.alignment);
assert(!(pos->offset % CHAR_BIT));
+ if (!ctf_pos_access_ok(pos, integer_declaration->len))
+ return -EFAULT;
+
if (!integer_declaration->signedness) {
switch (integer_declaration->len) {
case 8:
}
}
ctf_move_pos(pos, integer_declaration->len);
+ return 0;
}
static
-void _aligned_integer_write(struct stream_pos *ppos,
+int _aligned_integer_write(struct stream_pos *ppos,
struct definition *definition)
{
struct definition_integer *integer_definition =
ctf_align_pos(pos, integer_declaration->p.alignment);
assert(!(pos->offset % CHAR_BIT));
+ if (!ctf_pos_access_ok(pos, integer_declaration->len))
+ return -EFAULT;
+
if (pos->dummy)
goto end;
if (!integer_declaration->signedness) {
}
end:
ctf_move_pos(pos, integer_declaration->len);
+ return 0;
}
-void ctf_integer_read(struct stream_pos *ppos, struct definition *definition)
+int ctf_integer_read(struct stream_pos *ppos, struct definition *definition)
{
struct definition_integer *integer_definition =
container_of(definition, struct definition_integer, p);
if (!(integer_declaration->p.alignment % CHAR_BIT)
&& !(integer_declaration->len % CHAR_BIT)) {
- _aligned_integer_read(ppos, definition);
- return;
+ return _aligned_integer_read(ppos, definition);
}
ctf_align_pos(pos, integer_declaration->p.alignment);
+
+ if (!ctf_pos_access_ok(pos, integer_declaration->len))
+ return -EFAULT;
+
if (!integer_declaration->signedness) {
if (integer_declaration->byte_order == LITTLE_ENDIAN)
bt_bitfield_read_le(pos->base, unsigned long,
&integer_definition->value._signed);
}
ctf_move_pos(pos, integer_declaration->len);
+ return 0;
}
-void ctf_integer_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_integer_write(struct stream_pos *ppos, struct definition *definition)
{
struct definition_integer *integer_definition =
container_of(definition, struct definition_integer, p);
if (!(integer_declaration->p.alignment % CHAR_BIT)
&& !(integer_declaration->len % CHAR_BIT)) {
- _aligned_integer_write(ppos, definition);
- return;
+ return _aligned_integer_write(ppos, definition);
}
ctf_align_pos(pos, integer_declaration->p.alignment);
+
+ if (!ctf_pos_access_ok(pos, integer_declaration->len))
+ return -EFAULT;
+
if (pos->dummy)
goto end;
if (!integer_declaration->signedness) {
}
end:
ctf_move_pos(pos, integer_declaration->len);
+ return 0;
}
#include <babeltrace/ctf/types.h>
-void ctf_sequence_rw(struct stream_pos *ppos, struct definition *definition)
+int ctf_sequence_rw(struct stream_pos *ppos, struct definition *definition)
{
struct declaration *declaration = definition->declaration;
struct ctf_stream_pos *pos = ctf_pos(ppos);
ctf_align_pos(pos, declaration->alignment);
- sequence_rw(ppos, definition);
+ return sequence_rw(ppos, definition);
}
#include <limits.h> /* C99 limits */
#include <string.h>
-void ctf_string_read(struct stream_pos *ppos, struct definition *definition)
+int ctf_string_read(struct stream_pos *ppos, struct definition *definition)
{
struct definition_string *string_definition =
container_of(definition, struct definition_string, p);
string_definition->declaration;
struct ctf_stream_pos *pos = ctf_pos(ppos);
size_t len;
+ ssize_t max_len;
char *srcaddr;
ctf_align_pos(pos, string_declaration->p.alignment);
+
srcaddr = ctf_get_pos_addr(pos);
- len = strlen(srcaddr) + 1;
+ /* Not counting \0 */
+ max_len = pos->packet_size - pos->offset - 1;
+ if (max_len < 0)
+ return -EFAULT;
+ len = strnlen(srcaddr, max_len) + 1; /* Add \0 */
+ /* Truncated string, unexpected. Trace probably corrupted. */
+ if (srcaddr[len - 1] != '\0')
+ return -EFAULT;
+
if (string_definition->alloc_len < len) {
string_definition->value =
g_realloc(string_definition->value, len);
memcpy(string_definition->value, srcaddr, len);
string_definition->len = len;
ctf_move_pos(pos, len * CHAR_BIT);
+ return 0;
}
-void ctf_string_write(struct stream_pos *ppos,
+int ctf_string_write(struct stream_pos *ppos,
struct definition *definition)
{
struct definition_string *string_definition =
ctf_align_pos(pos, string_declaration->p.alignment);
assert(string_definition->value != NULL);
len = string_definition->len;
+
+ if (!ctf_pos_access_ok(pos, len))
+ return -EFAULT;
+
if (pos->dummy)
goto end;
destaddr = ctf_get_pos_addr(pos);
memcpy(destaddr, string_definition->value, len);
end:
ctf_move_pos(pos, len * CHAR_BIT);
+ return 0;
}
#include <babeltrace/ctf/types.h>
-void ctf_struct_rw(struct stream_pos *ppos, struct definition *definition)
+int ctf_struct_rw(struct stream_pos *ppos, struct definition *definition)
{
struct declaration *declaration = definition->declaration;
struct ctf_stream_pos *pos = ctf_pos(ppos);
ctf_align_pos(pos, declaration->alignment);
- struct_rw(ppos, definition);
+ return struct_rw(ppos, definition);
}
#include <babeltrace/ctf/types.h>
-void ctf_variant_rw(struct stream_pos *ppos, struct definition *definition)
+int ctf_variant_rw(struct stream_pos *ppos, struct definition *definition)
{
struct declaration *declaration = definition->declaration;
struct ctf_stream_pos *pos = ctf_pos(ppos);
ctf_align_pos(pos, declaration->alignment);
- variant_rw(ppos, definition);
+ return variant_rw(ppos, definition);
}
/*
* Write only is supported for now.
*/
-void ctf_text_integer_write(struct stream_pos *pos, struct definition *definition);
-void ctf_text_float_write(struct stream_pos *pos, struct definition *definition);
-void ctf_text_string_write(struct stream_pos *pos, struct definition *definition);
-void ctf_text_enum_write(struct stream_pos *pos, struct definition *definition);
-void ctf_text_struct_write(struct stream_pos *pos, struct definition *definition);
-void ctf_text_variant_write(struct stream_pos *pos, struct definition *definition);
-void ctf_text_array_write(struct stream_pos *pos, struct definition *definition);
-void ctf_text_sequence_write(struct stream_pos *pos, struct definition *definition);
+int ctf_text_integer_write(struct stream_pos *pos, struct definition *definition);
+int ctf_text_float_write(struct stream_pos *pos, struct definition *definition);
+int ctf_text_string_write(struct stream_pos *pos, struct definition *definition);
+int ctf_text_enum_write(struct stream_pos *pos, struct definition *definition);
+int ctf_text_struct_write(struct stream_pos *pos, struct definition *definition);
+int ctf_text_variant_write(struct stream_pos *pos, struct definition *definition);
+int ctf_text_array_write(struct stream_pos *pos, struct definition *definition);
+int ctf_text_sequence_write(struct stream_pos *pos, struct definition *definition);
static inline
void print_pos_tabs(struct ctf_text_stream_pos *pos)
#include <stdint.h>
#include <unistd.h>
#include <glib.h>
-
+#include <stdio.h>
struct packet_index {
off_t offset; /* offset of the packet in the file, in bytes */
return container_of(pos, struct ctf_stream_pos, parent);
}
-void ctf_integer_read(struct stream_pos *pos, struct definition *definition);
-void ctf_integer_write(struct stream_pos *pos, struct definition *definition);
-void ctf_float_read(struct stream_pos *pos, struct definition *definition);
-void ctf_float_write(struct stream_pos *pos, struct definition *definition);
-void ctf_string_read(struct stream_pos *pos, struct definition *definition);
-void ctf_string_write(struct stream_pos *pos, struct definition *definition);
-void ctf_enum_read(struct stream_pos *pos, struct definition *definition);
-void ctf_enum_write(struct stream_pos *pos, struct definition *definition);
-void ctf_struct_rw(struct stream_pos *pos, struct definition *definition);
-void ctf_variant_rw(struct stream_pos *pos, struct definition *definition);
-void ctf_array_rw(struct stream_pos *pos, struct definition *definition);
-void ctf_sequence_rw(struct stream_pos *pos, struct definition *definition);
+int ctf_integer_read(struct stream_pos *pos, struct definition *definition);
+int ctf_integer_write(struct stream_pos *pos, struct definition *definition);
+int ctf_float_read(struct stream_pos *pos, struct definition *definition);
+int ctf_float_write(struct stream_pos *pos, struct definition *definition);
+int ctf_string_read(struct stream_pos *pos, struct definition *definition);
+int ctf_string_write(struct stream_pos *pos, struct definition *definition);
+int ctf_enum_read(struct stream_pos *pos, struct definition *definition);
+int ctf_enum_write(struct stream_pos *pos, struct definition *definition);
+int ctf_struct_rw(struct stream_pos *pos, struct definition *definition);
+int ctf_variant_rw(struct stream_pos *pos, struct definition *definition);
+int ctf_array_rw(struct stream_pos *pos, struct definition *definition);
+int ctf_sequence_rw(struct stream_pos *pos, struct definition *definition);
void ctf_move_pos_slow(struct ctf_stream_pos *pos, size_t offset, int whence);
static inline
void ctf_move_pos(struct ctf_stream_pos *pos, size_t bit_offset)
{
+ if (pos->offset == -EOF)
+ return;
+
if (pos->fd >= 0) {
if (((pos->prot == PROT_READ)
&& (pos->offset + bit_offset >= pos->content_size))
ctf_move_pos(pos, pos->packet_size - pos->offset);
}
+static inline
+int ctf_pos_access_ok(struct ctf_stream_pos *pos, size_t bit_len)
+{
+ if (pos->offset == -EOF)
+ return 0;
+ if (pos->offset + bit_len > pos->packet_size)
+ return 0;
+ return 1;
+}
+
#endif /* _BABELTRACE_CTF_TYPES_H */
int ref; /* number of references to the definition */
};
-typedef void (*rw_dispatch)(struct stream_pos *pos,
- struct definition *definition);
+typedef int (*rw_dispatch)(struct stream_pos *pos,
+ struct definition *definition);
/* Parent of per-plugin positions */
struct stream_pos {
};
static inline
-void generic_rw(struct stream_pos *pos, struct definition *definition)
+int generic_rw(struct stream_pos *pos, struct definition *definition)
{
enum ctf_type_id dispatch_id = definition->declaration->id;
rw_dispatch call;
assert(pos->rw_table[dispatch_id] != NULL);
call = pos->rw_table[dispatch_id];
- call(pos, definition);
+ return call(pos, definition);
}
/*
struct field *
struct_definition_get_field_from_index(struct definition_struct *struct_definition,
int index);
-void struct_rw(struct stream_pos *pos, struct definition *definition);
+int struct_rw(struct stream_pos *pos, struct definition *definition);
/*
* The tag enumeration is validated to ensure that it contains only mappings
* to.
*/
struct field *variant_get_current_field(struct definition_variant *variant);
-void variant_rw(struct stream_pos *pos, struct definition *definition);
+int variant_rw(struct stream_pos *pos, struct definition *definition);
/*
* elem_declaration passed as parameter now belongs to the array. No
struct declaration_scope *parent_scope);
uint64_t array_len(struct definition_array *array);
struct definition *array_index(struct definition_array *array, uint64_t i);
-void array_rw(struct stream_pos *pos, struct definition *definition);
+int array_rw(struct stream_pos *pos, struct definition *definition);
/*
* int_declaration and elem_declaration passed as parameter now belong
struct declaration_scope *parent_scope);
uint64_t sequence_len(struct definition_sequence *sequence);
struct definition *sequence_index(struct definition_sequence *sequence, uint64_t i);
-void sequence_rw(struct stream_pos *pos, struct definition *definition);
+int sequence_rw(struct stream_pos *pos, struct definition *definition);
/*
* in: path (dot separated), out: q (GArray of GQuark)
static
void _array_definition_free(struct definition *definition);
-void array_rw(struct stream_pos *pos, struct definition *definition)
+int array_rw(struct stream_pos *pos, struct definition *definition)
{
struct definition_array *array_definition =
container_of(definition, struct definition_array, p);
const struct declaration_array *array_declaration =
array_definition->declaration;
uint64_t i;
+ int ret;
/* No need to align, because the first field will align itself. */
for (i = 0; i < array_declaration->len; i++) {
struct definition *elem =
g_array_index(array_definition->elems, struct field, i).definition;
- generic_rw(pos, elem);
+ ret = generic_rw(pos, elem);
+ if (ret)
+ return ret;
}
+ return 0;
}
static
static
void _sequence_definition_free(struct definition *definition);
-void sequence_rw(struct stream_pos *pos, struct definition *definition)
+int sequence_rw(struct stream_pos *pos, struct definition *definition)
{
struct definition_sequence *sequence_definition =
container_of(definition, struct definition_sequence, p);
const struct declaration_sequence *sequence_declaration =
sequence_definition->declaration;
uint64_t len, oldlen, i;
+ int ret;
- generic_rw(pos, &sequence_definition->len->p);
+ ret = generic_rw(pos, &sequence_definition->len->p);
+ if (ret)
+ return ret;
len = sequence_definition->len->value._unsigned;
/*
* Yes, large sequences could be _painfully slow_ to parse due
field->definition = sequence_declaration->elem->definition_new(sequence_declaration->elem,
sequence_definition->scope,
name, i);
- generic_rw(pos, field->definition);
+ ret = generic_rw(pos, field->definition);
+ if (ret)
+ return ret;
}
+ return 0;
}
static
static
void _struct_definition_free(struct definition *definition);
-void struct_rw(struct stream_pos *ppos, struct definition *definition)
+int struct_rw(struct stream_pos *ppos, struct definition *definition)
{
struct definition_struct *struct_definition =
container_of(definition, struct definition_struct, p);
unsigned long i;
+ int ret;
for (i = 0; i < struct_definition->fields->len; i++) {
struct field *field = &g_array_index(struct_definition->fields,
struct field, i);
- generic_rw(ppos, field->definition);
+ ret = generic_rw(ppos, field->definition);
+ if (ret)
+ return ret;
}
+ return 0;
}
static
static
void _variant_definition_free(struct definition *definition);
-void variant_rw(struct stream_pos *ppos, struct definition *definition)
+int variant_rw(struct stream_pos *ppos, struct definition *definition)
{
struct definition_variant *variant_definition =
container_of(definition, struct definition_variant, p);
struct field *field;
field = variant_get_current_field(variant_definition);
- generic_rw(ppos, field->definition);
+ return generic_rw(ppos, field->definition);
}
static