com php-src: Avoid magic number. NUM_BUF_SIZE may be in header. Suggestions are appreciated: ext/stand ard/var.c
| From: | Jakub Zelenka | Date: | Sun, 26 Jun 2016 12:26:43 +0000 |
| Subject: | com php-src: Avoid magic number. NUM_BUF_SIZE may be in header. Suggestions are appreciated: ext/stand ard/var.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-92668@lists.php.net to get a copy of this message | ||
Commit: 3043be37160961faf6985c242684892ee745b713
Author: Yasuo Ohgaki <yohgaki@php.net> Fri, 4 Sep 2015 07:17:44 +0900
Committer: Jakub Zelenka <bukka@php.net> Sun, 26 Jun 2016 13:26:43 +0100
Parents: b509b24e353c4ec84be839a61dec1b49ce8e02b7
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=3043be37160961faf6985c242684892ee745b713
Log:
Avoid magic number. NUM_BUF_SIZE may be in header. Suggestions are appreciated
Changed paths:
M ext/standard/var.c
Diff:
diff --git a/ext/standard/var.c b/ext/standard/var.c
index 59404b8..7b0b5da 100644
--- a/ext/standard/var.c
+++ b/ext/standard/var.c
@@ -31,9 +31,20 @@
#include "zend_smart_str.h"
#include "basic_functions.h"
#include "php_incomplete_class.h"
+/* }}} */
#define COMMON (is_ref ? "&" : "")
-/* }}} */
+
+/* Copied from main/spprintf.c and use the same buffer size
+ *
+ * NUM_BUF_SIZE is the size of the buffer used for arithmetic conversions
+ *
+ * XXX: this is a magic number; do not decrease it
+ * Emax = 1023
+ * NDIG = 320
+ * NUM_BUF_SIZE >= strlen("-") + Emax + strlrn(".") + NDIG +
strlen("E+1023") + 1;
+ */
+#define NUM_BUF_SIZE 2048
static void php_array_element_dump(zval *zv, zend_ulong index, zend_string *key, int level) /* {{{
*/
{
@@ -436,7 +447,7 @@ static void php_object_element_export(zval *zv, zend_ulong index, zend_string *k
PHPAPI void php_var_export_ex(zval *struc, int level, smart_str *buf) /* {{{ */
{
HashTable *myht;
- char tmp_str[2048]; /* Use the same magic number of spprintf.c NUM_BUF_SIZE */
+ char tmp_str[NUM_BUF_SIZE];
zend_string *ztmp, *ztmp2;
zend_ulong index;
zend_string *key;
@@ -847,7 +858,7 @@ again:
return;
case IS_DOUBLE: {
- char tmp_str[2048]; /* Use the same magic number of spprintf.c NUM_BUF_SIZE */
+ char tmp_str[NUM_BUF_SIZE];
smart_str_appendl(buf, "d:", 2);
php_gcvt(Z_DVAL_P(struc), (int)PG(serialize_precision), '.', 'E', tmp_str);
smart_str_appends(buf, tmp_str);