[PHP-CVS] com php-src: setting plausible default value for struct members: ext/date/php_date.c ext/date/tests/bug52113.phpt

2013-03-16 Thread Anatol Belski
Commit:fa3fc711d3fb54bf1746138ffcf7f46426921204
Author:Anatol Belski  Sat, 16 Mar 2013 18:07:21 +0100
Parents:   b46897941ac094e4e2fc09a5f1d4eeb7f8efca59
Branches:  PHP-5.5

Link:   
http://git.php.net/?p=php-src.git;a=commitdiff;h=fa3fc711d3fb54bf1746138ffcf7f46426921204

Log:
setting plausible default value for struct members

especially for unsigned members so they don't casted to max unsigned

Changed paths:
  M  ext/date/php_date.c
  M  ext/date/tests/bug52113.phpt


Diff:
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index b454dd0..a073aa6 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -4006,14 +4006,14 @@ static int php_date_interval_initialize_from_hash(zval 
**return_value, php_inter
 {
(*intobj)->diff = timelib_rel_time_ctor();
 
-#define PHP_DATE_INTERVAL_READ_PROPERTY(element, member, itype) \
+#define PHP_DATE_INTERVAL_READ_PROPERTY(element, member, itype, def) \
do { \
zval **z_arg = NULL; \
if (zend_hash_find(myht, element, strlen(element) + 1, (void**) 
&z_arg) == SUCCESS) { \
convert_to_long(*z_arg); \
(*intobj)->diff->member = (itype)Z_LVAL_PP(z_arg); \
} else { \
-   (*intobj)->diff->member = (itype)-1; \
+   (*intobj)->diff->member = (itype)def; \
} \
} while (0);
 
@@ -4028,21 +4028,21 @@ static int php_date_interval_initialize_from_hash(zval 
**return_value, php_inter
} \
} while (0);
 
-   PHP_DATE_INTERVAL_READ_PROPERTY("y", y, timelib_sll)
-   PHP_DATE_INTERVAL_READ_PROPERTY("m", m, timelib_sll)
-   PHP_DATE_INTERVAL_READ_PROPERTY("d", d, timelib_sll)
-   PHP_DATE_INTERVAL_READ_PROPERTY("h", h, timelib_sll)
-   PHP_DATE_INTERVAL_READ_PROPERTY("i", i, timelib_sll)
-   PHP_DATE_INTERVAL_READ_PROPERTY("s", s, timelib_sll)
-   PHP_DATE_INTERVAL_READ_PROPERTY("weekday", weekday, int)
-   PHP_DATE_INTERVAL_READ_PROPERTY("weekday_behavior", weekday_behavior, 
int)
-   PHP_DATE_INTERVAL_READ_PROPERTY("first_last_day_of", first_last_day_of, 
int)
-   PHP_DATE_INTERVAL_READ_PROPERTY("invert", invert, int);
+   PHP_DATE_INTERVAL_READ_PROPERTY("y", y, timelib_sll, -1)
+   PHP_DATE_INTERVAL_READ_PROPERTY("m", m, timelib_sll, -1)
+   PHP_DATE_INTERVAL_READ_PROPERTY("d", d, timelib_sll, -1)
+   PHP_DATE_INTERVAL_READ_PROPERTY("h", h, timelib_sll, -1)
+   PHP_DATE_INTERVAL_READ_PROPERTY("i", i, timelib_sll, -1)
+   PHP_DATE_INTERVAL_READ_PROPERTY("s", s, timelib_sll, -1)
+   PHP_DATE_INTERVAL_READ_PROPERTY("weekday", weekday, int, -1)
+   PHP_DATE_INTERVAL_READ_PROPERTY("weekday_behavior", weekday_behavior, 
int, -1)
+   PHP_DATE_INTERVAL_READ_PROPERTY("first_last_day_of", first_last_day_of, 
int, -1)
+   PHP_DATE_INTERVAL_READ_PROPERTY("invert", invert, int, 0);
PHP_DATE_INTERVAL_READ_PROPERTY_I64("days", days);
-   PHP_DATE_INTERVAL_READ_PROPERTY("special_type", special.type, unsigned 
int);
+   PHP_DATE_INTERVAL_READ_PROPERTY("special_type", special.type, unsigned 
int, 0);
PHP_DATE_INTERVAL_READ_PROPERTY_I64("special_amount", special.amount);
-   PHP_DATE_INTERVAL_READ_PROPERTY("have_weekday_relative", 
have_weekday_relative, unsigned int);
-   PHP_DATE_INTERVAL_READ_PROPERTY("have_special_relative", 
have_special_relative, unsigned int);
+   PHP_DATE_INTERVAL_READ_PROPERTY("have_weekday_relative", 
have_weekday_relative, unsigned int, 0);
+   PHP_DATE_INTERVAL_READ_PROPERTY("have_special_relative", 
have_special_relative, unsigned int, 0);
(*intobj)->initialized = 1;
 
return 0;
diff --git a/ext/date/tests/bug52113.phpt b/ext/date/tests/bug52113.phpt
index 226dae5..862e92e 100644
--- a/ext/date/tests/bug52113.phpt
+++ b/ext/date/tests/bug52113.phpt
@@ -189,13 +189,13 @@ object(DateInterval)#8 (15) {
   ["days"]=>
   string(4) "2400"
   ["special_type"]=>
-  int(-1)
+  int(0)
   ["special_amount"]=>
   string(2) "-1"
   ["have_weekday_relative"]=>
-  int(-1)
+  int(0)
   ["have_special_relative"]=>
-  int(-1)
+  int(0)
 }
 object(DatePeriod)#9 (6) {
   ["start"]=>


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



[PHP-CVS] com php-src: setting plausible default value for struct members: ext/date/php_date.c ext/date/tests/bug52113.phpt

2013-03-16 Thread Anatol Belski
Commit:add5420d89624550b1e6e72f960413ff7d0a69a2
Author:Anatol Belski  Sat, 16 Mar 2013 18:07:21 +0100
Parents:   c1cf7538f07d8f905afbff5e82f4c727f6cb9fee
Branches:  master

Link:   
http://git.php.net/?p=php-src.git;a=commitdiff;h=add5420d89624550b1e6e72f960413ff7d0a69a2

Log:
setting plausible default value for struct members

especially for unsigned members so they don't casted to max unsigned

Changed paths:
  M  ext/date/php_date.c
  M  ext/date/tests/bug52113.phpt


Diff:
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index b454dd0..a073aa6 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -4006,14 +4006,14 @@ static int php_date_interval_initialize_from_hash(zval 
**return_value, php_inter
 {
(*intobj)->diff = timelib_rel_time_ctor();
 
-#define PHP_DATE_INTERVAL_READ_PROPERTY(element, member, itype) \
+#define PHP_DATE_INTERVAL_READ_PROPERTY(element, member, itype, def) \
do { \
zval **z_arg = NULL; \
if (zend_hash_find(myht, element, strlen(element) + 1, (void**) 
&z_arg) == SUCCESS) { \
convert_to_long(*z_arg); \
(*intobj)->diff->member = (itype)Z_LVAL_PP(z_arg); \
} else { \
-   (*intobj)->diff->member = (itype)-1; \
+   (*intobj)->diff->member = (itype)def; \
} \
} while (0);
 
@@ -4028,21 +4028,21 @@ static int php_date_interval_initialize_from_hash(zval 
**return_value, php_inter
} \
} while (0);
 
-   PHP_DATE_INTERVAL_READ_PROPERTY("y", y, timelib_sll)
-   PHP_DATE_INTERVAL_READ_PROPERTY("m", m, timelib_sll)
-   PHP_DATE_INTERVAL_READ_PROPERTY("d", d, timelib_sll)
-   PHP_DATE_INTERVAL_READ_PROPERTY("h", h, timelib_sll)
-   PHP_DATE_INTERVAL_READ_PROPERTY("i", i, timelib_sll)
-   PHP_DATE_INTERVAL_READ_PROPERTY("s", s, timelib_sll)
-   PHP_DATE_INTERVAL_READ_PROPERTY("weekday", weekday, int)
-   PHP_DATE_INTERVAL_READ_PROPERTY("weekday_behavior", weekday_behavior, 
int)
-   PHP_DATE_INTERVAL_READ_PROPERTY("first_last_day_of", first_last_day_of, 
int)
-   PHP_DATE_INTERVAL_READ_PROPERTY("invert", invert, int);
+   PHP_DATE_INTERVAL_READ_PROPERTY("y", y, timelib_sll, -1)
+   PHP_DATE_INTERVAL_READ_PROPERTY("m", m, timelib_sll, -1)
+   PHP_DATE_INTERVAL_READ_PROPERTY("d", d, timelib_sll, -1)
+   PHP_DATE_INTERVAL_READ_PROPERTY("h", h, timelib_sll, -1)
+   PHP_DATE_INTERVAL_READ_PROPERTY("i", i, timelib_sll, -1)
+   PHP_DATE_INTERVAL_READ_PROPERTY("s", s, timelib_sll, -1)
+   PHP_DATE_INTERVAL_READ_PROPERTY("weekday", weekday, int, -1)
+   PHP_DATE_INTERVAL_READ_PROPERTY("weekday_behavior", weekday_behavior, 
int, -1)
+   PHP_DATE_INTERVAL_READ_PROPERTY("first_last_day_of", first_last_day_of, 
int, -1)
+   PHP_DATE_INTERVAL_READ_PROPERTY("invert", invert, int, 0);
PHP_DATE_INTERVAL_READ_PROPERTY_I64("days", days);
-   PHP_DATE_INTERVAL_READ_PROPERTY("special_type", special.type, unsigned 
int);
+   PHP_DATE_INTERVAL_READ_PROPERTY("special_type", special.type, unsigned 
int, 0);
PHP_DATE_INTERVAL_READ_PROPERTY_I64("special_amount", special.amount);
-   PHP_DATE_INTERVAL_READ_PROPERTY("have_weekday_relative", 
have_weekday_relative, unsigned int);
-   PHP_DATE_INTERVAL_READ_PROPERTY("have_special_relative", 
have_special_relative, unsigned int);
+   PHP_DATE_INTERVAL_READ_PROPERTY("have_weekday_relative", 
have_weekday_relative, unsigned int, 0);
+   PHP_DATE_INTERVAL_READ_PROPERTY("have_special_relative", 
have_special_relative, unsigned int, 0);
(*intobj)->initialized = 1;
 
return 0;
diff --git a/ext/date/tests/bug52113.phpt b/ext/date/tests/bug52113.phpt
index 226dae5..862e92e 100644
--- a/ext/date/tests/bug52113.phpt
+++ b/ext/date/tests/bug52113.phpt
@@ -189,13 +189,13 @@ object(DateInterval)#8 (15) {
   ["days"]=>
   string(4) "2400"
   ["special_type"]=>
-  int(-1)
+  int(0)
   ["special_amount"]=>
   string(2) "-1"
   ["have_weekday_relative"]=>
-  int(-1)
+  int(0)
   ["have_special_relative"]=>
-  int(-1)
+  int(0)
 }
 object(DatePeriod)#9 (6) {
   ["start"]=>


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