mirror of https://mirror.osredm.com/root/redis.git
config.c post refactory cleanup
This commit is contained in:
parent
18e72c5cc7
commit
6b4366b85b
84
src/config.c
84
src/config.c
|
@ -1802,6 +1802,36 @@ static void numericConfigInit(typeData data) {
|
|||
SET_NUMERIC_TYPE(data.numeric.default_value)
|
||||
}
|
||||
|
||||
static int numericBoundaryCheck(typeData data, long long ll, char **err) {
|
||||
if (data.numeric.numeric_type == NUMERIC_TYPE_ULONG_LONG ||
|
||||
data.numeric.numeric_type == NUMERIC_TYPE_UINT ||
|
||||
data.numeric.numeric_type == NUMERIC_TYPE_SIZE_T) {
|
||||
/* Boundary check for unsigned types */
|
||||
unsigned long long ull = ll;
|
||||
unsigned long long upper_bound = data.numeric.upper_bound;
|
||||
unsigned long long lower_bound = data.numeric.lower_bound;
|
||||
if (ull > upper_bound || ull < lower_bound) {
|
||||
snprintf(loadbuf, LOADBUF_SIZE,
|
||||
"argument must be between %llu and %llu inclusive",
|
||||
lower_bound,
|
||||
upper_bound);
|
||||
*err = loadbuf;
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
/* Boundary check for signed types */
|
||||
if (ll > data.numeric.upper_bound || ll < data.numeric.lower_bound) {
|
||||
snprintf(loadbuf, LOADBUF_SIZE,
|
||||
"argument must be between %lld and %lld inclusive",
|
||||
data.numeric.lower_bound,
|
||||
data.numeric.upper_bound);
|
||||
*err = loadbuf;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int numericConfigLoad(typeData data, sds *argv, int argc, char **err) {
|
||||
long long ll;
|
||||
|
||||
|
@ -1824,33 +1854,8 @@ static int numericConfigLoad(typeData data, sds *argv, int argc, char **err) {
|
|||
}
|
||||
}
|
||||
|
||||
if (data.numeric.numeric_type == NUMERIC_TYPE_ULONG_LONG ||
|
||||
data.numeric.numeric_type == NUMERIC_TYPE_UINT ||
|
||||
data.numeric.numeric_type == NUMERIC_TYPE_SIZE_T) {
|
||||
/* Boundary check for unsigned types */
|
||||
unsigned long long ull = ll;
|
||||
unsigned long long upper_bound = data.numeric.upper_bound;
|
||||
unsigned long long lower_bound = data.numeric.lower_bound;
|
||||
if (ull > upper_bound || ull < lower_bound) {
|
||||
snprintf(loadbuf, LOADBUF_SIZE,
|
||||
"argument must be between %llu and %llu inclusive",
|
||||
lower_bound,
|
||||
upper_bound);
|
||||
*err = loadbuf;
|
||||
if (!numericBoundaryCheck(data, ll, err))
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
/* Boundary check for signed types */
|
||||
if (ll > data.numeric.upper_bound ||
|
||||
ll < data.numeric.lower_bound) {
|
||||
snprintf(loadbuf, LOADBUF_SIZE,
|
||||
"argument must be between %lld and %lld inclusive",
|
||||
data.numeric.lower_bound,
|
||||
data.numeric.upper_bound);
|
||||
*err = loadbuf;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (data.numeric.is_valid_fn && !data.numeric.is_valid_fn(ll, err))
|
||||
return 0;
|
||||
|
@ -1870,33 +1875,8 @@ static int numericConfigSet(typeData data, sds value, char **err) {
|
|||
if (!string2ll(value, sdslen(value),&ll)) return 0;
|
||||
}
|
||||
|
||||
if (data.numeric.numeric_type == NUMERIC_TYPE_ULONG_LONG ||
|
||||
data.numeric.numeric_type == NUMERIC_TYPE_UINT ||
|
||||
data.numeric.numeric_type == NUMERIC_TYPE_SIZE_T) {
|
||||
/* Boundary check for unsigned types */
|
||||
unsigned long long ull = ll;
|
||||
unsigned long long upper_bound = data.numeric.upper_bound;
|
||||
unsigned long long lower_bound = data.numeric.lower_bound;
|
||||
if (ull > upper_bound || ull < lower_bound) {
|
||||
snprintf(loadbuf, LOADBUF_SIZE,
|
||||
"argument must be between %llu and %llu inclusive",
|
||||
lower_bound,
|
||||
upper_bound);
|
||||
*err = loadbuf;
|
||||
if (!numericBoundaryCheck(data, ll, err))
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
/* Boundary check for signed types */
|
||||
if (ll > data.numeric.upper_bound ||
|
||||
ll < data.numeric.lower_bound) {
|
||||
snprintf(loadbuf, LOADBUF_SIZE,
|
||||
"argument must be between %lld and %lld inclusive",
|
||||
data.numeric.lower_bound,
|
||||
data.numeric.upper_bound);
|
||||
*err = loadbuf;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (data.numeric.is_valid_fn && !data.numeric.is_valid_fn(ll, err))
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue