summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorDarrenJiang13 <yjjiang1996@163.com>2022-03-14 14:22:57 +0800
committerGitHub <noreply@github.com>2022-03-14 08:22:57 +0200
commit38ed6c600791f266cea1ba66f53674c605b7babb (patch)
tree1a3fd5084d073c39e8dab766f88ae358677b539e /src/util.c
parentdc7a9d3a3130e734e30076b3b0be70aa7f752272 (diff)
downloadredis-38ed6c600791f266cea1ba66f53674c605b7babb.tar.gz
improve string2ll() to avoid extra conversion for long integer string. (#10408)
For an integer string like "123456789012345678901" which could cause overflow-failure in string2ll() conversion, we could compare its length at the beginning to avoid extra work. * move LONG_STR_SIZE to be in declared in util.h, next to MAX_LONG_DOUBLE_CHARS
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/util.c b/src/util.c
index 75086db42..45591d9f2 100644
--- a/src/util.c
+++ b/src/util.c
@@ -405,8 +405,8 @@ int string2ll(const char *s, size_t slen, long long *value) {
int negative = 0;
unsigned long long v;
- /* A zero length string is not a valid number. */
- if (plen == slen)
+ /* A string of zero length or excessive length is not a valid number. */
+ if (plen == slen || slen >= LONG_STR_SIZE)
return 0;
/* Special case: first and only digit is 0. */