From 456390eea98018d5594b935443130a9f7a850d1a Mon Sep 17 00:00:00 2001 From: Jesse Lee Date: Sun, 31 May 2020 19:27:48 -0400 Subject: [PATCH] Fix Codex --- mindspore/ccsrc/dataset/util/btree.h | 8 ++++---- mindspore/ccsrc/dataset/util/btree_impl.tpp | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/mindspore/ccsrc/dataset/util/btree.h b/mindspore/ccsrc/dataset/util/btree.h index 72e3d1635..df7cb8516 100644 --- a/mindspore/ccsrc/dataset/util/btree.h +++ b/mindspore/ccsrc/dataset/util/btree.h @@ -252,8 +252,8 @@ class BPlusTree { ~InnerNode() = default; - slot_type slot_dir_[traits::kInnerSlots]; - key_type keys_[traits::kInnerSlots]; + slot_type slot_dir_[traits::kInnerSlots] = {0}; + key_type keys_[traits::kInnerSlots] = {0}; BaseNode *data_[traits::kInnerSlots + 1] = {nullptr}; uint64_t num_keys_[traits::kInnerSlots + 1] = {0}; slot_type slotuse_; @@ -282,8 +282,8 @@ class BPlusTree { ~LeafNode() = default; - slot_type slot_dir_[traits::kLeafSlots]; - key_type keys_[traits::kLeafSlots]; + slot_type slot_dir_[traits::kLeafSlots] = {0}; + key_type keys_[traits::kLeafSlots] = {0}; std::unique_ptr data_[traits::kLeafSlots]; slot_type slotuse_; }; diff --git a/mindspore/ccsrc/dataset/util/btree_impl.tpp b/mindspore/ccsrc/dataset/util/btree_impl.tpp index 1b324cee5..63117a009 100644 --- a/mindspore/ccsrc/dataset/util/btree_impl.tpp +++ b/mindspore/ccsrc/dataset/util/btree_impl.tpp @@ -42,6 +42,9 @@ typename BPlusTree::IndexRc BPlusTree::InnerNode:: // Swap the key std::swap(keys_[j], keys_[i]); // Swap the pointers. + if ((j + 1) >= traits::kInnerSlots + 1 || (i + 1) >= traits::kInnerSlots + 1) { + return IndexRc::kUnexpectedError; + } std::swap(data_[j + 1], data_[i + 1]); // one key in order. inverse[j] = j; @@ -131,6 +134,9 @@ typename BPlusTree::IndexRc BPlusTree::LeafNode::S slot_type j = inverse[i]; slot_type k = inverse[j]; // Swap the key + if (j >= traits::kLeafSlots || i >= traits::kLeafSlots) { + return IndexRc::kUnexpectedError; + } std::swap(keys_[j], keys_[i]); // Swap the shared pointers std::swap(data_[j], data_[i]); -- GitLab