Add debug out-of-bound checks to descriptor array accessors.

PiperOrigin-RevId: 551634574
pull/13401/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent 813fcad2ee
commit 56693aa588
  1. 6
      src/google/protobuf/descriptor.h

@ -2435,7 +2435,11 @@ class PROTOBUF_EXPORT DescriptorPool {
// Arrays take an index parameter, obviously.
#define PROTOBUF_DEFINE_ARRAY_ACCESSOR(CLASS, FIELD, TYPE) \
inline TYPE CLASS::FIELD(int index) const { return FIELD##s_ + index; }
inline TYPE CLASS::FIELD(int index) const { \
ABSL_DCHECK_LE(0, index); \
ABSL_DCHECK_LT(index, FIELD##_count()); \
return FIELD##s_ + index; \
}
#define PROTOBUF_DEFINE_OPTIONS_ACCESSOR(CLASS, TYPE) \
inline const TYPE& CLASS::options() const { return *options_; }

Loading…
Cancel
Save