From 422a5fd1cfc38ffb8944fc80f5206971da1956cb Mon Sep 17 00:00:00 2001 From: zoltanvb Date: Sun, 20 Aug 2023 09:01:49 +0200 Subject: [PATCH] Remove some temporary buffers --- runtime_file.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/runtime_file.c b/runtime_file.c index 1c62effca11..e9bb223d1cc 100644 --- a/runtime_file.c +++ b/runtime_file.c @@ -573,7 +573,6 @@ static bool runtime_last_played_human(runtime_log_t *runtime_log, time_t current; time_t delta; unsigned i; - char tmp[32]; unsigned units[7][2] = { @@ -588,8 +587,6 @@ static bool runtime_last_played_human(runtime_log_t *runtime_log, float periods[6] = {60.0f, 60.0f, 24.0f, 7.0f, 4.35f, 12.0f}; - tmp[0] = '\0'; - if (!runtime_log) return false; @@ -606,12 +603,11 @@ static bool runtime_last_played_human(runtime_log_t *runtime_log, delta /= periods[i]; /* Generate string */ - _len = snprintf(tmp, sizeof(tmp), "%u ", (int)delta); - strlcpy(tmp + _len, + _len = snprintf(str, len, "%u ", (int)delta); + _len += strlcpy(str + _len, msg_hash_to_str((enum msg_hash_enums)units[i][(delta == 1) ? 0 : 1]), - sizeof(tmp) - _len); + len - _len); - _len = strlcat(str, tmp, len); str[ _len] = ' '; str[++_len] = '\0'; strlcpy(str + _len, @@ -633,9 +629,7 @@ void runtime_log_get_last_played_str(runtime_log_t *runtime_log, if (runtime_log) { - char tmp[64]; bool has_am_pm = false; - tmp[0] = '\0'; /* Handle 12-hour clock options * > These require extra work, due to AM/PM localisation */ switch (timedate_style) @@ -773,10 +767,7 @@ void runtime_log_get_last_played_str(runtime_log_t *runtime_log, /* Get time */ struct tm time_info; runtime_log_get_last_played_time(runtime_log, &time_info); - strftime_am_pm(tmp, sizeof(tmp), format_str, &time_info); - str[ _len] = ' '; - str[++_len] = '\0'; - strlcpy(str + _len, tmp, len - _len); + strftime_am_pm(str + _len, len - _len, format_str, &time_info); return; } @@ -1028,14 +1019,13 @@ void runtime_log_get_last_played_str(runtime_log_t *runtime_log, runtime_log->last_played.day, runtime_log->last_played.month); return; case PLAYLIST_LAST_PLAYED_STYLE_AGO: - if (!(runtime_last_played_human(runtime_log, tmp, sizeof(tmp)))) - strlcat(tmp, + str[ _len] = ' '; + str[++_len] = '\0'; + if (!(runtime_last_played_human(runtime_log, str + _len, len - _len - 2))) + strlcat(str + _len, msg_hash_to_str( MENU_ENUM_LABEL_VALUE_PLAYLIST_INLINE_CORE_DISPLAY_NEVER), - sizeof(tmp)); - str[ _len] = ' '; - str[++_len] = '\0'; - strlcpy(str + _len, tmp, len - _len); + len - _len - 2); return; case PLAYLIST_LAST_PLAYED_STYLE_YMD_HMS: default: