aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/ChangeLog10
-rw-r--r--lib-src/b2m.c19
-rw-r--r--lib-src/fakemail.c19
3 files changed, 26 insertions, 22 deletions
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog
index 72ff56c2dfd..a38c0cb6770 100644
--- a/lib-src/ChangeLog
+++ b/lib-src/ChangeLog
@@ -1,3 +1,13 @@
12006-04-02 Paul Eggert <eggert@cs.ucla.edu>
2
3 * b2m.c (main): Don't include <limits.h>.
4 (TM_YEAR_BASE): New macro.
5 (TM_YEAR_IN_ASCTIME_RANGE): Don't define if already defined, so
6 that s/ files can override this. Use the more-conservative range
7 1000-9999.
8 (main): Check for asctime returning NULL.
9 * fakemail.c: Likewise.
10
12006-03-27 Paul Eggert <eggert@cs.ucla.edu> 112006-03-27 Paul Eggert <eggert@cs.ucla.edu>
2 12
3 * b2m.c: Include <limits.h>. 13 * b2m.c: Include <limits.h>.
diff --git a/lib-src/b2m.c b/lib-src/b2m.c
index adaa736bcd9..a3ab9a5bb9a 100644
--- a/lib-src/b2m.c
+++ b/lib-src/b2m.c
@@ -26,7 +26,6 @@
26#undef static 26#undef static
27#endif 27#endif
28 28
29#include <limits.h>
30#include <stdio.h> 29#include <stdio.h>
31#include <time.h> 30#include <time.h>
32#include <sys/types.h> 31#include <sys/types.h>
@@ -45,15 +44,13 @@
45 44
46typedef int logical; 45typedef int logical;
47 46
48/* True if TM_YEAR is a struct tm's tm_year value that is acceptable 47#define TM_YEAR_BASE 1900
49 to asctime. Glibc asctime returns a useful string unless TM_YEAR 48
50 is nearly INT_MAX, but the C Standard lets C libraries overrun a 49/* Nonzero if TM_YEAR is a struct tm's tm_year value that causes
51 buffer if TM_YEAR needs more than 4 bytes. */ 50 asctime to have well-defined behavior. */
52#ifdef __GLIBC__ 51#ifndef TM_YEAR_IN_ASCTIME_RANGE
53# define TM_YEAR_IN_ASCTIME_RANGE(tm_year) ((tm_year) <= INT_MAX - 1900)
54#else
55# define TM_YEAR_IN_ASCTIME_RANGE(tm_year) \ 52# define TM_YEAR_IN_ASCTIME_RANGE(tm_year) \
56 (-999 - 1900 <= (tm_year) && (tm_year) <= 9999 - 1900) 53 (1000 - TM_YEAR_BASE <= (tm_year) && (tm_year) <= 9999 - TM_YEAR_BASE)
57#endif 54#endif
58 55
59/* 56/*
@@ -148,9 +145,9 @@ main (argc, argv)
148 Don't use 'ctime', as that might dump core if the hardware clock 145 Don't use 'ctime', as that might dump core if the hardware clock
149 is set to a bizarre value. */ 146 is set to a bizarre value. */
150 tm = localtime (&ltoday); 147 tm = localtime (&ltoday);
151 if (! (tm && TM_YEAR_IN_ASCTIME_RANGE (tm->tm_year))) 148 if (! (tm && TM_YEAR_IN_ASCTIME_RANGE (tm->tm_year)
149 && (today = asctime (tm))))
152 fatal ("current time is out of range"); 150 fatal ("current time is out of range");
153 today = asctime (tm);
154 data.size = 200; 151 data.size = 200;
155 data.buffer = xnew (200, char); 152 data.buffer = xnew (200, char);
156 153
diff --git a/lib-src/fakemail.c b/lib-src/fakemail.c
index 2c2b462e366..6b8634f34ab 100644
--- a/lib-src/fakemail.c
+++ b/lib-src/fakemail.c
@@ -53,7 +53,6 @@ main ()
53#include "ntlib.h" 53#include "ntlib.h"
54#endif 54#endif
55 55
56#include <limits.h>
57#include <stdio.h> 56#include <stdio.h>
58#include <string.h> 57#include <string.h>
59#include <ctype.h> 58#include <ctype.h>
@@ -71,15 +70,13 @@ main ()
71#define true 1 70#define true 1
72#define false 0 71#define false 0
73 72
74/* True if TM_YEAR is a struct tm's tm_year value that is acceptable 73#define TM_YEAR_BASE 1900
75 to asctime. Glibc asctime returns a useful string unless TM_YEAR 74
76 is nearly INT_MAX, but the C Standard lets C libraries overrun a 75/* Nonzero if TM_YEAR is a struct tm's tm_year value that causes
77 buffer if TM_YEAR needs more than 4 bytes. */ 76 asctime to have well-defined behavior. */
78#ifdef __GLIBC__ 77#ifndef TM_YEAR_IN_ASCTIME_RANGE
79# define TM_YEAR_IN_ASCTIME_RANGE(tm_year) ((tm_year) <= INT_MAX - 1900)
80#else
81# define TM_YEAR_IN_ASCTIME_RANGE(tm_year) \ 78# define TM_YEAR_IN_ASCTIME_RANGE(tm_year) \
82 (-999 - 1900 <= (tm_year) && (tm_year) <= 9999 - 1900) 79 (1000 - TM_YEAR_BASE <= (tm_year) && (tm_year) <= 9999 - TM_YEAR_BASE)
83#endif 80#endif
84 81
85/* Various lists */ 82/* Various lists */
@@ -378,9 +375,9 @@ make_file_preface ()
378 Don't use 'ctime', as that might dump core if the hardware clock 375 Don't use 'ctime', as that might dump core if the hardware clock
379 is set to a bizarre value. */ 376 is set to a bizarre value. */
380 tm = localtime (&idiotic_interface); 377 tm = localtime (&idiotic_interface);
381 if (! (tm && TM_YEAR_IN_ASCTIME_RANGE (tm->tm_year))) 378 if (! (tm && TM_YEAR_IN_ASCTIME_RANGE (tm->tm_year)
379 && (the_date = asctime (tm))))
382 fatal ("current time is out of range", 0); 380 fatal ("current time is out of range", 0);
383 the_date = asctime (tm);
384 /* the_date has an unwanted newline at the end */ 381 /* the_date has an unwanted newline at the end */
385 date_length = strlen (the_date) - 1; 382 date_length = strlen (the_date) - 1;
386 the_date[date_length] = '\0'; 383 the_date[date_length] = '\0';