tony2001                Sat Aug  9 22:01:35 2008 UTC

  Modified files:              (Branch: PHP_5_2)
    /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.15&r2=1.20.2.6.2.16&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.15 
php-src/ext/date/lib/parse_tz.c:1.20.2.6.2.16
--- php-src/ext/date/lib/parse_tz.c:1.20.2.6.2.15       Tue Jul  8 18:02:32 2008
+++ php-src/ext/date/lib/parse_tz.c     Sat Aug  9 22:01:35 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: parse_tz.c,v 1.20.2.6.2.15 2008/07/08 18:02:32 derick Exp $ */
+/* $Id: parse_tz.c,v 1.20.2.6.2.16 2008/08/09 22:01:35 tony2001 Exp $ */
 
 #include "timelib.h"
 
@@ -125,46 +125,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);
 }
 
 void timelib_dump_tzinfo(timelib_tzinfo *tz)



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

Reply via email to