Hi all!

On 02.04.25 05:16, Grant Erickson wrote:
This improves self-documentation and readability of the code.

Signed-off-by: Grant Erickson <[email protected]>
---
sysklogd/syslogd.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index 73c681827d86..a188370b4a0a 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)
{
+       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 */

The 2 comment lines seems to explains the hard-coded indexes in the
if() condition so it should also move up just before the assignment.

-       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
[...]

Kind regards,
        Bernd
--
Bernd Petrovitsch                  Email : [email protected]
     There is NO CLOUD, just other people's computers. - FSFE
                     LUGA : http://www.luga.at
_______________________________________________
busybox mailing list
[email protected]
https://lists.busybox.net/mailman/listinfo/busybox

Reply via email to