Port: use SIZE_MAX as max size_t value
[babeltrace.git] / plugins / ctf / common / notif-iter / notif-iter.c
index 7d570a63acf93267fa79a3c424b8768872aa00a6..30f9727a10594093266e1dbd90efb9216599bc3a 100644 (file)
@@ -211,6 +211,9 @@ struct bt_ctf_notif_iter {
 
                /* Current position from addr (bits) */
                size_t at;
+
+               /* Position of the last event header from addr (bits) */
+               size_t last_eh_at;
        } buf;
 
        /* Binary type reader */
@@ -477,6 +480,7 @@ enum bt_ctf_notif_iter_status request_medium_bytes(
 
                /* Restart at the beginning of the new medium buffer */
                notit->buf.at = 0;
+               notit->buf.last_eh_at = SIZE_MAX;
 
                /* New medium buffer size */
                notit->buf.sz = buffer_sz;
@@ -1169,7 +1173,7 @@ enum bt_ctf_notif_iter_status set_current_packet_content_sizes(
        enum bt_ctf_notif_iter_status status = BT_CTF_NOTIF_ITER_STATUS_OK;
        struct bt_ctf_field *packet_size_field = NULL;
        struct bt_ctf_field *content_size_field = NULL;
-       uint64_t content_size = -1, packet_size = -1;
+       uint64_t content_size = -1ULL, packet_size = -1ULL;
 
        if (!notit->dscopes.stream_packet_context) {
                goto end;
@@ -1220,7 +1224,16 @@ enum bt_ctf_notif_iter_status set_current_packet_content_sizes(
                goto end;
        }
 
-       notit->cur_packet_size = packet_size;
+       if (packet_size != -1ULL) {
+               notit->cur_packet_size = packet_size;
+       } else {
+               /*
+                * Use the content size as packet size indicator if the
+                * packet size field is missing. This means there is no
+                * padding in this stream.
+                */
+               notit->cur_packet_size = content_size;
+       }
        notit->cur_content_size = content_size;
        BT_LOGV("Set current packet and content sizes: "
                "notit-addr=%p, packet-size=%" PRIu64 ", content-size=%" PRIu64,
@@ -1252,6 +1265,9 @@ enum bt_ctf_notif_iter_status read_event_header_begin_state(
        enum bt_ctf_notif_iter_status status = BT_CTF_NOTIF_ITER_STATUS_OK;
        struct bt_ctf_field_type *event_header_type = NULL;
 
+       /* Reset the position of the last event header */
+       notit->buf.last_eh_at = notit->buf.at;
+
        /* Check if we have some content left */
        if (notit->cur_content_size >= 0) {
                if (packet_at(notit) == notit->cur_content_size) {
@@ -1263,7 +1279,7 @@ enum bt_ctf_notif_iter_status read_event_header_begin_state(
                } else if (packet_at(notit) > notit->cur_content_size) {
                        /* That's not supposed to happen */
                        BT_LOGV("Before decoding event header field: cursor is passed the packet's content: "
-                               "notit-addr=%p, content-size=%zu, "
+                               "notit-addr=%p, content-size=%" PRId64 ", "
                                "cur=%zu", notit, notit->cur_content_size,
                                packet_at(notit));
                        status = BT_CTF_NOTIF_ITER_STATUS_ERROR;
@@ -1782,6 +1798,7 @@ void bt_ctf_notif_iter_reset(struct bt_ctf_notif_iter *notit)
        notit->buf.addr = NULL;
        notit->buf.sz = 0;
        notit->buf.at = 0;
+       notit->buf.last_eh_at = SIZE_MAX;
        notit->buf.packet_offset = 0;
        notit->state = STATE_INIT;
        notit->cur_content_size = -1;
@@ -2962,9 +2979,17 @@ void notify_event(struct bt_ctf_notif_iter *notit,
                struct bt_clock_class_priority_map *cc_prio_map,
                struct bt_notification **notification)
 {
-       struct bt_ctf_event *event;
+       struct bt_ctf_event *event = NULL;
        struct bt_notification *ret = NULL;
 
+       /* Make sure that the event contains at least one bit of data */
+       if (notit->buf.at == notit->buf.last_eh_at) {
+               BT_LOGE("Cannot create empty event with 0 bits of data: "
+                       "notit-addr=%p, packet-cur=%zu",
+                       notit, packet_at(notit));
+               goto end;
+       }
+
        /* Create event */
        event = create_event(notit);
        if (!event) {
This page took 0.034522 seconds and 4 git commands to generate.