Skip to content

Commit

Permalink
Remove some temporary buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
zoltanvb committed Aug 20, 2023
1 parent 10c60cd commit 422a5fd
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions runtime_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
{
Expand All @@ -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;

Expand All @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 422a5fd

Please sign in to comment.