[PATCH v3 1/3] syslogd: Use a local to track whether a message has a timestamp.

Grant Erickson <[email protected]>
Newsgroups gmane.linux.busybox
Message-ID <3e6f47e3a6010e672c8d39d02df97420ffa1a28a.1768850836.git.gerickson@nuovations.com>
This improves self-documentation and readability of the code.
---
 sysklogd/syslogd.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index 40644fb97484..22bd76bf5087 100644
--- a/sysklogd/syslogd.c
+++ b/sysklogd/syslogd.c
@@ -857,14 +857,16 @@ static char *timestamp_from_time(const time_t *time)
  * that there is no timestamp, short-circuiting the test. */
 static void timestamp_and_log(int pri, char *msg, int len)
 {
+	/* Jan 18 00:11:22 msg... */
+	/* 01234567890123456 */
+	const bool msg_has_timestamp = (len >= 16 &&
+		msg[ 3] == ' ' && msg[ 6] == ' ' &&
+		msg[ 9] == ':' && msg[12] == ':' &&
+		msg[15] == ' ');
 	char *timestamp = NULL;
 	time_t now;
 
-	/* Jan 18 00:11:22 msg... */
-	/* 01234567890123456 */
-	if (len >= 16 && msg[3] == ' ' && msg[6] == ' '
-	 && msg[9] == ':' && msg[12] == ':' && msg[15] == ' '
-	) {
+	if (msg_has_timestamp) {
 		if (!(option_mask32 & OPT_timestamp)) {
 			/* use message timestamp */
 #if ENABLE_FEATURE_SYSLOGD_UTC
-- 
2.45.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.