]> granicus.if.org Git - php/commitdiff
Avoid magic number. NUM_BUF_SIZE may be in header. Suggestions are appreciated
authorYasuo Ohgaki <yohgaki@php.net>
Thu, 3 Sep 2015 22:17:44 +0000 (07:17 +0900)
committerJakub Zelenka <bukka@php.net>
Sun, 26 Jun 2016 12:26:43 +0000 (13:26 +0100)
ext/standard/var.c

index 59404b8bc2953ae42a65ed043caf95c2d2362e69..7b0b5daa2b091dd105655d1f0351805a4a33eefd 100644 (file)
 #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);