From 0022a87819b0908869f99e08925d2d71c150b285 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Wed, 9 Dec 2020 11:41:14 -0500 Subject: [PATCH] Fix: clear_string_field(): set first character to 0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 . Reported-by: Brice Videau Signed-off-by: Philippe Proulx Change-Id: I964599ecfbea33a7cb583dcf7cf25e6cffbc30b6 Reviewed-on: https://review.lttng.org/c/babeltrace/+/4528 Tested-by: jenkins Reviewed-by: Jérémie Galarneau --- src/lib/trace-ir/field.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/trace-ir/field.c b/src/lib/trace-ir/field.c index cbba4a53..9d4d1335 100644 --- a/src/lib/trace-ir/field.c +++ b/src/lib/trace-ir/field.c @@ -856,6 +856,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); } -- 2.34.1