tests: logging: log_msg2: Prevent using negative array index
Move assert check before array access to ensure that
negative index is not used in an array. Coverity CID 222151.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
diff --git a/tests/subsys/logging/log_msg2/src/main.c b/tests/subsys/logging/log_msg2/src/main.c
index ed43b7c..b51172e 100644
--- a/tests/subsys/logging/log_msg2/src/main.c
+++ b/tests/subsys/logging/log_msg2/src/main.c
@@ -108,8 +108,8 @@
d = log_msg2_get_package(msg, &len);
if (str) {
rv = cbpprintf(out, &tbuf, d);
- buf[rv] = '\0';
zassert_true(rv > 0, NULL);
+ buf[rv] = '\0';
rv = strncmp(buf, str, sizeof(buf));
zassert_equal(rv, 0, "expected:\n%s,\ngot:\n%s", str, buf);