From 880a8276b75dcda8985d9e17a7349d993a491219 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 9 May 2017 21:56:31 -0700 Subject: [PATCH 1/6] Avoid non-null-terminated const char arrays This is mostly to pacify picky compilers. In practice, the performance difference is likely insignificant. * asctime.c (ASCTIME_FMT, ASCTIME_FMT_B): Simplify now that month and weekday names are null-terminated. (asctime_r): Null-terminate the month and weekday names. * zdump.c (dumptime): Likewise. --- asctime.c | 12 ++++++------ zdump.c | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/asctime.c b/asctime.c index 85ebf88..1613f78 100644 --- a/asctime.c +++ b/asctime.c @@ -32,9 +32,9 @@ ** but many implementations pad anyway; most likely the standards are buggy. */ #ifdef __GNUC__ -#define ASCTIME_FMT "%.3s %.3s%3d %2.2d:%2.2d:%2.2d %-4s\n" +#define ASCTIME_FMT "%s %s%3d %2.2d:%2.2d:%2.2d %-4s\n" #else /* !defined __GNUC__ */ -#define ASCTIME_FMT "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %-4s\n" +#define ASCTIME_FMT "%s %s%3d %02.2d:%02.2d:%02.2d %-4s\n" #endif /* !defined __GNUC__ */ /* ** For years that are more than four digits we put extra spaces before the year @@ -43,9 +43,9 @@ ** that no output is better than wrong output). */ #ifdef __GNUC__ -#define ASCTIME_FMT_B "%.3s %.3s%3d %2.2d:%2.2d:%2.2d %s\n" +#define ASCTIME_FMT_B "%s %s%3d %2.2d:%2.2d:%2.2d %s\n" #else /* !defined __GNUC__ */ -#define ASCTIME_FMT_B "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %s\n" +#define ASCTIME_FMT_B "%s %s%3d %02.2d:%02.2d:%02.2d %s\n" #endif /* !defined __GNUC__ */ #define STD_ASCTIME_BUF_SIZE 26 @@ -70,10 +70,10 @@ static char buf_asctime[MAX_ASCTIME_BUF_SIZE]; char * asctime_r(register const struct tm *timeptr, char *buf) { - static const char wday_name[][3] = { + static const char wday_name[][4] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; - static const char mon_name[][3] = { + static const char mon_name[][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; diff --git a/zdump.c b/zdump.c index bf75800..36a2e79 100644 --- a/zdump.c +++ b/zdump.c @@ -1030,10 +1030,10 @@ tformat(void) static void dumptime(register const struct tm *timeptr) { - static const char wday_name[][3] = { + static const char wday_name[][4] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; - static const char mon_name[][3] = { + static const char mon_name[][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; @@ -1059,7 +1059,7 @@ dumptime(register const struct tm *timeptr) (int) (sizeof mon_name / sizeof mon_name[0])) mn = "???"; else mn = mon_name[timeptr->tm_mon]; - printf("%.3s %.3s%3d %.2d:%.2d:%.2d ", + printf("%s %s%3d %.2d:%.2d:%.2d ", wn, mn, timeptr->tm_mday, timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec); -- 2.7.4