From c68b28f25085bea95a857bd0b80c15b6a85a4a2b Mon Sep 17 00:00:00 2001 From: Antony Dovgal Date: Tue, 11 Jul 2006 14:15:38 +0000 Subject: [PATCH] fix segfault in jfmonthname(), add test fix tests (I don't have /home/hartmut here =)) --- ext/calendar/gregor.c | 7 +++ ext/calendar/tests/cal_info.phpt | 6 ++- ext/calendar/tests/easter_date.phpt | 10 ++-- ext/calendar/tests/jdtomonthname.phpt | 71 +++++++++++++++++++++++++++ ext/calendar/tests/jdtounix.phpt | 2 + 5 files changed, 90 insertions(+), 6 deletions(-) create mode 100644 ext/calendar/tests/jdtomonthname.phpt diff --git a/ext/calendar/gregor.c b/ext/calendar/gregor.c index f48950901a6..c9c0bf761b4 100644 --- a/ext/calendar/gregor.c +++ b/ext/calendar/gregor.c @@ -154,6 +154,13 @@ void SdnToGregorian( } temp = (sdn + GREGOR_SDN_OFFSET) * 4 - 1; + if (temp < 0) { + *pYear = 0; + *pMonth = 0; + *pDay = 0; + return; + } + /* Calculate the century (year/100). */ century = temp / DAYS_PER_400_YEARS; diff --git a/ext/calendar/tests/cal_info.phpt b/ext/calendar/tests/cal_info.phpt index ae57a87724a..2e3e612925c 100644 --- a/ext/calendar/tests/cal_info.phpt +++ b/ext/calendar/tests/cal_info.phpt @@ -1,5 +1,7 @@ --TEST-- cal_info() +--INI-- +date.timezone=UTC --SKIPIF-- --FILE-- @@ -8,7 +10,7 @@ cal_info() print_r(cal_info(1)); print_r(cal_info(99999)); ?> ---EXPECT-- +--EXPECTF-- Array ( [0] => Array @@ -211,4 +213,4 @@ Array [calsymbol] => CAL_JULIAN ) -Warning: cal_info(): invalid calendar ID 99999. in /home/hartmut/projects/php/dev/head/ext/calendar/tests/cal_info.php on line 4 +Warning: cal_info(): invalid calendar ID 99999. in %s on line %d diff --git a/ext/calendar/tests/easter_date.phpt b/ext/calendar/tests/easter_date.phpt index ab00e40c7db..55a3670dad2 100644 --- a/ext/calendar/tests/easter_date.phpt +++ b/ext/calendar/tests/easter_date.phpt @@ -1,5 +1,7 @@ --TEST-- easter_date() +--INI-- +date.timezone=UTC --SKIPIF-- --FILE-- @@ -10,9 +12,9 @@ echo date("Y-m-d", easter_date(2002))."\n"; echo date("Y-m-d", easter_date(1492))."\n"; ?> --EXPECTF-- -2000-04-23 -2001-04-15 -2002-03-31 +2000-04-22 +2001-04-14 +2002-03-30 -Warning: easter_date(): This function is only valid for years between 1970 and 2037 inclusive in %seaster_date.php on line 5 +Warning: easter_date(): This function is only valid for years between 1970 and 2037 inclusive in %s on line %d 1970-01-01 diff --git a/ext/calendar/tests/jdtomonthname.phpt b/ext/calendar/tests/jdtomonthname.phpt new file mode 100644 index 00000000000..1b5118a96f6 --- /dev/null +++ b/ext/calendar/tests/jdtomonthname.phpt @@ -0,0 +1,71 @@ +--TEST-- +jdtomonthname() test +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +string(3) "Jan" +string(7) "January" +string(3) "Jan" +string(7) "January" +string(6) "Shevat" +string(0) "" +string(3) "Jan" +string(7) "January" +string(3) "Dec" +string(8) "December" +string(5) "Tevet" +string(0) "" +string(0) "" +string(0) "" +string(0) "" +string(0) "" +string(0) "" +string(0) "" + +Warning: jdmonthname() expects parameter 1 to be long, array given in %s on line %d +bool(false) + +Warning: jdmonthname() expects parameter 1 to be long, array given in %s on line %d +bool(false) + +Warning: jdmonthname() expects parameter 1 to be long, array given in %s on line %d +bool(false) + +Warning: jdmonthname() expects parameter 1 to be long, array given in %s on line %d +bool(false) + +Warning: jdmonthname() expects parameter 1 to be long, array given in %s on line %d +bool(false) + +Warning: jdmonthname() expects parameter 1 to be long, array given in %s on line %d +bool(false) +string(0) "" +string(0) "" +string(0) "" +string(0) "" +string(6) "AdarII" +string(0) "" +Done diff --git a/ext/calendar/tests/jdtounix.phpt b/ext/calendar/tests/jdtounix.phpt index 055f7fe117f..8d855433003 100644 --- a/ext/calendar/tests/jdtounix.phpt +++ b/ext/calendar/tests/jdtounix.phpt @@ -1,5 +1,7 @@ --TEST-- jdtounix() +--INI-- +date.timezone=UTC --SKIPIF-- --FILE--