summaryrefslogtreecommitdiff
path: root/ext/standard/var.c
diff options
context:
space:
mode:
authorYasuo Ohgaki <yohgaki@php.net>2015-09-04 07:17:44 +0900
committerJakub Zelenka <bukka@php.net>2016-06-26 13:26:43 +0100
commit3043be37160961faf6985c242684892ee745b713 (patch)
tree9a256d356333fdcd864c1f7bbd7d1067a645bce6 /ext/standard/var.c
parentb509b24e353c4ec84be839a61dec1b49ce8e02b7 (diff)
downloadphp-git-3043be37160961faf6985c242684892ee745b713.tar.gz
Avoid magic number. NUM_BUF_SIZE may be in header. Suggestions are appreciated
Diffstat (limited to 'ext/standard/var.c')
-rw-r--r--ext/standard/var.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/ext/standard/var.c b/ext/standard/var.c
index 59404b8bc2..7b0b5daa2b 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);