Copilot commented on code in PR #50322:
URL: https://github.com/apache/arrow/pull/50322#discussion_r3510840247


##########
cpp/src/arrow/util/key_value_metadata.cc:
##########
@@ -100,6 +100,14 @@ Result<std::string> KeyValueMetadata::Get(std::string_view 
key) const {
 }
 
 Status KeyValueMetadata::Delete(int64_t index) {
+  if (ARROW_PREDICT_FALSE(index < 0 || std::cmp_greater_equal(index, 
values_.size()))) {
+    return Status::IndexError(
+        "KeyValueMetadata::Delete: index ", std::to_string(index),
+        " is out of bounds for metadata "
+        "of size ",
+        std::to_string(keys_.size()), " (valid range: [0, ",
+        std::to_string((keys_.size() == 0 ? 0UL : keys_.size() - 1)), "])");
+  }

Review Comment:
   The bounds check compares against values_.size() but the error message 
reports keys_.size(), and the reported "valid range" is misleading when the 
metadata is empty (currently renders as [0, 0], which implies index 0 is 
valid). Consider checking against keys_.size() consistently and wording the 
expected bounds without a size-1 upper bound.



-- 
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