summaryrefslogtreecommitdiffstats
path: root/usr.bin/calendar
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>2002-03-10 14:54:59 +0000
committerache <ache@FreeBSD.org>2002-03-10 14:54:59 +0000
commitbb01e620026e8d654f437b75282305b589263a68 (patch)
tree5a37935417a263b3a342664ffc141862e800ea05 /usr.bin/calendar
parente948cabaa639da963212b21b2f077d2f3acc4cc0 (diff)
downloadFreeBSD-src-bb01e620026e8d654f437b75282305b589263a68.zip
FreeBSD-src-bb01e620026e8d654f437b75282305b589263a68.tar.gz
Setlocale returns static buffer, don't assume it will be unchanged
Pointed by: phantom
Diffstat (limited to 'usr.bin/calendar')
-rw-r--r--usr.bin/calendar/day.c12
1 files changed, 8 insertions, 4 deletions
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <string.h>
#include <time.h>
#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();
}
OpenPOWER on IntegriCloud