From 821d5e9214017220a76344df586a0985631c69ae Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Fri, 17 Aug 2018 13:25:36 -0400 Subject: [PATCH] Fix: assume that conditions are valid before being compared MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- src/common/buffer-usage.c | 36 ++++++++++++------------------ src/common/session-consumed-size.c | 5 +++-- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/common/buffer-usage.c b/src/common/buffer-usage.c index 3d0026081..dbfae89c8 100644 --- a/src/common/buffer-usage.c +++ b/src/common/buffer-usage.c @@ -88,6 +88,10 @@ bool lttng_condition_buffer_usage_validate( ERR("Invalid buffer condition: a threshold must be set."); goto end; } + if (!usage->domain.set) { + ERR("Invalid buffer usage condition: a domain must be set."); + goto end; + } valid = true; end: @@ -194,36 +198,24 @@ bool lttng_condition_buffer_usage_is_equal(const struct lttng_condition *_a, } } - if ((a->session_name && !b->session_name) || - (!a->session_name && b->session_name)) { + /* Condition is not valid if this is not true. */ + assert(a->session_name); + assert(b->session_name); + if (strcmp(a->session_name, b->session_name)) { goto end; } - if (a->channel_name && b->channel_name) { - if (strcmp(a->channel_name, b->channel_name)) { - goto end; - } - } if ((a->channel_name && !b->channel_name) || - (!a->channel_name && b->channel_name)) { + assert(a->channel_name); + assert(b->channel_name); + if (strcmp(a->channel_name, b->channel_name)) { goto end; } - if (a->channel_name && b->channel_name) { - if (strcmp(a->channel_name, b->channel_name)) { - goto end; - } - } - - if ((a->domain.set && !b->domain.set) || - (!a->domain.set && b->domain.set)) { + assert(a->domain.set); + assert(b->domain.set); + if (a->domain.type != b->domain.type) { goto end; } - - if (a->domain.set && b->domain.set) { - if (a->domain.type != b->domain.type) { - goto end; - } - } is_equal = true; end: return is_equal; diff --git a/src/common/session-consumed-size.c b/src/common/session-consumed-size.c index 6ff1c2486..e60437d13 100644 --- a/src/common/session-consumed-size.c +++ b/src/common/session-consumed-size.c @@ -136,8 +136,9 @@ bool lttng_condition_session_consumed_size_is_equal(const struct lttng_condition } } - if ((a->session_name && !b->session_name) || - (!a->session_name && b->session_name)) { + assert(a->session_name); + assert(b->session_name); + if (strcmp(a->session_name, b->session_name)) { goto end; } -- 2.34.1