Status: New
Labels: Type-Defect Priority-Medium

New issue 426 by repeated_field.h : some ::Mutable(..) methods do check validity of index, others don't. Why?

What steps will reproduce the problem?
1. myMessage.set_repeated_field(0,"some str message");

Note: without first calling myMessage.add

What is the expected output? What do you see instead?
I would expect a fatal log message (as is the case with myMessage.repeated_field(0) if this field does not exist.

What version of the product are you using? On what operating system?
KEIL ARM Cortex M3 cross compiler on Windows 7

Please provide any additional information below.
Why is it that some methods do an index check and others don't?

e.g. repeated_field.h

line 663:
template <typename TypeHandler>
inline typename TypeHandler::Type*
RepeatedPtrFieldBase::Mutable(int index) {
  GOOGLE_DCHECK_LT(index, size());
  return cast<TypeHandler>(elements_[index]);


line 863:
template <typename Element>
inline Element* RepeatedPtrField<Element>::Mutable(int index) {
  return RepeatedPtrFieldBase::Mutable<TypeHandler>(index);

The latter one will produce an undefined situation (pointer to nowhere) when called e.g. by a method like this one created by .proto compiler:

inline void MbSendMessage::set_receivers(int index, const char* value) {

Where as the first version would (rightly) produce a fatal log message.

You received this message because you are subscribed to the Google Groups "Protocol 
Buffers" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Reply via email to