Always use %j with an intmax_t cast to print time_t values. time_t is
longer than long on 32-bit platforms with a 64-bit time_t. Inspired by: mail from bde
This commit is contained in:
parent
4e3da534fc
commit
a143677385
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=286939
@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -323,15 +324,15 @@ main(int ac, char **av)
|
|||||||
if (trussinfo->flags & ABSOLUTETIMESTAMPS) {
|
if (trussinfo->flags & ABSOLUTETIMESTAMPS) {
|
||||||
timespecsubt(&trussinfo->curthread->after,
|
timespecsubt(&trussinfo->curthread->after,
|
||||||
&trussinfo->start_time, &timediff);
|
&trussinfo->start_time, &timediff);
|
||||||
fprintf(trussinfo->outfile, "%ld.%09ld ",
|
fprintf(trussinfo->outfile, "%jd.%09ld ",
|
||||||
(long)timediff.tv_sec,
|
(intmax_t)timediff.tv_sec,
|
||||||
timediff.tv_nsec);
|
timediff.tv_nsec);
|
||||||
}
|
}
|
||||||
if (trussinfo->flags & RELATIVETIMESTAMPS) {
|
if (trussinfo->flags & RELATIVETIMESTAMPS) {
|
||||||
timespecsubt(&trussinfo->curthread->after,
|
timespecsubt(&trussinfo->curthread->after,
|
||||||
&trussinfo->curthread->before, &timediff);
|
&trussinfo->curthread->before, &timediff);
|
||||||
fprintf(trussinfo->outfile, "%ld.%09ld ",
|
fprintf(trussinfo->outfile, "%jd.%09ld ",
|
||||||
(long)timediff.tv_sec,
|
(intmax_t)timediff.tv_sec,
|
||||||
timediff.tv_nsec);
|
timediff.tv_nsec);
|
||||||
}
|
}
|
||||||
signame = strsig(trussinfo->pr_data);
|
signame = strsig(trussinfo->pr_data);
|
||||||
@ -348,15 +349,16 @@ main(int ac, char **av)
|
|||||||
if (trussinfo->flags & ABSOLUTETIMESTAMPS) {
|
if (trussinfo->flags & ABSOLUTETIMESTAMPS) {
|
||||||
timespecsubt(&trussinfo->curthread->after,
|
timespecsubt(&trussinfo->curthread->after,
|
||||||
&trussinfo->start_time, &timediff);
|
&trussinfo->start_time, &timediff);
|
||||||
fprintf(trussinfo->outfile, "%ld.%09ld ",
|
fprintf(trussinfo->outfile, "%jd.%09ld ",
|
||||||
(long)timediff.tv_sec,
|
(intmax_t)timediff.tv_sec,
|
||||||
timediff.tv_nsec);
|
timediff.tv_nsec);
|
||||||
}
|
}
|
||||||
if (trussinfo->flags & RELATIVETIMESTAMPS) {
|
if (trussinfo->flags & RELATIVETIMESTAMPS) {
|
||||||
timespecsubt(&trussinfo->curthread->after,
|
timespecsubt(&trussinfo->curthread->after,
|
||||||
&trussinfo->curthread->before, &timediff);
|
&trussinfo->curthread->before, &timediff);
|
||||||
fprintf(trussinfo->outfile, "%ld.%09ld ",
|
fprintf(trussinfo->outfile, "%jd.%09ld ",
|
||||||
(long)timediff.tv_sec, timediff.tv_nsec);
|
(intmax_t)timediff.tv_sec,
|
||||||
|
timediff.tv_nsec);
|
||||||
}
|
}
|
||||||
fprintf(trussinfo->outfile,
|
fprintf(trussinfo->outfile,
|
||||||
"process exit, rval = %u\n", trussinfo->pr_data);
|
"process exit, rval = %u\n", trussinfo->pr_data);
|
||||||
|
@ -993,7 +993,7 @@ print_arg(struct syscall_args *sc, unsigned long *args, long retval,
|
|||||||
|
|
||||||
if (get_struct(pid, (void *)args[sc->offset], &ts,
|
if (get_struct(pid, (void *)args[sc->offset], &ts,
|
||||||
sizeof(ts)) != -1)
|
sizeof(ts)) != -1)
|
||||||
fprintf(fp, "{ %ld.%09ld }", (long)ts.tv_sec,
|
fprintf(fp, "{ %jd.%09ld }", (intmax_t)ts.tv_sec,
|
||||||
ts.tv_nsec);
|
ts.tv_nsec);
|
||||||
else
|
else
|
||||||
fprintf(fp, "0x%lx", args[sc->offset]);
|
fprintf(fp, "0x%lx", args[sc->offset]);
|
||||||
@ -1019,8 +1019,9 @@ print_arg(struct syscall_args *sc, unsigned long *args, long retval,
|
|||||||
fprintf(fp, "UTIME_OMIT");
|
fprintf(fp, "UTIME_OMIT");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(fp, "%ld.%09ld",
|
fprintf(fp, "%jd.%09ld",
|
||||||
(long)ts[i].tv_sec, ts[i].tv_nsec);
|
(intmax_t)ts[i].tv_sec,
|
||||||
|
ts[i].tv_nsec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1034,7 +1035,7 @@ print_arg(struct syscall_args *sc, unsigned long *args, long retval,
|
|||||||
|
|
||||||
if (get_struct(pid, (void *)args[sc->offset], &tv, sizeof(tv))
|
if (get_struct(pid, (void *)args[sc->offset], &tv, sizeof(tv))
|
||||||
!= -1)
|
!= -1)
|
||||||
fprintf(fp, "{ %ld.%06ld }", (long)tv.tv_sec,
|
fprintf(fp, "{ %jd.%06ld }", (intmax_t)tv.tv_sec,
|
||||||
tv.tv_usec);
|
tv.tv_usec);
|
||||||
else
|
else
|
||||||
fprintf(fp, "0x%lx", args[sc->offset]);
|
fprintf(fp, "0x%lx", args[sc->offset]);
|
||||||
@ -1045,9 +1046,9 @@ print_arg(struct syscall_args *sc, unsigned long *args, long retval,
|
|||||||
|
|
||||||
if (get_struct(pid, (void *)args[sc->offset], &tv, sizeof(tv))
|
if (get_struct(pid, (void *)args[sc->offset], &tv, sizeof(tv))
|
||||||
!= -1)
|
!= -1)
|
||||||
fprintf(fp, "{ %ld.%06ld, %ld.%06ld }",
|
fprintf(fp, "{ %jd.%06ld, %jd.%06ld }",
|
||||||
(long)tv[0].tv_sec, tv[0].tv_usec,
|
(intmax_t)tv[0].tv_sec, tv[0].tv_usec,
|
||||||
(long)tv[1].tv_sec, tv[1].tv_usec);
|
(intmax_t)tv[1].tv_sec, tv[1].tv_usec);
|
||||||
else
|
else
|
||||||
fprintf(fp, "0x%lx", args[sc->offset]);
|
fprintf(fp, "0x%lx", args[sc->offset]);
|
||||||
break;
|
break;
|
||||||
@ -1057,10 +1058,10 @@ print_arg(struct syscall_args *sc, unsigned long *args, long retval,
|
|||||||
|
|
||||||
if (get_struct(pid, (void *)args[sc->offset], &itv,
|
if (get_struct(pid, (void *)args[sc->offset], &itv,
|
||||||
sizeof(itv)) != -1)
|
sizeof(itv)) != -1)
|
||||||
fprintf(fp, "{ %ld.%06ld, %ld.%06ld }",
|
fprintf(fp, "{ %jd.%06ld, %jd.%06ld }",
|
||||||
(long)itv.it_interval.tv_sec,
|
(intmax_t)itv.it_interval.tv_sec,
|
||||||
itv.it_interval.tv_usec,
|
itv.it_interval.tv_usec,
|
||||||
(long)itv.it_value.tv_sec,
|
(intmax_t)itv.it_value.tv_sec,
|
||||||
itv.it_value.tv_usec);
|
itv.it_value.tv_usec);
|
||||||
else
|
else
|
||||||
fprintf(fp, "0x%lx", args[sc->offset]);
|
fprintf(fp, "0x%lx", args[sc->offset]);
|
||||||
@ -1410,9 +1411,9 @@ print_arg(struct syscall_args *sc, unsigned long *args, long retval,
|
|||||||
if (get_struct(pid, (void *)args[sc->offset], &ru, sizeof(ru))
|
if (get_struct(pid, (void *)args[sc->offset], &ru, sizeof(ru))
|
||||||
!= -1) {
|
!= -1) {
|
||||||
fprintf(fp,
|
fprintf(fp,
|
||||||
"{ u=%ld.%06ld,s=%ld.%06ld,in=%ld,out=%ld }",
|
"{ u=%jd.%06ld,s=%jd.%06ld,in=%ld,out=%ld }",
|
||||||
(long)ru.ru_utime.tv_sec, ru.ru_utime.tv_usec,
|
(intmax_t)ru.ru_utime.tv_sec, ru.ru_utime.tv_usec,
|
||||||
(long)ru.ru_stime.tv_sec, ru.ru_stime.tv_usec,
|
(intmax_t)ru.ru_stime.tv_sec, ru.ru_stime.tv_usec,
|
||||||
ru.ru_inblock, ru.ru_oublock);
|
ru.ru_inblock, ru.ru_oublock);
|
||||||
} else
|
} else
|
||||||
fprintf(fp, "0x%lx", args[sc->offset]);
|
fprintf(fp, "0x%lx", args[sc->offset]);
|
||||||
@ -1513,15 +1514,15 @@ print_syscall(struct trussinfo *trussinfo, const char *name, int nargs,
|
|||||||
if (trussinfo->flags & ABSOLUTETIMESTAMPS) {
|
if (trussinfo->flags & ABSOLUTETIMESTAMPS) {
|
||||||
timespecsubt(&trussinfo->curthread->after,
|
timespecsubt(&trussinfo->curthread->after,
|
||||||
&trussinfo->start_time, &timediff);
|
&trussinfo->start_time, &timediff);
|
||||||
len += fprintf(trussinfo->outfile, "%ld.%09ld ",
|
len += fprintf(trussinfo->outfile, "%jd.%09ld ",
|
||||||
(long)timediff.tv_sec, timediff.tv_nsec);
|
(intmax_t)timediff.tv_sec, timediff.tv_nsec);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trussinfo->flags & RELATIVETIMESTAMPS) {
|
if (trussinfo->flags & RELATIVETIMESTAMPS) {
|
||||||
timespecsubt(&trussinfo->curthread->after,
|
timespecsubt(&trussinfo->curthread->after,
|
||||||
&trussinfo->curthread->before, &timediff);
|
&trussinfo->curthread->before, &timediff);
|
||||||
len += fprintf(trussinfo->outfile, "%ld.%09ld ",
|
len += fprintf(trussinfo->outfile, "%jd.%09ld ",
|
||||||
(long)timediff.tv_sec, timediff.tv_nsec);
|
(intmax_t)timediff.tv_sec, timediff.tv_nsec);
|
||||||
}
|
}
|
||||||
|
|
||||||
len += fprintf(trussinfo->outfile, "%s(", name);
|
len += fprintf(trussinfo->outfile, "%s(", name);
|
||||||
|
Loading…
Reference in New Issue
Block a user