diff options
author | Antony Dovgal <tony2001@php.net> | 2006-06-22 21:03:48 +0000 |
---|---|---|
committer | Antony Dovgal <tony2001@php.net> | 2006-06-22 21:03:48 +0000 |
commit | a3d2ed63562651e0571b28cce1b7d3beb77c3a87 (patch) | |
tree | 48fcd9669ac74d3c8877ca63566bdd0940251f0c /ext/date | |
parent | fbbfdafe0a8c1c0614ad6a261eae92b14918d137 (diff) | |
download | php-git-a3d2ed63562651e0571b28cce1b7d3beb77c3a87.tar.gz |
timelib_day_of_week_ex() returns -1 if the year is less than 1753
don't use its return value directly, as accessing array element with negative index may lead to unpredictable result (crash?)
Diffstat (limited to 'ext/date')
-rw-r--r-- | ext/date/php_date.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/ext/date/php_date.c b/ext/date/php_date.c index e0e44855bf..3982341801 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -679,6 +679,26 @@ static char *english_suffix(timelib_sll number) } /* }}} */ +/* {{{ day of week helpers */ +char *php_date_full_day_name(timelib_sll y, timelib_sll m, timelib_sll d) +{ + timelib_sll day_of_week = timelib_day_of_week(y, m, d); + if (day_of_week < 0) { + return "Unknown"; + } + return day_full_names[day_of_week]; +} + +char *php_date_short_day_name(timelib_sll y, timelib_sll m, timelib_sll d) +{ + timelib_sll day_of_week = timelib_day_of_week(y, m, d); + if (day_of_week < 0) { + return "Unknown"; + } + return day_short_names[day_of_week]; +} +/* }}} */ + /* {{{ date_format - (gm)date helper */ typedef struct { @@ -765,8 +785,8 @@ static inline int date_spprintf(char **str, size_t size TSRMLS_DC, const char *f return c; } -#define dayname_short(s,l) l ? loc_dat->day_shortname[s] : day_short_names[s] -#define dayname_full(s,l) l ? loc_dat->day_fullname[s] : day_full_names[s] +#define dayname_short(s,l) s < 0 ? "Unknown" : (l ? loc_dat->day_shortname[s] : day_short_names[s]) +#define dayname_full(s,l) s < 0 ? "Unknown" : (l ? loc_dat->day_fullname[s] : day_full_names[s]) #define monthname_short(s,l) l ? loc_dat->month_shortname[s] : mon_short_names[s] #define monthname_full(s,l) l ? loc_dat->month_fullname[s] : mon_full_names[s] #define am_pm_lower_full(s,l) l ? loc_dat->am_pm_name[s] : am_pm_lower_names[s] @@ -887,7 +907,7 @@ static char *date_format(char *format, int format_len, int *return_len, timelib_ ); break; case 'r': length = date_spprintf(&buffer, 96 TSRMLS_CC, "%3s, %02d %3s %04d %02d:%02d:%02d %c%02d%02d", - day_short_names[timelib_day_of_week(t->y, t->m, t->d)], + php_date_short_day_name(t->y, t->m, t->d), (int) t->d, mon_short_names[t->m - 1], (int) t->y, (int) t->h, (int) t->i, (int) t->s, localtime ? ((offset->offset < 0) ? '-' : '+') : '+', @@ -1534,7 +1554,7 @@ PHP_FUNCTION(getdate) add_assoc_long(return_value, "mon", ts->m); add_assoc_long(return_value, "year", ts->y); add_assoc_long(return_value, "yday", timelib_day_of_year(ts->y, ts->m, ts->d)); - add_assoc_string(return_value, "weekday", day_full_names[timelib_day_of_week(ts->y, ts->m, ts->d)], 1); + add_assoc_string(return_value, "weekday", php_date_full_day_name(ts->y, ts->m, ts->d), 1); add_assoc_string(return_value, "month", mon_full_names[ts->m - 1], 1); add_index_long(return_value, 0, timestamp); |