tony2001                Mon Aug 18 13:09:41 2008 UTC

  Modified files:              (Branch: PHP_5_3)
    /php-src    README.PARAMETER_PARSING_API 
  Log:
  MFH: add note on 64bit compatibility and mention check_parameters.php
  
  
http://cvs.php.net/viewvc.cgi/php-src/README.PARAMETER_PARSING_API?r1=1.7.6.2.2.3&r2=1.7.6.2.2.4&diff_format=u
Index: php-src/README.PARAMETER_PARSING_API
diff -u php-src/README.PARAMETER_PARSING_API:1.7.6.2.2.3 
php-src/README.PARAMETER_PARSING_API:1.7.6.2.2.4
--- php-src/README.PARAMETER_PARSING_API:1.7.6.2.2.3    Tue Nov  6 09:48:24 2007
+++ php-src/README.PARAMETER_PARSING_API        Mon Aug 18 13:09:41 2008
@@ -65,6 +65,32 @@
                to all specifiers except for 'b', 'l', and 'd'). If NULL is 
passed, the
                results pointer is set to NULL as well.
 
+
+Note on 64bit compatibility
+---------------------------
+Please do not forget that int and long are two different things on 64bit 
+OSes (int is 4bit and long is 8bit), so make sure you pass longs to "l" 
+and ints to strings length (i.e. for "s" you need to pass char * and int), 
+not the other way round!
+Remember: "l" is the only case when you need to pass long (and that's why 
+it's "l", not "i" btw).
+
+Both mistakes cause memory corruptions and segfaults on 64bit OSes:
+1)
+  char *str;
+  long str_len; /* XXX THIS IS WRONG!! Use int instead. */
+  zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len)
+
+2)
+  int num; /* XXX THIS IS WRONG!! Use long instead. */
+  zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &num)
+
+If you're in doubt, use check_parameters.php script to the parameters 
+and their types (it can be found in ./scripts/dev/ directory of PHP sources):
+
+# php ./scripts/dev/check_parameters.php /path/to/your/sources/
+
+
 Examples
 --------
 /* Gets a long, a string and its length, and a zval */



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

Reply via email to