简体   繁体   中英

EXC_BAD_ACCESS in protocol buffer code

I have this scenario:

a) A static library created for iOS and uses protocol buffer classes generated from a protobuf message file. This static library is used in an Application (A)

b)The protobuff messages has bunch of setters and allocated_setters, all c++ code

c) An Application (C), which has a dependency on the project which creates the static library.

What is happening:

When the static library is included with Application (A) and the App is ran, I get an EXC_BAD_ACCESS in one of the basic setter of the protocol buffer class.

    inline void ABCD::set_companyname32chars(const char* value) {
  set_has_companyname32chars();
  if (companyname32chars_ == &::google::protobuf::internal::kEmptyString) {
    companyname32chars_ = new ::std::string;
  }
  companyname32chars_->assign(value);
}

The last line

companyname32chars_->assign(value) 

generates the EXC_BAD_ACCESS. The way I'm using this setter is like this:

ABCD* abcd = new ABCD();
abcd->set_companyname32chars("Andes");

The kicker is, the same code runs fine on Application C on the same phone.

The static library is created with the following slices, armv7, armv7s and arm64.

The iPhone I'm trying this on is iPhone 5 and iOS 8.2(beta)

EXC_BAD_ACCESS is something to do with memory, however,

a) Why does the same code works with a similar application when it is included as a project dependency rather than a static library. b) Is there a way to debug and fins out what is going on? I tried enabling Zombies, but of no avail.

It would seem that ::google::protobuf::internal::kEmptyString is a variable that exists both in your static library and in your application, with different values. So if your companyname32chars equals the address of one of them but not the other, this isn't recognised. This will always happen if the variable is set within the static library code, but is checked through inlining in your application code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM