From c4759885d7c2aedf310739d9a2420ae1d67a0338 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Tue, 16 Jan 2018 02:10:48 +0100 Subject: cosmetic: logging: if color is disabled, don't print "" If color output is disabled, skip the empty snprintf() to (not) clear the ANSI color. Also, no need to use a format string of "%s", just pass the string constant directly. That is a micro optimisation as well as clarification of the code. Change-Id: Ie7cb06de160830d2f8ee5718246c0fe311f68d49 --- src/logging.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/logging.c b/src/logging.c index 9b37bf53..e6e09e06 100644 --- a/src/logging.c +++ b/src/logging.c @@ -398,11 +398,12 @@ static void _output(struct log_target *target, unsigned int subsys, goto err; OSMO_SNPRINTF_RET(ret, rem, offset, len); - ret = snprintf(buf + offset, rem, "%s", - target->use_color ? "\033[0;m" : ""); - if (ret < 0) - goto err; - OSMO_SNPRINTF_RET(ret, rem, offset, len); + if (target->use_color) { + ret = snprintf(buf + offset, rem, "\033[0;m"); + if (ret < 0) + goto err; + OSMO_SNPRINTF_RET(ret, rem, offset, len); + } err: buf[sizeof(buf)-1] = '\0'; target->output(target, level, buf); -- cgit v1.2.3