From bb01e620026e8d654f437b75282305b589263a68 Mon Sep 17 00:00:00 2001 From: ache Date: Sun, 10 Mar 2002 14:54:59 +0000 Subject: Setlocale returns static buffer, don't assume it will be unchanged Pointed by: phantom --- usr.bin/calendar/day.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'usr.bin/calendar') diff --git a/usr.bin/calendar/day.c b/usr.bin/calendar/day.c index 2216b56..3f8ab25 100644 --- a/usr.bin/calendar/day.c +++ b/usr.bin/calendar/day.c @@ -42,7 +42,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include "pathnames.h" @@ -140,7 +139,7 @@ void settime(now) time_t now; { - char *oldl; + char *oldl, *lbufp; tp = localtime(&now); if ( isleap(tp->tm_year + 1900) ) { @@ -154,10 +153,15 @@ settime(now) offset = tp->tm_wday == 5 ? 3 : 1; header[5].iov_base = dayname; - oldl = setlocale(LC_TIME, NULL); + oldl = NULL; + lbufp = setlocale(LC_TIME, NULL); + if (lbufp != NULL && (oldl = strdup(lbufp)) == NULL) + errx(1, "cannot allocate memory"); (void) setlocale(LC_TIME, "C"); header[5].iov_len = strftime(dayname, sizeof(dayname), "%A", tp); - (void) setlocale(LC_TIME, oldl); + (void) setlocale(LC_TIME, (oldl != NULL ? oldl : "")); + if (oldl != NULL) + free(oldl); setnnames(); } -- cgit v1.1