Your msg is completely empty. There aren't any entries in the repeated field
- FieldSize() should be returning 0. Your loop needs to terminate when i <
size, not i <= size - accessing the 1st element of an empty repeated field
is going to return an invalid pointer.

FYI bounds checking is done in debug mode, so you'd get more informative
assertion failures rather than segfaults.

On Mon, May 3, 2010 at 10:12 PM, Ryan <droopyk...@gmail.com> wrote:

> Hello all,
>
> I am getting a segmentation fault when trying to use the
> MutableRepeatedMessage() class with a nested repeated method. My
> simple C++ code is as follows:
>
> /* Decleration in bufferDB.h*/
>        private:
>                        std::string serialData;
>                        Message* msg;
>                        Message* nestedMsg;
>                        const Descriptor* msgDescript;
>                        const Reflection* msgReflect;
>                        const FieldDescriptor* msgField;
>
>                        const Descriptor* nestedDescript;
>                        const Reflection* nestedReflect;
>                        const FieldDescriptor* nestedField;
>
> /*Definition in bufferDB.cpp */
> msg = new db::Database;
>        msgDescript = msg->GetDescriptor();
>        msgReflect = msg->GetReflection();
>        msgField = msgDescript->field(2);

       //msgReflect->MutableRepeatedMessage(msg, msgField, 0)-
> >DiscardUnknownFields();

        if (msgField->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE)
>         {
>                printf("Field is a MESSAGE\n");
>              if (msgField->is_repeated())
>              {
>                        printf("Field is Repeated\n");
>                int size = msgReflect->FieldSize(*msg, msgField);
>                        printf("Field size is %d\n",size);
>                for (int i = 0; i <= size; i++)
>                {
>                        printf("I went inside this loop");
>                        nestedReflect =
> msgReflect->MutableRepeatedMessage(msg, msgField,
> i)->GetReflection();
>
>                }
>              }
>              else
>              {
>                        printf("Field is NOT repeated");
>                const Message& sub_message = msgReflect->GetMessage(*msg,
> msgField);
>              }
>          }
>
> The segmentation fault occurs when I call GetReflection(). Am I doing
> something wrong with the use of the mutable message pointer being
> returned from MutableRepeatedMessage?
>
> Any help anyone could give me would be great. Thanks!
>
> -Ryan
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To post to this group, send email to proto...@googlegroups.com.
> To unsubscribe from this group, send email to
> protobuf+unsubscr...@googlegroups.com<protobuf%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/protobuf?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

Reply via email to