diff --git a/deps/oblib/src/lib/udt/ob_array_type.cpp b/deps/oblib/src/lib/udt/ob_array_type.cpp index a35243fa5..e40187e03 100644 --- a/deps/oblib/src/lib/udt/ob_array_type.cpp +++ b/deps/oblib/src/lib/udt/ob_array_type.cpp @@ -609,12 +609,14 @@ int ObArrayBinary::get_data_binary(char *res_buf, int64_t buf_len) ret = OB_ERR_UNEXPECTED; OB_LOG(WARN, "buf len isn't enough", K(ret), K(buf_len)); } else if (data_container_ == NULL) { - uint32_t last_idx = length_ > 0 ? length_ - 1 : 0; - MEMCPY(res_buf + pos, reinterpret_cast(null_bitmaps_), sizeof(uint8_t) * length_); - pos += sizeof(uint8_t) * length_; - MEMCPY(res_buf + pos, reinterpret_cast(offsets_), sizeof(uint32_t) * length_); - pos += sizeof(uint32_t) * length_; - MEMCPY(res_buf + pos, data_, offsets_[last_idx]); + if (length_ > 0) { + uint32_t last_idx = length_ - 1; + MEMCPY(res_buf + pos, reinterpret_cast(null_bitmaps_), sizeof(uint8_t) * length_); + pos += sizeof(uint8_t) * length_; + MEMCPY(res_buf + pos, reinterpret_cast(offsets_), sizeof(uint32_t) * length_); + pos += sizeof(uint32_t) * length_; + MEMCPY(res_buf + pos, data_, offsets_[last_idx]); + } } else { MEMCPY(res_buf + pos, reinterpret_cast(data_container_->null_bitmaps_.get_data()), sizeof(uint8_t) * data_container_->null_bitmaps_.size()); pos += sizeof(uint8_t) * data_container_->null_bitmaps_.size(); diff --git a/deps/oblib/src/lib/udt/ob_array_type.h b/deps/oblib/src/lib/udt/ob_array_type.h index c1e213de0..a6dc5cecd 100644 --- a/deps/oblib/src/lib/udt/ob_array_type.h +++ b/deps/oblib/src/lib/udt/ob_array_type.h @@ -936,8 +936,10 @@ public : { int32_t len = 0; if (this->data_container_ == NULL) { - uint32_t last_idx = this->length_ > 0 ? this->length_ - 1 : 0; - len = this->length_ * sizeof(uint8_t) + this->length_ * sizeof(uint32_t) + this->offsets_[last_idx]; + if (this->length_ > 0) { + uint32_t last_idx = this->length_ - 1; + len = this->length_ * sizeof(uint8_t) + this->length_ * sizeof(uint32_t) + this->offsets_[last_idx]; + } } else { len = sizeof(uint8_t) * data_container_->null_bitmaps_.size() + sizeof(uint32_t) * data_container_->offsets_.size()