Ticket #4613: check for ETA overflow.

(file_eta_prepare_for_show): check if 'eta_secs' is too large to display
as integer. If yes, display "--".

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Jakob Kastelic 2024-12-13 19:51:52 +03:00 committed by Andrew Borodin
parent 7fc6dfc16b
commit 27c01b8942

View File

@ -62,6 +62,7 @@
#include <errno.h> #include <errno.h>
#include <ctype.h> #include <ctype.h>
#include <limits.h> /* INT_MAX */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
@ -347,6 +348,13 @@ file_eta_prepare_for_show (char *buffer, double eta_secs, gboolean always_show)
{ {
char _fmt_buff[BUF_TINY]; char _fmt_buff[BUF_TINY];
if (eta_secs >= INT_MAX)
{
/* Over 68 years */
g_strlcpy (_fmt_buff, "--", sizeof (_fmt_buff));
}
else
{
if (eta_secs <= 0.5) if (eta_secs <= 0.5)
{ {
if (!always_show) if (!always_show)
@ -359,6 +367,8 @@ file_eta_prepare_for_show (char *buffer, double eta_secs, gboolean always_show)
} }
file_frmt_time (_fmt_buff, eta_secs); file_frmt_time (_fmt_buff, eta_secs);
}
g_snprintf (buffer, BUF_TINY, _("ETA %s"), _fmt_buff); g_snprintf (buffer, BUF_TINY, _("ETA %s"), _fmt_buff);
} }