Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
q3356564 committed May 31, 2024
1 parent 5daec01 commit 4f6931a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 31 deletions.
8 changes: 1 addition & 7 deletions src/common/bit_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,7 @@ inline size_t RawPopcount(const uint8_t *p, int64_t count) {

return bits;
}
inline bool Int64OperationOverFlow(int64_t a, int64_t b, int64_t result, uint8_t operation) {
if (operation == 1) {
return __builtin_add_overflow(a, b, &result);
} else {
return __builtin_mul_overflow(a, b, &result);
}
}


template <typename T = void>
inline int ClzllWithEndian(uint64_t x) {
Expand Down
16 changes: 2 additions & 14 deletions src/types/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -576,11 +576,6 @@ struct JsonValue {
result->value.push_back(jsoncons::json::null());
return;
}
if (CheckJsonInt64OverFlow(number.value) || CheckJsonInt64OverFlow(origin)) {
status = {Status::RedisExecErr, "number out of range"};
return;
}

if (number.value.is_double() || origin.is_double()) {
double v = 0;
if (op == NumOpEnum::Incr) {
Expand All @@ -594,12 +589,6 @@ struct JsonValue {
}
origin = v;
} else {
int64_t v = 0;
if (util::Int64OperationOverFlow(origin.as_integer<int64_t>(), number.value.as_integer<int64_t>(), v,
static_cast<uint8_t>(op))) {
status = {Status::RedisExecErr, "number out of range"};
return;
}
if (op == NumOpEnum::Incr) {
origin = origin.as_integer<int64_t>() + number.value.as_integer<int64_t>();
} else if (op == NumOpEnum::Mul) {
Expand All @@ -610,12 +599,11 @@ struct JsonValue {
});
} catch (const jsoncons::jsonpath::jsonpath_error &e) {
return {Status::NotOK, e.what()};
} catch (const jsoncons::json_runtime_error<std::runtime_error> &e) {
return {Status::NotOK, e.what()};
}
return status;
}
static bool CheckJsonInt64OverFlow(const jsoncons::json &check_value) {
return (check_value.is_number() && (!check_value.is_int64() && !check_value.is_double()));
}

JsonValue(const JsonValue &) = default;
JsonValue(JsonValue &&) = default;
Expand Down
10 changes: 0 additions & 10 deletions tests/gocase/unit/type/json/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,18 +509,8 @@ func TestJson(t *testing.T) {
EqualJSON(t, `[1]`, rdb.Do(ctx, "JSON.NUMINCRBY", "a", "$.foo", 1).Val())
EqualJSON(t, `[1]`, rdb.Do(ctx, "JSON.GET", "a", "$.foo").Val())
EqualJSON(t, `[3]`, rdb.Do(ctx, "JSON.NUMINCRBY", "a", "$.foo", 2).Val())
//args overflow
require.Error(t, rdb.Do(ctx, "JSON.NUMINCRBY", "a", "$.foo", "22222222222222222222222222222222222222222222222222222").Err())
require.Error(t, rdb.Do(ctx, "JSON.NUMMULTBY", "a", "$.foo", "22222222222222222222222222222222222222222222222222222").Err())
//origin overflow
require.NoError(t, rdb.Do(ctx, "JSON.SET", "over_flow", "$", `{ "foo":9223372036854775809, "bar": "baz" }`).Err())
require.Error(t, rdb.Do(ctx, "JSON.NUMINCRBY", "over_flow", "$.foo", 2).Err())
require.Error(t, rdb.Do(ctx, "JSON.NUMMULTBY", "over_flow", "$.foo", 2).Err())
//result overflow 9223372036854775806<std::numeric_limits::max()
require.NoError(t, rdb.Do(ctx, "JSON.SET", "over_flow", "$", `{ "foo":9223372036854775806, "bar": "baz" }`).Err())
require.Error(t, rdb.Do(ctx, "JSON.NUMINCRBY", "over_flow", "$.foo", 20).Err())
require.Error(t, rdb.Do(ctx, "JSON.NUMMULTBY", "over_flow", "$.foo", 2).Err())

EqualJSON(t, `[3.5]`, rdb.Do(ctx, "JSON.NUMINCRBY", "a", "$.foo", 0.5).Val())

// wrong type
Expand Down

0 comments on commit 4f6931a

Please sign in to comment.