From c8df824bd67b3b532220e5f38162ae0059181ace Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 14 Jan 2025 11:48:20 -0400 Subject: [PATCH] MT#55283 put time_t into struct Avoids possible issues with time_t being too large for an int Change-Id: I067e83061eab7dc9ff179cf0536d08484e93c330 --- lib/loglib.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/loglib.c b/lib/loglib.c index 1b181bdd1..a2febb137 100644 --- a/lib/loglib.c +++ b/lib/loglib.c @@ -15,6 +15,7 @@ struct log_limiter_entry { char *prefix; char *msg; + time_t when; }; typedef struct _fac_code { @@ -159,7 +160,6 @@ void __vpilog(int prio, const char *prefix, const char *fmt, va_list ap) { len--; if ((prio & LOG_FLAG_LIMIT)) { - time_t when; struct log_limiter_entry lle, *llep; lle.prefix = (char *) prefix; @@ -174,18 +174,18 @@ void __vpilog(int prio, const char *prefix, const char *fmt, va_list ap) { time_t now = time(NULL); - when = (time_t) GPOINTER_TO_UINT(g_hash_table_lookup(__log_limiter, &lle)); - if (!when || (now - when) >= 15) { + llep = g_hash_table_lookup(__log_limiter, &lle); + if (!llep || (now - llep->when) >= 15) { llep = g_slice_alloc0(sizeof(*llep)); llep->prefix = strdup(prefix); llep->msg = strdup(msg); - g_hash_table_insert(__log_limiter, llep, GUINT_TO_POINTER(now)); + llep->when = now; + g_hash_table_insert(__log_limiter, llep, llep); __log_limiter_count++; - when = 0; + llep = NULL; } - - if (when) + if (llep) return; }