Copilot commented on code in PR #50322:
URL: https://github.com/apache/arrow/pull/50322#discussion_r3507369895
##########
cpp/src/arrow/util/key_value_metadata.cc:
##########
@@ -100,6 +100,11 @@ 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("Index out of bounds. Expected 0 to ",
+ std::to_string(keys_.size() - 1), ", but got ",
+ std::to_string(index));
+ }
Review Comment:
`keys_.size() - 1` underflows when the metadata is empty, producing a bogus
upper bound in the IndexError message (e.g. Delete(0) on empty metadata would
report a huge expected index). Prefer reporting the valid range as `[0, size)`
and avoid subtracting 1 from an unsigned size.
##########
cpp/src/arrow/util/key_value_metadata.cc:
##########
@@ -100,6 +100,11 @@ 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("Index out of bounds. Expected 0 to ",
+ std::to_string(keys_.size() - 1), ", but got ",
+ std::to_string(index));
+ }
Review Comment:
The new out-of-bounds behavior in `KeyValueMetadata::Delete(int64_t)` isn't
covered by the existing `KeyValueMetadataTest.Delete` test (which only
exercises in-range deletions). Add a regression test that `Delete(-1)` and
`Delete(size)` return `IndexError` instead of crashing.
--
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]