On September 24, 2002 11:34 pm, Yasuo Ohgaki wrote: > Ilia A. wrote: > > '"time_t" is not defined for negative values and results may be > > unpredictable'. > > > > As I understand this statement, if you rely on a valid output when given > > a negative value you make your code dependant on an OS. Even though your > > code may work on Linux, it'll not work on Windows and possibly other > > OSes. The problem is that on Windows if a negative value is passed to > > localtime function Windows will core, as can be shown by this example: > > php -r " mktime(0,0,0,1,1,1932); ". > > That's too bad... > > > I think a better solution would be a ifdef in the datetime.c that would > > prevent negative values from being passed along to localtime() on > > Windows. And return an error specifying that current OS does not support > > negative values. > > > > What do you think? > > No objection to your solution :)
If no one objects and there are still no segvs in Windows with the attached patch, I'll drop it into the CVS tomorrow. If someone does try this patch on Windows, the following script should make for a good litmus test: <?php mktime(0,0,0,1,1,1925); mktime(0,0,0,1,1,1); mktime(3,14,7,1,19,2038); localtime((-1)*time()); ?> Ilia
Index: datetime.c =================================================================== RCS file: /repository/php4/ext/standard/datetime.c,v retrieving revision 1.95 diff -u -3 -p -r1.95 datetime.c --- datetime.c 21 Sep 2002 15:41:20 -0000 1.95 +++ datetime.c 25 Sep 2002 04:05:04 -0000 @@ -194,9 +194,13 @@ void php_mktime(INTERNAL_FUNCTION_PARAME } t = mktime(ta); - if (t == -1) { + +#ifdef PHP_WIN32 + if (t < 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Windows does not support negative values for this function"); RETURN_LONG(-1); } +#endif seconds = t - chgsecs; @@ -646,7 +650,15 @@ PHP_FUNCTION(localtime) assoc_array = Z_LVAL_PP(assoc_array_arg); break; } - if (timestamp < 0 || NULL == (ta = php_localtime_r(×tamp, &tmbuf))) { + +#ifdef PHP_WIN32 + if (timestamp < 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Windows does not support negative values for this function"); + RETURN_FALSE + } +#endif + + if (NULL == (ta = php_localtime_r(×tamp, &tmbuf))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid local time"); RETURN_FALSE; }
-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php