#include <config.h>
#include <stdio.h>
#include <stdlib.h>
+#include <assert.h>
#include "../src/systime.h"
static struct timeval TV1, TV2;
static int watch_not_started = 1; /* flag */
-static char time_string[30];
+static char time_string[64];
/* Reset the stopwatch to zero. */
}
/* This call returns the time since the last reset_watch call. The time
- is returned as a string with the format <seconds>.<micro-seconds>
+ is returned as a string with the format <seconds>.<micro-seconds>
If reset_watch was not called yet, exit. */
static char *get_time(void)
{
+ int sz;
if (watch_not_started)
exit(1); /* call reset_watch first ! */
EMACS_GET_TIME(TV2);
TV2.tv_usec += 1000000;
TV2.tv_sec--;
}
- sprintf(time_string, "%lu.%06lu",
- (unsigned long)TV2.tv_sec - TV1.tv_sec,
- (unsigned long)TV2.tv_usec - TV1.tv_usec);
+ sz = snprintf(time_string, sizeof(time_string), "%lu.%06lu",
+ (unsigned long)TV2.tv_sec - TV1.tv_sec,
+ (unsigned long)TV2.tv_usec - TV1.tv_usec);
+ assert(sz >= 0 && (size_t)sz < sizeof(time_string));
return time_string;
}