git-hulk commented on code in PR #1867:
URL: https://github.com/apache/kvrocks/pull/1867#discussion_r1397094635


##########
src/types/json.h:
##########
@@ -179,6 +179,33 @@ struct JsonValue {
     return result_count;
   }
 
+  StatusOr<std::vector<std::optional<uint64_t>>> ArrInsert(std::string_view 
path, const int64_t &index,
+                                                           const 
std::vector<jsoncons::json> &insert_values) {
+    std::vector<std::optional<uint64_t>> result_count;
+
+    try {
+      jsoncons::jsonpath::json_replace(
+          value, path, [&insert_values, &result_count, index](const 
std::string & /*path*/, jsoncons::json &val) {
+            if (val.is_array()) {
+              auto len = static_cast<int64_t>(val.size());
+              if (index >= len /*index > 0*/ || len + index < 0 /*index < 0*/) 
{

Review Comment:
   `/*when index > 0*/` it should be >= length instead > 0? since index > 0 is 
good if it doesn't exceed the upper bound of the array.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to