This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Neels Hofmeyr gerrit-no-reply at lists.osmocom.orgNeels Hofmeyr has submitted this change and it was merged.
Change subject: cosmetic: logging: if color is disabled, don't print ""
......................................................................
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
---
M src/logging.c
1 file changed, 6 insertions(+), 5 deletions(-)
Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified
diff --git a/src/logging.c b/src/logging.c
index 9b37bf5..e6e09e0 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -398,11 +398,12 @@
 		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);
-- 
To view, visit https://gerrit.osmocom.org/5816
To unsubscribe, visit https://gerrit.osmocom.org/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie7cb06de160830d2f8ee5718246c0fe311f68d49
Gerrit-PatchSet: 4
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>