bug in tzcode2001c: strftime locale cache

Olson, Arthur David (NCI) olsona at dc37a.nci.nih.gov
Fri Jun 15 17:01:52 UTC 2001


> The strftime locale code attempts to read the locale cache even if the
> cache wasn't set up correctly.  This leads to bogus output on your
program's
> second (and subsequent) call to strftime(), if lookup failed.
> ...
> This patch fixes this.

An alternate fix appears below.

				--ado

*** 7.62/strftime.c	Fri Jun 15 13:00:07 2001
--- 7.63/strftime.c	Fri Jun 15 13:00:07 2001
***************
*** 603,609 ****
  	static const char	locale_home[] = LOCALE_HOME;
  	static const char	lc_time[] = "LC_TIME";
  	static char *		locale_buf;
- 	static char		locale_buf_C[] = "C";
  
  	int			fd;
  	int			oldsun;	/* "...ain't got nothin' to do..."
*/
--- 603,608 ----
***************
*** 664,671 ****
  		goto bad_locale;
  	bufsize = namesize + st.st_size;
  	locale_buf = NULL;
! 	lbuf = (lbuf == NULL || lbuf == locale_buf_C) ?
! 		malloc(bufsize) : realloc(lbuf, bufsize);
  	if (lbuf == NULL)
  		goto bad_locale;
  	(void) strcpy(lbuf, name);
--- 663,669 ----
  		goto bad_locale;
  	bufsize = namesize + st.st_size;
  	locale_buf = NULL;
! 	lbuf = (lbuf == NULL) ?  malloc(bufsize) : realloc(lbuf, bufsize);
  	if (lbuf == NULL)
  		goto bad_locale;
  	(void) strcpy(lbuf, name);
***************
*** 714,720 ****
  	(void) close(fd);
  no_locale:
  	localebuf = C_time_locale;
! 	locale_buf = locale_buf_C;
  	return &localebuf;
  }
  #endif /* defined LOCALE_HOME */
--- 712,718 ----
  	(void) close(fd);
  no_locale:
  	localebuf = C_time_locale;
! 	locale_buf = NULL;
  	return &localebuf;
  }
  #endif /* defined LOCALE_HOME */





More information about the tz mailing list