diff options
author | Oran Agra <oran@redislabs.com> | 2022-03-28 18:35:56 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-28 18:35:56 +0300 |
commit | 14b198868fd8f8c7cbd319bec369fbc3fb24aff6 (patch) | |
tree | 697849f07d2a07b45a36ab036cdc3ed897294296 /src/util.h | |
parent | 3f28d7d712329261d0c56df77eef37c88d610cf3 (diff) | |
download | redis-14b198868fd8f8c7cbd319bec369fbc3fb24aff6.tar.gz |
introduce MAX_D2STRING_CHARS instead of 128 const (#10487)
There are a few places that use a hard coded const of 128 to allocate a buffer for d2string.
Replace these with a clear macro.
Note that In theory, converting double into string could take as much as nearly 400 chars,
but since d2string uses `%g` and not `%f`, it won't pass some 40 chars.
unrelated:
restore some changes to auto generated commands.c that got accidentally reverted in #10293
Diffstat (limited to 'src/util.h')
-rw-r--r-- | src/util.h | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/util.h b/src/util.h index c81db5d16..d2780e00e 100644 --- a/src/util.h +++ b/src/util.h @@ -34,10 +34,19 @@ #include "sds.h" /* The maximum number of characters needed to represent a long double - * as a string (long double has a huge range). + * as a string (long double has a huge range of some 4952 chars, see LDBL_MAX). * This should be the size of the buffer given to ld2string */ #define MAX_LONG_DOUBLE_CHARS 5*1024 +/* The maximum number of characters needed to represent a double + * as a string (double has a huge range of some 328 chars, see DBL_MAX). + * This should be the size of the buffer for sprintf with %f */ +#define MAX_DOUBLE_CHARS 400 + +/* The maximum number of characters needed to for d2string call. + * Since it uses %g and not %f, some 40 chars should be enough. */ +#define MAX_D2STRING_CHARS 128 + /* Bytes needed for long -> str + '\0' */ #define LONG_STR_SIZE 21 |