[PHP-CVS] cvs: php-src /ext/calendar cal_unix.c /ext/date php_date.c /ext/mime_magic mime_magic.c /main main.c

2007-06-07 Thread Antony Dovgal
tony2001Thu Jun  7 08:46:32 2007 UTC

  Modified files:  
/php-src/ext/calendar   cal_unix.c 
/php-src/ext/date   php_date.c 
/php-src/ext/mime_magic mime_magic.c 
/php-src/main   main.c 
  Log:
  check return value of *time_r() functions for NULL
  more checks will follow
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/calendar/cal_unix.c?r1=1.22r2=1.23diff_format=u
Index: php-src/ext/calendar/cal_unix.c
diff -u php-src/ext/calendar/cal_unix.c:1.22 
php-src/ext/calendar/cal_unix.c:1.23
--- php-src/ext/calendar/cal_unix.c:1.22Mon Jan  1 09:29:21 2007
+++ php-src/ext/calendar/cal_unix.c Thu Jun  7 08:46:32 2007
@@ -47,8 +47,11 @@
   }
 
   ta = php_localtime_r(timestamp, tmbuf);
+  if (!ta) {
+ RETURN_FALSE;
+  }
+
   jdate = GregorianToSdn(ta-tm_year+1900, ta-tm_mon+1, ta-tm_mday);
-  
   RETURN_LONG(jdate);
 }
 /* }}} */
http://cvs.php.net/viewvc.cgi/php-src/ext/date/php_date.c?r1=1.139r2=1.140diff_format=u
Index: php-src/ext/date/php_date.c
diff -u php-src/ext/date/php_date.c:1.139 php-src/ext/date/php_date.c:1.140
--- php-src/ext/date/php_date.c:1.139   Thu Jun  7 02:21:55 2007
+++ php-src/ext/date/php_date.c Thu Jun  7 08:46:32 2007
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: php_date.c,v 1.139 2007/06/07 02:21:55 iliaa Exp $ */
+/* $Id: php_date.c,v 1.140 2007/06/07 08:46:32 tony2001 Exp $ */
 
 #include php.h
 #include php_streams.h
@@ -583,16 +583,18 @@
{
struct tm *ta, tmbuf;
time_t the_time;
-   char  *tzid;
+   char  *tzid = NULL;

the_time = time(NULL);
ta = php_localtime_r(the_time, tmbuf);
-   tzid = timelib_timezone_id_from_abbr(ta-tm_zone, 
ta-tm_gmtoff, ta-tm_isdst);
+   if (ta) {
+   tzid = timelib_timezone_id_from_abbr(ta-tm_zone, 
ta-tm_gmtoff, ta-tm_isdst);
+   }
if (! tzid) {
tzid = UTC;
}

-   php_error_docref(NULL TSRMLS_CC, E_STRICT, DATE_TZ_ERRMSG We 
selected '%s' for '%s/%.1f/%s' instead, tzid, ta-tm_zone, (float) 
(ta-tm_gmtoff / 3600), ta-tm_isdst ? DST : no DST);
+   php_error_docref(NULL TSRMLS_CC, E_STRICT, DATE_TZ_ERRMSG We 
selected '%s' for '%s/%.1f/%s' instead, tzid, ta ? ta-tm_zone : Unknown, ta 
? (float) (ta-tm_gmtoff / 3600) : 0, ta ? (ta-tm_isdst ? DST : no DST) : 
Unknown);
return tzid;
}
 #endif
http://cvs.php.net/viewvc.cgi/php-src/ext/mime_magic/mime_magic.c?r1=1.56r2=1.57diff_format=u
Index: php-src/ext/mime_magic/mime_magic.c
diff -u php-src/ext/mime_magic/mime_magic.c:1.56 
php-src/ext/mime_magic/mime_magic.c:1.57
--- php-src/ext/mime_magic/mime_magic.c:1.56Mon May 28 23:33:13 2007
+++ php-src/ext/mime_magic/mime_magic.c Thu Jun  7 08:46:32 2007
@@ -15,7 +15,7 @@
   | Author: Hartmut Holzgraefe  [EMAIL PROTECTED]   |
   +--+
 
-  $Id: mime_magic.c,v 1.56 2007/05/28 23:33:13 iliaa Exp $ 
+  $Id: mime_magic.c,v 1.57 2007/06/07 08:46:32 tony2001 Exp $ 
 
   This module contains a lot of stuff taken from Apache mod_mime_magic,
   so the license section is a little bit longer than usual:
@@ -1764,6 +1764,9 @@
{
char ctimebuf[52];
pp = php_ctime_r((time_t *) p-l, ctimebuf);
+   if (!pp) {
+   return;
+   }
if ((rt = strchr(pp, '\n')) != NULL) {
*rt = '\0';
}
http://cvs.php.net/viewvc.cgi/php-src/main/main.c?r1=1.728r2=1.729diff_format=u
Index: php-src/main/main.c
diff -u php-src/main/main.c:1.728 php-src/main/main.c:1.729
--- php-src/main/main.c:1.728   Thu Apr 26 09:39:03 2007
+++ php-src/main/main.c Thu Jun  7 08:46:32 2007
@@ -18,7 +18,7 @@
+--+
 */
 
-/* $Id: main.c,v 1.728 2007/04/26 09:39:03 tony2001 Exp $ */
+/* $Id: main.c,v 1.729 2007/06/07 08:46:32 tony2001 Exp $ */
 
 /* {{{ includes
  */
@@ -1132,8 +1132,12 @@
time(curtime);
ta = php_localtime_r(curtime, tmbuf);
datetime_str = php_asctime_r(ta, asctimebuf);
-   datetime_str[strlen(datetime_str)-1]=0; /* get 
rid of the trailing newline */
-   snprintf(memory_leak_buf, 
sizeof(memory_leak_buf), [%s]  Script:  '%s'\n, datetime_str, 
SAFE_FILENAME(SG(request_info).path_translated));
+   if (datetime_str) {
+   datetime_str[strlen(datetime_str)-1]=0; 
/* get rid of the trailing newline */
+  

[PHP-CVS] cvs: php-src /ext/calendar cal_unix.c

2006-10-07 Thread Hannes Magnusson
bjori   Sat Oct  7 15:14:57 2006 UTC

  Modified files:  
/php-src/ext/calendar   cal_unix.c 
  Log:
  Avoid portability problems
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/calendar/cal_unix.c?r1=1.20r2=1.21diff_format=u
Index: php-src/ext/calendar/cal_unix.c
diff -u php-src/ext/calendar/cal_unix.c:1.20 
php-src/ext/calendar/cal_unix.c:1.21
--- php-src/ext/calendar/cal_unix.c:1.20Wed Oct  4 12:50:02 2006
+++ php-src/ext/calendar/cal_unix.c Sat Oct  7 15:14:57 2006
@@ -28,15 +28,21 @@
Convert UNIX timestamp to Julian Day */
 PHP_FUNCTION(unixtojd)
 {
-  time_t timestamp = time(NULL);
-  long jdate; 
+  time_t timestamp;
+  long jdate, t;
   struct tm *ta, tmbuf;

-  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |l, timestamp) == 
FAILURE) {
+  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |l, t) == FAILURE) {
 return;
   }
 
-  if(timestamp  0) {
+  if (ZEND_NUM_ARGS()) {
+timestamp = (time_t) t;
+  } else {
+timestamp = time(NULL);
+  }
+
+  if (timestamp  0) {
RETURN_FALSE;
   }
 

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/calendar cal_unix.c

2006-10-04 Thread Hannes Magnusson
bjori   Wed Oct  4 12:50:02 2006 UTC

  Modified files:  
/php-src/ext/calendar   cal_unix.c 
  Log:
  Update to the new parameter parsing API
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/calendar/cal_unix.c?r1=1.19r2=1.20diff_format=u
Index: php-src/ext/calendar/cal_unix.c
diff -u php-src/ext/calendar/cal_unix.c:1.19 
php-src/ext/calendar/cal_unix.c:1.20
--- php-src/ext/calendar/cal_unix.c:1.19Sun Jan  1 13:09:48 2006
+++ php-src/ext/calendar/cal_unix.c Wed Oct  4 12:50:02 2006
@@ -28,28 +28,19 @@
Convert UNIX timestamp to Julian Day */
 PHP_FUNCTION(unixtojd)
 {
-  zval *timestamp;
+  time_t timestamp = time(NULL);
   long jdate; 
-  time_t t;
   struct tm *ta, tmbuf;
-  int myargc=ZEND_NUM_ARGS();

-  if ((myargc  1) || (zend_get_parameters(ht, myargc, timestamp) != 
SUCCESS)) {
-WRONG_PARAM_COUNT;
+  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |l, timestamp) == 
FAILURE) {
+return;
   }
 
-  if(myargc==1) {
-convert_to_long(timestamp);
-t = Z_LVAL_P(timestamp);
-  } else {
-t = time(NULL);
-  }
-
-  if(t  0) {
+  if(timestamp  0) {
RETURN_FALSE;
   }
 
-  ta = php_localtime_r(t, tmbuf);
+  ta = php_localtime_r(timestamp, tmbuf);
   jdate = GregorianToSdn(ta-tm_year+1900, ta-tm_mon+1, ta-tm_mday);
   
   RETURN_LONG(jdate);
@@ -60,17 +51,13 @@
Convert Julian Day to UNIX timestamp */
 PHP_FUNCTION(jdtounix)
 {
-  zval *jday;
-  long uday;
+  long uday, jday;
 
-  if ((ZEND_NUM_ARGS()!= 1) || (zend_get_parameters(ht, 1, jday) != SUCCESS)) 
{
-WRONG_PARAM_COUNT;
+  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, l, jday) != SUCCESS) 
{
+return;
   }
   
-  convert_to_long(jday);
-
-  uday = Z_LVAL_P(jday) - 2440588 /* J.D. of 1.1.1970 */;
-  
+  uday = jday - 2440588; /* J.D. of 1.1.1970 */
   if(uday0) RETURN_FALSE; /* before beginning of unix epoch */ 
   if(uday24755) RETURN_FALSE; /* behind end of unix epoch */
 

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-CVS] cvs: php-src /ext/calendar cal_unix.c

2006-10-04 Thread Andrei Zmievski

Hannes,

It's better to pass a real long to the zend_parse_parameters and then 
cast it to (time_t) to avoid portability issues.


-Andrei

On Oct 4, 2006, at 5:50 AM, Hannes Magnusson wrote:


-  zval *timestamp;
+  time_t timestamp = time(NULL);
   long jdate;
-  time_t t;
   struct tm *ta, tmbuf;
-  int myargc=ZEND_NUM_ARGS();

-  if ((myargc  1) || (zend_get_parameters(ht, myargc, timestamp) != 
SUCCESS)) {

-WRONG_PARAM_COUNT;
+  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |l, 
timestamp) == FAILURE) {

+return;
   }


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php