]> granicus.if.org Git - php/commitdiff
- Added a test case for bug #45866
authorDerick Rethans <derick@php.net>
Wed, 10 Feb 2010 16:23:30 +0000 (16:23 +0000)
committerDerick Rethans <derick@php.net>
Wed, 10 Feb 2010 16:23:30 +0000 (16:23 +0000)
- Fixed tests: oo_002, bug46268
- Fixed bug #50930 (Wrong date by php_date.c patch with ancient gcc/glibc
  versions).
- Make sure faulty strings passed to DateTime::modify() notify the user.
- Revert fix for bug #50392 as it was fixed wrongly without a proper test case.
- Fixed a bug with the 'r' formatting function as the default buffer size that
  was allocated only fit 4 digit years.

ext/date/config0.m4
ext/date/lib/parse_date.c
ext/date/lib/parse_date.re
ext/date/php_date.c
ext/date/tests/bug45866.phpt [new file with mode: 0644]
ext/date/tests/bug46268.phpt
ext/date/tests/oo_002.phpt

index 3d03c8969921ecf1cfd504fa6bd4b734f20dfe71..f403104a8afbeae26eb156531acc68c87a255c3b 100644 (file)
@@ -16,8 +16,6 @@ PHP_ADD_INCLUDE([$ext_srcdir/lib])
 
 PHP_INSTALL_HEADERS([ext/date], [php_date.h lib/timelib.h lib/timelib_structs.h lib/timelib_config.h])
 
-AC_CHECK_FUNCS([llabs])
-
 cat > $ext_builddir/lib/timelib_config.h <<EOF
 #ifdef PHP_WIN32
 # include "config.w32.h"
index f33f9d5e66a16aeeae5ebd7b616169ffaba16f59..6b4d0cb7c999e94f87b59c355bcb8a04e639ab80 100644 (file)
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.13.5 on Thu Jan  7 07:53:05 2010 */
+/* Generated by re2c 0.13.5 on Wed Feb 10 15:19:16 2010 */
 #line 1 "ext/date/lib/parse_date.re"
 /*
    +----------------------------------------------------------------------+
@@ -24157,8 +24157,8 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim
 
                                        TIMELIB_CHECK_NUMBER;
                                        tptr = ptr;
-                                       if ((f = timelib_get_nr((char **) &ptr, 6)) == TIMELIB_UNSET || (ptr - tptr) < 1) {
-                                               add_pbf_error(s, "At least a single digit millisecond could not be found", string, begin);
+                                       if ((f = timelib_get_nr((char **) &ptr, 6)) == TIMELIB_UNSET || ptr - tptr != 6) {
+                                               add_pbf_error(s, "A six digit millisecond could not be found", string, begin);
                                        } else {
                                                s->time->f = (f / 1000000);
                                        }
index 21e4ebbe3162caa937bf0ca050053132d1e20cef..66e31becde8398ca15d7321abf837bef4bbb2b9f 100644 (file)
@@ -1951,8 +1951,8 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim
 
                                        TIMELIB_CHECK_NUMBER;
                                        tptr = ptr;
-                                       if ((f = timelib_get_nr((char **) &ptr, 6)) == TIMELIB_UNSET || (ptr - tptr) < 1) {
-                                               add_pbf_error(s, "At least a single digit millisecond could not be found", string, begin);
+                                       if ((f = timelib_get_nr((char **) &ptr, 6)) == TIMELIB_UNSET || ptr - tptr != 6) {
+                                               add_pbf_error(s, "A six digit millisecond could not be found", string, begin);
                                        } else {
                                                s->time->f = (f / 1000000);
                                        }
index db7f37a67df4be2b972e3d311c02b83f6f565d4d..9d43364f14b49cb49110ed678847e580c316bfd0 100644 (file)
 # include "win32/php_stdint.h"
 #endif
 
-#ifndef HAVE_LLABS
-# if defined(__GNUC__) && __GNUC__ < 3
-static __inline __int64_t llabs( __int64_t i ) { return i >= 0 ? i : -i; }
-# elif defined(NETWARE) && defined(__MWERKS__)
-static __inline long long llabs( long long i ) { return i >= 0 ? i : -i; }
-# endif
-#endif
+static __inline long long php_date_llabs( long long i ) { return i >= 0 ? i : -i; }
 
 /* {{{ arginfo */
 ZEND_BEGIN_ARG_INFO_EX(arginfo_date, 0, 0, 1)
@@ -790,7 +784,6 @@ PHP_MINIT_FUNCTION(date)
 
        php_date_global_timezone_db = NULL;
        php_date_global_timezone_db_enabled = 0;
-
        DATEG(last_errors) = NULL;
        return SUCCESS;
 }
@@ -2889,7 +2882,7 @@ PHP_FUNCTION(date_modify)
        char         *modify;
        int           modify_len;
        timelib_time *tmp_time;
-       struct timelib_error_container *error;
+       timelib_error_container *err = NULL;
 
        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &object, date_ce_date, &modify, &modify_len) == FAILURE) {
                RETURN_FALSE;
@@ -2897,13 +2890,14 @@ PHP_FUNCTION(date_modify)
        dateobj = (php_date_obj *) zend_object_store_get_object(object TSRMLS_CC);
        DATE_CHECK_INITIALIZED(dateobj->time, DateTime);
 
-       tmp_time = timelib_strtotime(modify, modify_len, &error, DATE_TIMEZONEDB);
+       tmp_time = timelib_strtotime(modify, modify_len, &err, DATE_TIMEZONEDB);
 
-       /* update last errors and warnings, and display the first one */
-       update_errors_warnings(error TSRMLS_CC);
-       if (error && error->error_count > 0) {
+       /* update last errors and warnings */
+       update_errors_warnings(err TSRMLS_CC);
+       if (err && err->error_count) {
+               /* spit out the first library error message, at least */
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse time string (%s) at position %d (%c): %s", modify,
-                       error->error_messages[0].position, error->error_messages[0].character, error->error_messages[0].message);
+                       err->error_messages[0].position, err->error_messages[0].character, err->error_messages[0].message);
                timelib_time_dtor(tmp_time);
                RETURN_FALSE;
        }
diff --git a/ext/date/tests/bug45866.phpt b/ext/date/tests/bug45866.phpt
new file mode 100644 (file)
index 0000000..a8407a6
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--
+Bug #45866 (decimal values fed to DateTime->modify() causes long execution times)
+--INI--
+date.timezone=UTC
+--FILE--
+<?php
+$date = new DateTime( '2009-07-29 16:44:23 Europe/London' );
+$date->modify( "+1.61538461538 day" );
+echo $date->format( 'r' ), "\n";
+
+$date = new DateTime( '2009-07-29 16:44:23 Europe/London' );
+$date->modify( "61538461538 day" );
+echo $date->format( 'r' ), "\n";
+
+$date = new DateTime( '2009-07-29 16:44:23 Europe/London' );
+$date->modify( "£61538461538 day" );
+echo $date->format( 'r' ), "\n";
+?>
+--EXPECTF--
+Thu, 14 Aug 168488594 16:44:23 +0000
+Thu, 14 Aug 168488594 16:44:23 +0000
+
+Warning: DateTime::modify(): Failed to parse time string (£61538461538 day) at position 0 (%s): Unexpected character in %sbug45866.php on line 11
+Wed, 29 Jul 2009 16:44:23 +0100
index dd2d4a3ca5e2c8998e90d9b526ac2331558a0d27..808fd856a9f08063f4f3154b5775d871effbfa03 100644 (file)
@@ -7,10 +7,10 @@ date_default_timezone_set('Asia/Tokyo');
 $now = new DateTime('2008-10-10 01:02:03');
 echo $now->format("Y-m-d H:i:s") . PHP_EOL;
 
-$now->modify("1 day after");
+$now->modify("1 day");
 echo $now->format("Y-m-d H:i:s") . PHP_EOL;
 
-$now->modify("1 hour after");
+$now->modify("1 hour");
 echo $now->format("Y-m-d H:i:s") . PHP_EOL;
 
 $now->setTime(0, 0, 0);
index 891af7b4f880ab8ea88efb60bd49e37c124d5305..dbf34be778f0c1bb03bed7dcf3e8d47b8d645d6a 100644 (file)
@@ -10,7 +10,7 @@ $d = new _d("1pm Aug 1 GMT 2007");
 var_dump($d->format(DateTime::RFC822));
 $c = clone $d;
 var_dump($c->format(DateTime::RFC822));
-$d->modify("1 hour after");
+$d->modify("1 hour");
 $c->modify("1 second ago");
 var_dump($d->format(DateTime::RFC822));
 var_dump($c->format(DateTime::RFC822));