[PHP-CVS] cvs: php-src(PHP_5_3) /ext/date/lib parse_tz.c

2009-04-25 Thread Nuno Lopes
nlopess Sat Apr 25 16:33:41 2009 UTC

  Modified files:  (Branch: PHP_5_3)
/php-src/ext/date/lib   parse_tz.c 
  Log:
  fix strict aliasing problems.
  this should fix the crash that Sebastian was having with gcc 4.4. Please 
confirm this is the case
  
http://cvs.php.net/viewvc.cgi/php-src/ext/date/lib/parse_tz.c?r1=1.20.2.6.2.13.2.5&r2=1.20.2.6.2.13.2.6&diff_format=u
Index: php-src/ext/date/lib/parse_tz.c
diff -u php-src/ext/date/lib/parse_tz.c:1.20.2.6.2.13.2.5 
php-src/ext/date/lib/parse_tz.c:1.20.2.6.2.13.2.6
--- php-src/ext/date/lib/parse_tz.c:1.20.2.6.2.13.2.5   Wed Dec 31 11:15:35 2008
+++ php-src/ext/date/lib/parse_tz.c Sat Apr 25 16:33:41 2009
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: parse_tz.c,v 1.20.2.6.2.13.2.5 2008/12/31 11:15:35 sebastian Exp $ */
+/* $Id: parse_tz.c,v 1.20.2.6.2.13.2.6 2009/04/25 16:33:41 nlopess Exp $ */
 
 #include "timelib.h"
 
@@ -49,7 +49,7 @@
 #define timelib_conv_int(l) ((l & 0x00ff) << 24) + ((l & 0xff00) << 8) 
+ ((l & 0x00ff) >> 8) + ((l & 0xff00) >> 24)
 #endif
 
-static void read_preamble(char **tzf, timelib_tzinfo *tz)
+static void read_preamble(const unsigned char **tzf, timelib_tzinfo *tz)
 {
/* skip ID */
*tzf += 4;
@@ -67,7 +67,7 @@
*tzf += 13;
 }
 
-static void read_header(char **tzf, timelib_tzinfo *tz)
+static void read_header(const unsigned char **tzf, timelib_tzinfo *tz)
 {
uint32_t buffer[6];
 
@@ -81,7 +81,7 @@
*tzf += sizeof(buffer);
 }
 
-static void read_transistions(char **tzf, timelib_tzinfo *tz)
+static void read_transistions(const unsigned char **tzf, timelib_tzinfo *tz)
 {
int32_t *buffer = NULL;
uint32_t i;
@@ -110,7 +110,7 @@
tz->trans_idx = cbuffer;
 }
 
-static void read_types(char **tzf, timelib_tzinfo *tz)
+static void read_types(const unsigned char **tzf, timelib_tzinfo *tz)
 {
unsigned char *buffer;
int32_t *leap_buffer;
@@ -191,7 +191,7 @@
}
 }
 
-static void read_location(char **tzf, timelib_tzinfo *tz)
+static void read_location(const unsigned char **tzf, timelib_tzinfo *tz)
 {
uint32_t buffer[3];
uint32_t comments_len;
@@ -317,11 +317,11 @@
if (seek_to_tz_position(&tzf, timezone, tzdb)) {
tmp = timelib_tzinfo_ctor(timezone);
 
-   read_preamble((char**) &tzf, tmp);
-   read_header((char**) &tzf, tmp);
-   read_transistions((char**) &tzf, tmp);
-   read_types((char**) &tzf, tmp);
-   read_location((char**) &tzf, tmp);
+   read_preamble(&tzf, tmp);
+   read_header(&tzf, tmp);
+   read_transistions(&tzf, tmp);
+   read_types(&tzf, tmp);
+   read_location(&tzf, tmp);
} else {
tmp = NULL;
}



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



[PHP-CVS] cvs: php-src(PHP_5_3) /ext/date/lib parse_tz.c

2008-08-09 Thread Antony Dovgal
tony2001Sat Aug  9 22:01:08 2008 UTC

  Modified files:  (Branch: PHP_5_3)
/php-src/ext/date/lib   parse_tz.c 
  Log:
  MFH: do not fail & segfault if malloc(0) returns NULL, that's expected
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/date/lib/parse_tz.c?r1=1.20.2.6.2.13.2.3&r2=1.20.2.6.2.13.2.4&diff_format=u
Index: php-src/ext/date/lib/parse_tz.c
diff -u php-src/ext/date/lib/parse_tz.c:1.20.2.6.2.13.2.3 
php-src/ext/date/lib/parse_tz.c:1.20.2.6.2.13.2.4
--- php-src/ext/date/lib/parse_tz.c:1.20.2.6.2.13.2.3   Fri Jul 18 14:33:53 2008
+++ php-src/ext/date/lib/parse_tz.c Sat Aug  9 22:01:08 2008
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: parse_tz.c,v 1.20.2.6.2.13.2.3 2008/07/18 14:33:53 derick Exp $ */
+/* $Id: parse_tz.c,v 1.20.2.6.2.13.2.4 2008/08/09 22:01:08 tony2001 Exp $ */
 
 #include "timelib.h"
 
@@ -143,46 +143,52 @@
memcpy(tz->timezone_abbr, *tzf, sizeof(char) * tz->charcnt);
*tzf += sizeof(char) * tz->charcnt;
 
-   leap_buffer = (int32_t *) malloc(tz->leapcnt * 2 * sizeof(int32_t));
-   if (!leap_buffer) {
-   return;
-   }
-   memcpy(leap_buffer, *tzf, sizeof(int32_t) * tz->leapcnt * 2);
-   *tzf += sizeof(int32_t) * tz->leapcnt * 2;
+   if (tz->leapcnt) {
+   leap_buffer = (int32_t *) malloc(tz->leapcnt * 2 * 
sizeof(int32_t));
+   if (!leap_buffer) {
+   return;
+   }
+   memcpy(leap_buffer, *tzf, sizeof(int32_t) * tz->leapcnt * 2);
+   *tzf += sizeof(int32_t) * tz->leapcnt * 2;
 
-   tz->leap_times = (tlinfo*) malloc(tz->leapcnt * sizeof(tlinfo));
-   if (!tz->leap_times) {
-   return;
-   }
-   for (i = 0; i < tz->leapcnt; i++) {
-   tz->leap_times[i].trans = timelib_conv_int(leap_buffer[i * 2]);
-   tz->leap_times[i].offset = timelib_conv_int(leap_buffer[i * 2 + 
1]);
-   }
-   free(leap_buffer);
-   
-   buffer = (unsigned char*) malloc(tz->ttisstdcnt * sizeof(unsigned 
char));
-   if (!buffer) {
-   return;
+   tz->leap_times = (tlinfo*) malloc(tz->leapcnt * sizeof(tlinfo));
+   if (!tz->leap_times) {
+   return;
+   }
+   for (i = 0; i < tz->leapcnt; i++) {
+   tz->leap_times[i].trans = 
timelib_conv_int(leap_buffer[i * 2]);
+   tz->leap_times[i].offset = 
timelib_conv_int(leap_buffer[i * 2 + 1]);
+   }
+   free(leap_buffer);
}
-   memcpy(buffer, *tzf, sizeof(unsigned char) * tz->ttisstdcnt);
-   *tzf += sizeof(unsigned char) * tz->ttisstdcnt;
 
-   for (i = 0; i < tz->ttisstdcnt; i++) {
-   tz->type[i].isstdcnt = buffer[i];
-   }
-   free(buffer);
+   if (tz->ttisstdcnt) {
+   buffer = (unsigned char*) malloc(tz->ttisstdcnt * 
sizeof(unsigned char));
+   if (!buffer) {
+   return;
+   }
+   memcpy(buffer, *tzf, sizeof(unsigned char) * tz->ttisstdcnt);
+   *tzf += sizeof(unsigned char) * tz->ttisstdcnt;
 
-   buffer = (unsigned char*) malloc(tz->ttisgmtcnt * sizeof(unsigned 
char));
-   if (!buffer) {
-   return;
+   for (i = 0; i < tz->ttisstdcnt; i++) {
+   tz->type[i].isstdcnt = buffer[i];
+   }
+   free(buffer);
}
-   memcpy(buffer, *tzf, sizeof(unsigned char) * tz->ttisgmtcnt);
-   *tzf += sizeof(unsigned char) * tz->ttisgmtcnt;
 
-   for (i = 0; i < tz->ttisgmtcnt; i++) {
-   tz->type[i].isgmtcnt = buffer[i];
+   if (tz->ttisgmtcnt) {
+   buffer = (unsigned char*) malloc(tz->ttisgmtcnt * 
sizeof(unsigned char));
+   if (!buffer) {
+   return;
+   }
+   memcpy(buffer, *tzf, sizeof(unsigned char) * tz->ttisgmtcnt);
+   *tzf += sizeof(unsigned char) * tz->ttisgmtcnt;
+
+   for (i = 0; i < tz->ttisgmtcnt; i++) {
+   tz->type[i].isgmtcnt = buffer[i];
+   }
+   free(buffer);
}
-   free(buffer);
 }
 
 static void read_location(char **tzf, timelib_tzinfo *tz)



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



[PHP-CVS] cvs: php-src(PHP_5_3) /ext/date/lib parse_tz.c unixtime2tm.c

2008-04-07 Thread Derick Rethans
derick  Mon Apr  7 17:44:04 2008 UTC

  Modified files:  (Branch: PHP_5_3)
/php-src/ext/date/lib   parse_tz.c unixtime2tm.c 
  Log:
  - MFH: Fixing returned offset.
  - MFH: Algorithm optimization.
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/date/lib/parse_tz.c?r1=1.20.2.6.2.13.2.1&r2=1.20.2.6.2.13.2.2&diff_format=u
Index: php-src/ext/date/lib/parse_tz.c
diff -u php-src/ext/date/lib/parse_tz.c:1.20.2.6.2.13.2.1 
php-src/ext/date/lib/parse_tz.c:1.20.2.6.2.13.2.2
--- php-src/ext/date/lib/parse_tz.c:1.20.2.6.2.13.2.1   Mon Dec 31 07:17:07 2007
+++ php-src/ext/date/lib/parse_tz.c Mon Apr  7 17:44:03 2008
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: parse_tz.c,v 1.20.2.6.2.13.2.1 2007/12/31 07:17:07 sebastian Exp $ */
+/* $Id: parse_tz.c,v 1.20.2.6.2.13.2.2 2008/04/07 17:44:03 derick Exp $ */
 
 #include "timelib.h"
 
@@ -391,7 +391,7 @@
switch (t->zone_type) {
case TIMELIB_ZONETYPE_ABBR:
case TIMELIB_ZONETYPE_OFFSET:
-   return t->z * 60;
+   return (t->z + t->dst) * -60;

case TIMELIB_ZONETYPE_ID:
gmt_offset = timelib_get_time_zone_info(t->sse, 
t->tz_info);
http://cvs.php.net/viewvc.cgi/php-src/ext/date/lib/unixtime2tm.c?r1=1.12.2.4.2.3.2.1&r2=1.12.2.4.2.3.2.2&diff_format=u
Index: php-src/ext/date/lib/unixtime2tm.c
diff -u php-src/ext/date/lib/unixtime2tm.c:1.12.2.4.2.3.2.1 
php-src/ext/date/lib/unixtime2tm.c:1.12.2.4.2.3.2.2
--- php-src/ext/date/lib/unixtime2tm.c:1.12.2.4.2.3.2.1 Mon Dec 31 07:17:07 2007
+++ php-src/ext/date/lib/unixtime2tm.c  Mon Apr  7 17:44:03 2008
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: unixtime2tm.c,v 1.12.2.4.2.3.2.1 2007/12/31 07:17:07 sebastian Exp $ */
+/* $Id: unixtime2tm.c,v 1.12.2.4.2.3.2.2 2008/04/07 17:44:03 derick Exp $ */
 
 #include "timelib.h"
 
@@ -76,12 +76,18 @@
*/
 
while (tmp_days <= 0) {
-   cur_year--;
-   DEBUG(printf("tmp_days=%lld, year=%lld\n", tmp_days, 
cur_year););
-   if (timelib_is_leap(cur_year)) {
-   tmp_days += DAYS_PER_LYEAR;
+   if (tmp_days < -1460970) {
+   cur_year -= 4000;
+   DEBUG(printf("tmp_days=%lld, year=%lld\n", 
tmp_days, cur_year););
+   tmp_days += 1460970;
} else {
-   tmp_days += DAYS_PER_YEAR;
+   cur_year--;
+   DEBUG(printf("tmp_days=%lld, year=%lld\n", 
tmp_days, cur_year););
+   if (timelib_is_leap(cur_year)) {
+   tmp_days += DAYS_PER_LYEAR;
+   } else {
+   tmp_days += DAYS_PER_YEAR;
+   }
}
}
remainder += SECS_PER_DAY;



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