From b1accfd0ffa6516b3985ba9e610d8bd562645cd5 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Fri, 19 Aug 2016 16:32:56 +0200 Subject: [PATCH] sourcestats: make reading/writing dump files Y2106 ready The sample times were written and read as unsigned long, which would overflow in year 2016 on platforms that have 32-bit long. --- sourcestats.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/sourcestats.c b/sourcestats.c index 9a6371c..7d3fd0f 100644 --- a/sourcestats.c +++ b/sourcestats.c @@ -825,8 +825,14 @@ SST_SaveToFile(SST_Stats inst, FILE *out) i = get_runsbuf_index(inst, m); j = get_buf_index(inst, m); - fprintf(out, "%08lx %08lx %.6e %.6e %.6e %.6e %.6e %.6e %.6e %d\n", - (unsigned long) inst->sample_times[i].tv_sec, + fprintf(out, +#ifdef HAVE_LONG_TIME_T + "%08"PRIx64" %08lx %.6e %.6e %.6e %.6e %.6e %.6e %.6e %d\n", + (uint64_t)inst->sample_times[i].tv_sec, +#else + "%08lx %08lx %.6e %.6e %.6e %.6e %.6e %.6e %.6e %d\n", + (unsigned long)inst->sample_times[i].tv_sec, +#endif (unsigned long)inst->sample_times[i].tv_nsec / 1000, inst->offsets[i], inst->orig_offsets[j], @@ -846,9 +852,14 @@ SST_SaveToFile(SST_Stats inst, FILE *out) int SST_LoadFromFile(SST_Stats inst, FILE *in) { +#ifdef HAVE_LONG_TIME_T + uint64_t sec; +#else + unsigned long sec; +#endif + unsigned long usec; int i, line_number; char line[1024]; - unsigned long sec, usec; double weight; assert(!inst->n_samples); @@ -861,7 +872,12 @@ SST_LoadFromFile(SST_Stats inst, FILE *in) for (i=0; in_samples; i++) { if (!fgets(line, sizeof(line), in) || - (sscanf(line, "%lx%lx%lf%lf%lf%lf%lf%lf%lf%d\n", + (sscanf(line, +#ifdef HAVE_LONG_TIME_T + "%"SCNx64"%lx%lf%lf%lf%lf%lf%lf%lf%d\n", +#else + "%lx%lx%lf%lf%lf%lf%lf%lf%lf%d\n", +#endif &(sec), &(usec), &(inst->offsets[i]), &(inst->orig_offsets[i]),