Fix: set proper size when creating new strings
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 19 Sep 2023 19:41:11 +0000 (15:41 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 20 Oct 2023 23:29:14 +0000 (19:29 -0400)
commitc8a4375195b0ca586c43e5733dfc0266b4ba8a50
tree09c76c7827f59a9f91fc79dc56626ed442676957
parenta0a92e790c59dbe2483a54a1b7cb62fa0ed57bd8
Fix: set proper size when creating new strings

After adding a wrapper to g_array_index that validates that accessed
indices don't go past the end of the arrays, I got this:

    (╯°□°)╯︵ ┻━┻  /home/smarchi/src/babeltrace/src/lib/trace-ir/field.c:392: create_string_field(): Assertion `0 < string_field->buf->len` failed.

The problem is that arrays backing string fields are created with:

    string->buf = g_array_sized_new(FALSE, FALSE, sizeof(char), 1);

This g_array_sized_new call reserves space for one element, but doesn't
actually make the length of the array one.  Add a call to
g_array_set_size to fix that.  Fix another occurence of the same bug in
ctf-writer.

Change-Id: I2b90b26c37d70d64bcd825b5b07b204bcbb5baf5
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10904
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
src/ctf-writer/fields.c
src/lib/trace-ir/field.c
This page took 0.036067 seconds and 4 git commands to generate.