Skip to content

Commit

Permalink
sprintf -> snprintf, to avoid (harmless) complaints by users/compilers
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Mar 28, 2006
1 parent a2e4f6b commit bfc1158
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ AC_FUNC_ALLOCA
AC_FUNC_STRTOD
AC_FUNC_VPRINTF
AC_CHECK_LIB(m, sin)
AC_CHECK_FUNCS([BSDgettimeofday gettimeofday gethrtime read_real_time time_base_to_time drand48 sqrt memset posix_memalign memalign _mm_malloc _mm_free clock_gettime mach_absolute_time sysctl abort sinl cosl])
AC_CHECK_FUNCS([BSDgettimeofday gettimeofday gethrtime read_real_time time_base_to_time drand48 sqrt memset posix_memalign memalign _mm_malloc _mm_free clock_gettime mach_absolute_time sysctl abort sinl cosl snprintf])
AC_CHECK_DECLS([drand48, memalign, posix_memalign, sinl, cosl])

dnl Cray UNICOS _rtc() (real-time clock) intrinsic
Expand Down
31 changes: 19 additions & 12 deletions libbench2/report.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
*/

/* $Id: report.c,v 1.10 2006-01-05 03:04:27 stevenj Exp $ */
/* $Id: report.c,v 1.11 2006-03-28 04:41:05 stevenj Exp $ */

#include "bench.h"
#include <stdio.h>
Expand Down Expand Up @@ -91,16 +91,23 @@ void report_benchmark(const bench_problem *p, double *t, int st)
ovtpvt("%.5g %.8g %g\n", mflops(p, s.min), s.min, p->setup_time);
}

static void sprintf_time(double x, char *buf)
static void sprintf_time(double x, char *buf, int buflen)
{
#ifdef HAVE_SNPRINTF
# define BENCH_BUFARG buf, buflen
#else
# define snprintf sprintf
# define BENCH_BUFARG buf
#endif
if (x < 1.0E-6)
sprintf(buf, "%.2f ns", x * 1.0E9);
snprintf(BENCH_BUFARG, "%.2f ns", x * 1.0E9);
else if (x < 1.0E-3)
sprintf(buf, "%.2f us", x * 1.0E6);
snprintf(BENCH_BUFARG, "%.2f us", x * 1.0E6);
else if (x < 1.0)
sprintf(buf, "%.2f ms", x * 1.0E3);
snprintf(BENCH_BUFARG, "%.2f ms", x * 1.0E3);
else
sprintf(buf, "%.2f s", x);
snprintf(BENCH_BUFARG, "%.2f s", x);
#undef BENCH_BUFARG
}

void report_verbose(const bench_problem *p, double *t, int st)
Expand All @@ -112,12 +119,12 @@ void report_verbose(const bench_problem *p, double *t, int st)

mkstat(t, st, &s);

sprintf_time(s.min, bmin);
sprintf_time(s.max, bmax);
sprintf_time(s.avg, bavg);
sprintf_time(s.median, bmedian);
sprintf_time(time_min, btmin);
sprintf_time(p->setup_time, bsetup);
sprintf_time(s.min, bmin, 64);
sprintf_time(s.max, bmax, 64);
sprintf_time(s.avg, bavg, 64);
sprintf_time(s.median, bmedian, 64);
sprintf_time(time_min, btmin, 64);
sprintf_time(p->setup_time, bsetup, 64);

ovtpvt("Problem: %s, setup: %s, time: %s, %s: %.5g\n",
p->pstring, bsetup, bmin,
Expand Down
4 changes: 4 additions & 0 deletions tools/fftw-wisdom.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,11 @@ int bench_main(int argc, char *argv[])
char ps[64];
if (!strchr(canonical_sizes[i],'x')
|| !strchr(types[j],'o')) {
#ifdef HAVE_SNPRINTF
snprintf(ps,64, "%s%s", types[j], canonical_sizes[i]);
#else
sprintf(ps, "%s%s", types[j], canonical_sizes[i]);
#endif
add_problem(ps, &problems, &iproblem, &nproblems);
}
}
Expand Down

0 comments on commit bfc1158

Please sign in to comment.