Adjust the ETA max to 68 years on systems where a long integer is 32 bits wide, as that is all that will fit.
This commit is contained in:
+12
-3
@@ -10,6 +10,8 @@
|
||||
#include "pv.h"
|
||||
#include "pv-internal.h"
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
|
||||
/*
|
||||
* Estimated time until completion.
|
||||
@@ -17,7 +19,7 @@
|
||||
pvdisplay_bytecount_t pv_formatter_eta(pvformatter_args_t args)
|
||||
{
|
||||
char content[128]; /* flawfinder: ignore - bounded in pv_snprintf(). */
|
||||
long eta;
|
||||
long eta, max_days;
|
||||
|
||||
content[0] = '\0';
|
||||
|
||||
@@ -39,8 +41,15 @@ pvdisplay_bytecount_t pv_formatter_eta(pvformatter_args_t args)
|
||||
eta = 0;
|
||||
|
||||
/* The ETA must be under 1,000,000 days so it's not too wide. */
|
||||
if ((eta / 86400L) >= 1000000L)
|
||||
eta = 1000000L * 86400L - 1L;
|
||||
/* If a "long" is 32 bits, only 24,855 days will fit in it. */
|
||||
max_days = 24855L;
|
||||
#ifdef LONG_MAX
|
||||
if (LONG_MAX > 2147483647L)
|
||||
max_days = 1000000;
|
||||
#endif
|
||||
|
||||
if ((eta / 86400L) >= max_days)
|
||||
eta = max_days * 86400L - 1L;
|
||||
|
||||
/*
|
||||
* If the ETA is more than a day, include a day count as well as
|
||||
|
||||
+11
-3
@@ -13,6 +13,7 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
|
||||
|
||||
/*
|
||||
@@ -23,7 +24,7 @@ pvdisplay_bytecount_t pv_formatter_fineta(pvformatter_args_t args)
|
||||
char content[128]; /* flawfinder: ignore - bounded by strftime(). */
|
||||
time_t now, then;
|
||||
struct tm *time_ptr;
|
||||
long eta;
|
||||
long eta, max_years;
|
||||
const char *time_format;
|
||||
bool show_fineta;
|
||||
|
||||
@@ -55,8 +56,15 @@ pvdisplay_bytecount_t pv_formatter_fineta(pvformatter_args_t args)
|
||||
eta = 0;
|
||||
|
||||
/* Clamp the ETA to 7,000 years max so the date isn't too wide. */
|
||||
if ((eta / 31536000L) > 7000L)
|
||||
eta = 31536000L * 7000L;
|
||||
/* If a "long" is 32 bits, only 68 years will fit in it. */
|
||||
max_years = 68;
|
||||
#ifdef LONG_MAX
|
||||
if (LONG_MAX > 2147483647L)
|
||||
max_years = 7000;
|
||||
#endif
|
||||
|
||||
if ((eta / 31536000L) > max_years)
|
||||
eta = 31536000L * max_years;
|
||||
|
||||
/*
|
||||
* Only include the date if the ETA is more than 6 hours
|
||||
|
||||
Reference in New Issue
Block a user