summaryrefslogtreecommitdiff
path: root/ext/json/json_encoder.c
diff options
context:
space:
mode:
authorJakub Zelenka <bukka@php.net>2016-06-26 14:03:01 +0100
committerJakub Zelenka <bukka@php.net>2016-06-26 14:03:01 +0100
commit3f13507dd281adf0518c9162dce5391e9250e93b (patch)
tree70f4addc37de995e1a58e5baec180e0ef266a937 /ext/json/json_encoder.c
parent158b537c99ca5fc7846e7d16d532644be95894a7 (diff)
downloadphp-git-3f13507dd281adf0518c9162dce5391e9250e93b.tar.gz
Use one place to define max length of double
Introduce new constant PHP_DOUBLE_MAX_LENGTH for that purpose
Diffstat (limited to 'ext/json/json_encoder.c')
-rw-r--r--ext/json/json_encoder.c12
1 files changed, 2 insertions, 10 deletions
diff --git a/ext/json/json_encoder.c b/ext/json/json_encoder.c
index 7720393c36..7cf7673235 100644
--- a/ext/json/json_encoder.c
+++ b/ext/json/json_encoder.c
@@ -31,14 +31,6 @@
#include "php_json.h"
#include <zend_exceptions.h>
-/* double limits */
-#include <float.h>
-#if defined(DBL_MANT_DIG) && defined(DBL_MIN_EXP)
-#define PHP_JSON_DOUBLE_MAX_LENGTH (3 + DBL_MANT_DIG - DBL_MIN_EXP)
-#else
-#define PHP_JSON_DOUBLE_MAX_LENGTH 1080
-#endif
-
static const char digits[] = "0123456789abcdef";
static void php_json_escape_string(smart_str *buf, char *s, size_t len, int options);
@@ -103,11 +95,11 @@ static inline int php_json_is_valid_double(double d) /* {{{ */
static inline void php_json_encode_double(smart_str *buf, double d, int options) /* {{{ */
{
size_t len;
- char num[PHP_JSON_DOUBLE_MAX_LENGTH];
+ char num[PHP_DOUBLE_MAX_LENGTH];
php_gcvt(d, (int)PG(serialize_precision), '.', 'e', num);
len = strlen(num);
- if (options & PHP_JSON_PRESERVE_ZERO_FRACTION && strchr(num, '.') == NULL && len < PHP_JSON_DOUBLE_MAX_LENGTH - 2) {
+ if (options & PHP_JSON_PRESERVE_ZERO_FRACTION && strchr(num, '.') == NULL && len < PHP_DOUBLE_MAX_LENGTH - 2) {
num[len++] = '.';
num[len++] = '0';
num[len] = '\0';