Build: Fix some format truncation warnings.

Generally all should be safe already, but better to be sure.
This commit is contained in:
Unknown W. Brackets committed 2021-12-11 10:45:27 -08:00
1 parent aeee317368
commit 63e623ecb2
9 files changed
+27 -24

No files matched your search

+6 -8
View File
@@ -66,24 +66,22 @@ void sleep_ms(int ms) {
// Return the current time formatted as Minutes:Seconds:Milliseconds
// in the form 00:00:000.
void GetTimeFormatted(char formattedTime[13]) {
void GetTimeFormatted(char formattedTime[11]) {
time_t sysTime;
struct tm * gmTime;
char tmp[13];
time(&sysTime);
gmTime = localtime(&sysTime);
strftime(tmp, 6, "%M:%S", gmTime);
struct tm *gmTime = localtime(&sysTime);
char tmp[6];
strftime(tmp, sizeof(tmp), "%M:%S", gmTime);
// Now tack on the milliseconds
#ifdef _WIN32
struct timeb tp;
(void)::ftime(&tp);
snprintf(formattedTime, 13, "%s:%03i", tmp, tp.millitm);
snprintf(formattedTime, 11, "%s:%03i", tmp, tp.millitm);
#else
struct timeval t;
(void)gettimeofday(&t, NULL);
snprintf(formattedTime, 13, "%s:%03d", tmp, (int)(t.tv_usec / 1000));
snprintf(formattedTime, 11, "%s:%03d", tmp, (int)(t.tv_usec / 1000));
#endif
}