Repeated Field - Add element method.

149 views
Skip to first unread message

Ashish Kumar

unread,
May 17, 2022, 3:04:08 PM5/17/22
to Protocol Buffers
When we are constructing an object with repeated field member, we generally call
auto memberObj = parentObject->add_member() -- C++

My question is that whether we should always add a defensive check for NULL-Pointer being returned from the Add function. 
I assume it will happen only in the out of memory condition.

Protobuf does not throw an out of memory exception.
So is there a way to check if Add succeded or Failed.


Ashish

Deanna Garcia

unread,
Aug 1, 2022, 4:57:19 PM8/1/22
to Protocol Buffers
There shouldn't be a case where ->add_member() returns a null pointer. It should be safe to not make the null check.
Reply all
Reply to author
Forward
0 new messages