Fix: barectf_packet_set_buf(): keep full packet state
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 6 Oct 2020 18:20:12 +0000 (14:20 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 6 Oct 2020 18:20:12 +0000 (14:20 -0400)
commit0a5733ae7584859cc36092a093acaac876efcd16
tree40f4391630dedee3cb248a127c8dae779b36dc98
parentb157169b2757fc3ed3e4eaa8f209eb4754bc7bd8
Fix: barectf_packet_set_buf(): keep full packet state

The condition of barectf_packet_is_full() is:

    ctx->at == ctx->packet_size

So we're reusing `ctx->at` to know whether or not a packet is full.

A full packet is always (already) closed.

The problem is that barectf_packet_set_buf() changes `ctx->packet_size`
without touching `ctx->at`. Therefore if the value of `ctx->packet_size`
changes, and if the packet was considered to be full, it's not the case
anymore, but it must be.

In barectf_packet_set_buf(), set `ctx->at` to `ctx->packet_size` if it
was already the case to keep any full packet state.

Adding a test with a custom platform calling barectf_packet_set_buf()
with a `NULL` buffer after closing a completely full packet. Without
this patch (in `barectf.c.j2`), this test leads to a segmentation fault.

Fixes: https://github.com/efficios/barectf/issues/18
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
barectf/templates/c/barectf.c.j2
tests/tracing/configs/packet-set-buf/packet-set-buf/packet-set-buf.yaml [new file with mode: 0644]
tests/tracing/expect/packet-set-buf/packet-set-buf/packet-set-buf.data.expect [new file with mode: 0644]
tests/tracing/expect/packet-set-buf/packet-set-buf/packet-set-buf.metadata.expect [new file with mode: 0644]
tests/tracing/src/packet-set-buf/packet-set-buf/packet-set-buf.c [new file with mode: 0644]
tests/tracing/support/packet-set-buf/Makefile [new file with mode: 0644]
tests/tracing/support/packet-set-buf/test-platform.c [new file with mode: 0644]
tests/tracing/support/packet-set-buf/test-platform.h [new file with mode: 0644]
This page took 0.025517 seconds and 4 git commands to generate.