return width + 6;
}
-static void get_duration_buf(int seconds, char *buf, struct ls_options *opts)
+static void get_duration_buf(int seconds, char *buf, size_t bufsize,
+ struct ls_options *opts)
{
unsigned hours = seconds / 3600, mins = (seconds % 3600) / 60;
short unsigned max_width;
if (!hours) { /* m:ss or mm:ss */
max_width = opts->mode == LS_MODE_LONG?
opts->widths.duration_width : 4;
+ assert(max_width < bufsize - 1);
sprintf(buf, "%*u:%02d", max_width - 3, mins, seconds % 60);
} else { /* more than one hour => h:mm:ss, hh:mm:ss, hhh:mm:ss, ... */
max_width = opts->mode == LS_MODE_LONG?
opts->widths.duration_width : 7;
+ assert(max_width < bufsize - 1);
sprintf(buf, "%*u:%02u:%02d", max_width - 6, hours, mins,
seconds % 60);
}
if (ret < 0)
goto out;
}
- get_duration_buf(afhi->seconds_total, duration_buf, opts);
+ get_duration_buf(afhi->seconds_total, duration_buf,
+ sizeof(duration_buf), opts);
if (opts->mode == LS_MODE_LONG) {
struct ls_widths *w = &opts->widths;
if (lls_opt_given(r_a))