mirror of https://mirror.osredm.com/root/redis.git
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
This commit is contained in:
parent
3f28d7d712
commit
14b198868f
|
@ -588,9 +588,9 @@ NULL
|
||||||
|
|
||||||
/* CLUSTER SETSLOT subcommand argument table */
|
/* CLUSTER SETSLOT subcommand argument table */
|
||||||
struct redisCommandArg CLUSTER_SETSLOT_subcommand_Subargs[] = {
|
struct redisCommandArg CLUSTER_SETSLOT_subcommand_Subargs[] = {
|
||||||
{"node-id",ARG_TYPE_INTEGER,-1,"IMPORTING",NULL,NULL,CMD_ARG_NONE},
|
{"node-id",ARG_TYPE_STRING,-1,"IMPORTING",NULL,NULL,CMD_ARG_NONE},
|
||||||
{"node-id",ARG_TYPE_INTEGER,-1,"MIGRATING",NULL,NULL,CMD_ARG_NONE},
|
{"node-id",ARG_TYPE_STRING,-1,"MIGRATING",NULL,NULL,CMD_ARG_NONE},
|
||||||
{"node-id",ARG_TYPE_INTEGER,-1,"NODE",NULL,NULL,CMD_ARG_NONE},
|
{"node-id",ARG_TYPE_STRING,-1,"NODE",NULL,NULL,CMD_ARG_NONE},
|
||||||
{"stable",ARG_TYPE_PURE_TOKEN,-1,"STABLE",NULL,NULL,CMD_ARG_NONE},
|
{"stable",ARG_TYPE_PURE_TOKEN,-1,"STABLE",NULL,NULL,CMD_ARG_NONE},
|
||||||
{0}
|
{0}
|
||||||
};
|
};
|
||||||
|
@ -672,8 +672,8 @@ struct redisCommand CLUSTER_Subcommands[] = {
|
||||||
{"set-config-epoch","Set the configuration epoch in a new node","O(1)","3.0.0",CMD_DOC_NONE,NULL,NULL,COMMAND_GROUP_CLUSTER,CLUSTER_SET_CONFIG_EPOCH_History,CLUSTER_SET_CONFIG_EPOCH_tips,clusterCommand,3,CMD_NO_ASYNC_LOADING|CMD_ADMIN|CMD_STALE,0,.args=CLUSTER_SET_CONFIG_EPOCH_Args},
|
{"set-config-epoch","Set the configuration epoch in a new node","O(1)","3.0.0",CMD_DOC_NONE,NULL,NULL,COMMAND_GROUP_CLUSTER,CLUSTER_SET_CONFIG_EPOCH_History,CLUSTER_SET_CONFIG_EPOCH_tips,clusterCommand,3,CMD_NO_ASYNC_LOADING|CMD_ADMIN|CMD_STALE,0,.args=CLUSTER_SET_CONFIG_EPOCH_Args},
|
||||||
{"setslot","Bind a hash slot to a specific node","O(1)","3.0.0",CMD_DOC_NONE,NULL,NULL,COMMAND_GROUP_CLUSTER,CLUSTER_SETSLOT_History,CLUSTER_SETSLOT_tips,clusterCommand,-4,CMD_NO_ASYNC_LOADING|CMD_ADMIN|CMD_STALE,0,.args=CLUSTER_SETSLOT_Args},
|
{"setslot","Bind a hash slot to a specific node","O(1)","3.0.0",CMD_DOC_NONE,NULL,NULL,COMMAND_GROUP_CLUSTER,CLUSTER_SETSLOT_History,CLUSTER_SETSLOT_tips,clusterCommand,-4,CMD_NO_ASYNC_LOADING|CMD_ADMIN|CMD_STALE,0,.args=CLUSTER_SETSLOT_Args},
|
||||||
{"shards","Get array of cluster slots to node mappings","O(N) where N is the total number of cluster nodes","7.0.0",CMD_DOC_NONE,NULL,NULL,COMMAND_GROUP_CLUSTER,CLUSTER_SHARDS_History,CLUSTER_SHARDS_tips,clusterCommand,2,CMD_STALE,0},
|
{"shards","Get array of cluster slots to node mappings","O(N) where N is the total number of cluster nodes","7.0.0",CMD_DOC_NONE,NULL,NULL,COMMAND_GROUP_CLUSTER,CLUSTER_SHARDS_History,CLUSTER_SHARDS_tips,clusterCommand,2,CMD_STALE,0},
|
||||||
{"slaves","List replica nodes of the specified master node","O(1)","3.0.0",CMD_DOC_NONE,"`CLUSTER REPLICAS`","5.0.0",COMMAND_GROUP_CLUSTER,CLUSTER_SLAVES_History,CLUSTER_SLAVES_tips,clusterCommand,3,CMD_ADMIN|CMD_STALE,0,.args=CLUSTER_SLAVES_Args},
|
{"slaves","List replica nodes of the specified master node","O(1)","3.0.0",CMD_DOC_DEPRECATED,"`CLUSTER REPLICAS`","5.0.0",COMMAND_GROUP_CLUSTER,CLUSTER_SLAVES_History,CLUSTER_SLAVES_tips,clusterCommand,3,CMD_ADMIN|CMD_STALE,0,.args=CLUSTER_SLAVES_Args},
|
||||||
{"slots","Get array of Cluster slot to node mappings","O(N) where N is the total number of Cluster nodes","3.0.0",CMD_DOC_NONE,NULL,NULL,COMMAND_GROUP_CLUSTER,CLUSTER_SLOTS_History,CLUSTER_SLOTS_tips,clusterCommand,2,CMD_STALE,0},
|
{"slots","Get array of Cluster slot to node mappings","O(N) where N is the total number of Cluster nodes","3.0.0",CMD_DOC_NONE,"`CLUSTER SHARDS`","7.0.0",COMMAND_GROUP_CLUSTER,CLUSTER_SLOTS_History,CLUSTER_SLOTS_tips,clusterCommand,2,CMD_STALE,0},
|
||||||
{0}
|
{0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3461,8 +3461,9 @@ struct redisCommandArg FUNCTION_RESTORE_Args[] = {
|
||||||
|
|
||||||
/* FUNCTION STATS tips */
|
/* FUNCTION STATS tips */
|
||||||
const char *FUNCTION_STATS_tips[] = {
|
const char *FUNCTION_STATS_tips[] = {
|
||||||
|
"nondeterministic_output",
|
||||||
"request_policy:all_shards",
|
"request_policy:all_shards",
|
||||||
"response_policy:one_succeeded",
|
"response_policy:special",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4526,7 +4527,12 @@ struct redisCommandArg LATENCY_GRAPH_Args[] = {
|
||||||
#define LATENCY_HISTOGRAM_History NULL
|
#define LATENCY_HISTOGRAM_History NULL
|
||||||
|
|
||||||
/* LATENCY HISTOGRAM tips */
|
/* LATENCY HISTOGRAM tips */
|
||||||
#define LATENCY_HISTOGRAM_tips NULL
|
const char *LATENCY_HISTOGRAM_tips[] = {
|
||||||
|
"nondeterministic_output",
|
||||||
|
"request_policy:all_nodes",
|
||||||
|
"response_policy:special",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
/* LATENCY HISTOGRAM argument table */
|
/* LATENCY HISTOGRAM argument table */
|
||||||
struct redisCommandArg LATENCY_HISTOGRAM_Args[] = {
|
struct redisCommandArg LATENCY_HISTOGRAM_Args[] = {
|
||||||
|
@ -4540,7 +4546,12 @@ struct redisCommandArg LATENCY_HISTOGRAM_Args[] = {
|
||||||
#define LATENCY_HISTORY_History NULL
|
#define LATENCY_HISTORY_History NULL
|
||||||
|
|
||||||
/* LATENCY HISTORY tips */
|
/* LATENCY HISTORY tips */
|
||||||
#define LATENCY_HISTORY_tips NULL
|
const char *LATENCY_HISTORY_tips[] = {
|
||||||
|
"nondeterministic_output",
|
||||||
|
"request_policy:all_nodes",
|
||||||
|
"response_policy:special",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
/* LATENCY HISTORY argument table */
|
/* LATENCY HISTORY argument table */
|
||||||
struct redisCommandArg LATENCY_HISTORY_Args[] = {
|
struct redisCommandArg LATENCY_HISTORY_Args[] = {
|
||||||
|
@ -4554,7 +4565,12 @@ struct redisCommandArg LATENCY_HISTORY_Args[] = {
|
||||||
#define LATENCY_LATEST_History NULL
|
#define LATENCY_LATEST_History NULL
|
||||||
|
|
||||||
/* LATENCY LATEST tips */
|
/* LATENCY LATEST tips */
|
||||||
#define LATENCY_LATEST_tips NULL
|
const char *LATENCY_LATEST_tips[] = {
|
||||||
|
"nondeterministic_output",
|
||||||
|
"request_policy:all_nodes",
|
||||||
|
"response_policy:special",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
/********** LATENCY RESET ********************/
|
/********** LATENCY RESET ********************/
|
||||||
|
|
||||||
|
@ -4562,7 +4578,11 @@ struct redisCommandArg LATENCY_HISTORY_Args[] = {
|
||||||
#define LATENCY_RESET_History NULL
|
#define LATENCY_RESET_History NULL
|
||||||
|
|
||||||
/* LATENCY RESET tips */
|
/* LATENCY RESET tips */
|
||||||
#define LATENCY_RESET_tips NULL
|
const char *LATENCY_RESET_tips[] = {
|
||||||
|
"request_policy:all_nodes",
|
||||||
|
"response_policy:all_succeeded",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
/* LATENCY RESET argument table */
|
/* LATENCY RESET argument table */
|
||||||
struct redisCommandArg LATENCY_RESET_Args[] = {
|
struct redisCommandArg LATENCY_RESET_Args[] = {
|
||||||
|
@ -4650,6 +4670,8 @@ NULL
|
||||||
/* MEMORY STATS tips */
|
/* MEMORY STATS tips */
|
||||||
const char *MEMORY_STATS_tips[] = {
|
const char *MEMORY_STATS_tips[] = {
|
||||||
"nondeterministic_output",
|
"nondeterministic_output",
|
||||||
|
"request_policy:all_shards",
|
||||||
|
"response_policy:special",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2256,7 +2256,7 @@ RedisModuleString *RM_CreateStringFromLongLong(RedisModuleCtx *ctx, long long ll
|
||||||
* The returned string must be released with RedisModule_FreeString() or by
|
* The returned string must be released with RedisModule_FreeString() or by
|
||||||
* enabling automatic memory management. */
|
* enabling automatic memory management. */
|
||||||
RedisModuleString *RM_CreateStringFromDouble(RedisModuleCtx *ctx, double d) {
|
RedisModuleString *RM_CreateStringFromDouble(RedisModuleCtx *ctx, double d) {
|
||||||
char buf[128];
|
char buf[MAX_D2STRING_CHARS];
|
||||||
size_t len = d2string(buf,sizeof(buf),d);
|
size_t len = d2string(buf,sizeof(buf),d);
|
||||||
return RM_CreateString(ctx,buf,len);
|
return RM_CreateString(ctx,buf,len);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1027,7 +1027,7 @@ unsigned char *zzlDelete(unsigned char *zl, unsigned char *eptr) {
|
||||||
|
|
||||||
unsigned char *zzlInsertAt(unsigned char *zl, unsigned char *eptr, sds ele, double score) {
|
unsigned char *zzlInsertAt(unsigned char *zl, unsigned char *eptr, sds ele, double score) {
|
||||||
unsigned char *sptr;
|
unsigned char *sptr;
|
||||||
char scorebuf[128];
|
char scorebuf[MAX_D2STRING_CHARS];
|
||||||
int scorelen;
|
int scorelen;
|
||||||
|
|
||||||
scorelen = d2string(scorebuf,sizeof(scorebuf),score);
|
scorelen = d2string(scorebuf,sizeof(scorebuf),score);
|
||||||
|
|
11
src/util.h
11
src/util.h
|
@ -34,10 +34,19 @@
|
||||||
#include "sds.h"
|
#include "sds.h"
|
||||||
|
|
||||||
/* The maximum number of characters needed to represent a long double
|
/* 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 */
|
* This should be the size of the buffer given to ld2string */
|
||||||
#define MAX_LONG_DOUBLE_CHARS 5*1024
|
#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' */
|
/* Bytes needed for long -> str + '\0' */
|
||||||
#define LONG_STR_SIZE 21
|
#define LONG_STR_SIZE 21
|
||||||
|
|
||||||
|
|
|
@ -2399,4 +2399,12 @@ start_server {tags {"zset"}} {
|
||||||
r config set zset-max-ziplist-value $original_max_value
|
r config set zset-max-ziplist-value $original_max_value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test {zset score double range} {
|
||||||
|
set dblmax 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00000000000000000
|
||||||
|
r del zz
|
||||||
|
r zadd zz $dblmax dblmax
|
||||||
|
assert_encoding listpack zz
|
||||||
|
r zscore zz dblmax
|
||||||
|
} {1.7976931348623157e+308}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue