From 3043be37160961faf6985c242684892ee745b713 Mon Sep 17 00:00:00 2001 From: Yasuo Ohgaki Date: Fri, 4 Sep 2015 07:17:44 +0900 Subject: Avoid magic number. NUM_BUF_SIZE may be in header. Suggestions are appreciated --- ext/standard/var.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'ext/standard/var.c') 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); -- cgit v1.2.1