Fix: clear_string_field(): set first character to 0
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 9 Dec 2020 16:41:14 +0000 (11:41 -0500)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 19 May 2023 18:42:55 +0000 (14:42 -0400)
The API documentation of bt_field_string_clear() says:

> Clears the string field `field`, making its value an empty string.

clear_string_field(), called by bt_field_string_clear(), sets the string
field's buffer's length to 0 without setting its first character to 0 to
make the string field empty from bt_field_string_get_value()'s point of
view.

This patch makes clear_string_field() also set the string field's
buffer's first character to 0.

Reported by Brice Videau (@Kerilk) in
<https://github.com/efficios/babeltrace/pull/116>.

Reported-by: Brice Videau <bvideau@anl.gov>
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I964599ecfbea33a7cb583dcf7cf25e6cffbc30b6
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4528
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
(cherry picked from commit 0022a87819b0908869f99e08925d2d71c150b285)
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10010
CI-Build: Simon Marchi <simon.marchi@efficios.com>

src/lib/trace-ir/field.c

index c53d7fafc5325fd5b48e356962315448911952e6..62626428170f54600b77f7bc1844476139894727 100644 (file)
@@ -857,6 +857,7 @@ void clear_string_field(struct bt_field *field)
 
        BT_ASSERT_DBG(field);
        string_field->length = 0;
+       g_array_index(string_field->buf, char, 0) = '\0';
        bt_field_set_single(field, true);
 }
 
This page took 0.034612 seconds and 4 git commands to generate.