Skip to content

Commit 9420b69

Browse files
committed
Make time_t formatting more consistent
A few cases did not use %jd + intmax_t. Make these consistent. Also prevents a segfault on ARMv7 when %lu was used.
1 parent 91da750 commit 9420b69

4 files changed

Lines changed: 8 additions & 6 deletions

File tree

cf-agent/verify_files_utils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,8 +1672,8 @@ bool CopyRegularFile(EvalContext *ctx, const char *source, const char *dest, con
16721672
if (attr->copy.backup == BACKUP_OPTION_TIMESTAMP)
16731673
{
16741674
stampnow = time((time_t *) NULL);
1675-
snprintf(stamp, CF_BUFSIZE - 1, "_%lu_%s",
1676-
CFSTARTTIME, CanonifyName(ctime(&stampnow)));
1675+
snprintf(stamp, CF_BUFSIZE - 1, "_%jd_%s",
1676+
(intmax_t) CFSTARTTIME, CanonifyName(ctime(&stampnow)));
16771677

16781678
if (!JoinSuffix(backup, sizeof(backup), stamp))
16791679
{

libpromises/evalfunction.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7576,6 +7576,8 @@ static FnCallResult FnCallStrftime(ARG_UNUSED EvalContext *ctx,
75767576
const FnCall *fp,
75777577
const Rlist *finalargs)
75787578
{
7579+
assert(fp != NULL);
7580+
75797581
/* begin fn-specific content */
75807582

75817583
char *mode = RlistScalarValue(finalargs);
@@ -7599,8 +7601,8 @@ static FnCallResult FnCallStrftime(ARG_UNUSED EvalContext *ctx,
75997601
if (tm_pointer == NULL)
76007602
{
76017603
Log(LOG_LEVEL_WARNING,
7602-
"Function %s, the given time stamp '%ld' was invalid. (strftime: %s)",
7603-
fp->name, when, GetErrorStr());
7604+
"Function %s, the given time stamp '%jd' was invalid. (strftime: %s)",
7605+
fp->name, (intmax_t) when, GetErrorStr());
76047606
}
76057607
else if (PortablyFormatTime(buffer, sizeof(buffer),
76067608
format_string, when, tm_pointer))

libpromises/locks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ static bool NoOrObsoleteLock(LockData *entry, ARG_UNUSED size_t entry_size, size
353353
time_t now = time(NULL);
354354
if ((now - entry->time) <= (time_t) *max_old)
355355
{
356-
Log(LOG_LEVEL_DEBUG, "Giving time to process '%d' (holding lock for %ld s)", entry->pid, (now - entry->time));
356+
Log(LOG_LEVEL_DEBUG, "Giving time to process '%d' (holding lock for %jd s)", entry->pid, (intmax_t) (now - entry->time));
357357
}
358358
return ((now - entry->time) > (time_t) *max_old);
359359
}

libpromises/processes_select.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ static void MaybeFixStartTime(const char *line,
708708
fields[j], ctime(&value));
709709

710710
free(fields[j]);
711-
xasprintf(fields + j, "%ld", value);
711+
xasprintf(fields + j, "%jd", (intmax_t) value);
712712
}
713713
}
714714
else if (fields[k])

0 commit comments

Comments
 (0)