Status: New
Owner: liuj...@google.com
Labels: Type-Defect Priority-Medium

New issue 574 by sizefi...@gmail.com: generated header function ::mutable_<string item> attempts to initialize by dereferencing an uninitialized default
http://code.google.com/p/protobuf/issues/detail?id=574

What steps will reproduce the problem?
1. Create a global class instance whose constructor calls GPB's ParseFromArray on GPB object
2. ParseFromArray will attempt to initialize values to defaults
3. Default has not yet been assigned, e.g. _default_<string item>_ is null

What is the expected output? What do you see instead?
<string item>_ value should be defaulted, instead an access violation error occurs (from new ::std::string(*null)) where _default is unassigned.

What version of the product are you using? On what operating system?
2.5.0 on Windows 7 64-bit (32-bit build of GPB), VS2012 SP1

Please provide any additional information below.

The timing of global and static object construction will ultimately affect whether or not this violation happens. I was able to avert disaster by checking for null on _default_version_ however it forced me to not assign the default. This probably may not be easily replicated unless static GPB initializers happenstance execute after the global object is created.

// this is the generated function in the C++ header:
inline ::std::string* mytype::mutable_myfield() {
  set_has_myfield();
  if (version_ == _default_myfield_) {
    version_ = new ::std::string(*_default_myfield_);
  }
  return myfield_;
}

// this is the generated function in the C++ implementation which
// is supposed to initialize the defaults, but happens after the above
// is called.
void protobuf_AddDesc_mytype_2eproto();



--
You received this message because this project is configured to send all issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

--
You received this message because you are subscribed to the Google Groups "Protocol 
Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to