mirror of
https://github.com/RsyncProject/rsync.git
synced 2026-05-24 23:05:52 -04:00
util1: handle out-of-range times in timestring
This commit is contained in:
7
util1.c
7
util1.c
@@ -1459,7 +1459,12 @@ char *timestring(time_t t)
|
||||
static char buffers[4][20]; /* We support 4 simultaneous timestring results. */
|
||||
char *TimeBuf = buffers[ndx = (ndx + 1) % 4];
|
||||
struct tm tmp, *tm = localtime_r(&t, &tmp);
|
||||
int len = snprintf(TimeBuf, sizeof buffers[0], "%4d/%02d/%02d %02d:%02d:%02d",
|
||||
int len;
|
||||
if (!tm) {
|
||||
strlcpy(TimeBuf, "(time out of range)", sizeof buffers[0]);
|
||||
return TimeBuf;
|
||||
}
|
||||
len = snprintf(TimeBuf, sizeof buffers[0], "%4d/%02d/%02d %02d:%02d:%02d",
|
||||
(int)tm->tm_year + 1900, (int)tm->tm_mon + 1, (int)tm->tm_mday,
|
||||
(int)tm->tm_hour, (int)tm->tm_min, (int)tm->tm_sec);
|
||||
assert(len > 0); /* Silence gcc warning */
|
||||
|
||||
Reference in New Issue
Block a user