sqlite3_prepare_v2 exc_bad_access in iOS 10

我怕爱的太早我们不能终老 提交于 2019-12-01 02:46:44

问题


I have use sqlite in my iOS project for database. In iOS 9 all things are working perfectly. Now i have update new Xcode. But app is crashes many times at 'sqlite3_prepare_v2'.

Also, i am not closing database overtime. And open it only once. I have added DB open in below code b'acs in debug i got DB close. But still got crash.

crash

Can anyone help me ?

Thanks in advance


回答1:


I think issue is in line 2592.

Do not treat key as string when passing it to sqlite3_key(...) Not sure how you generate key but if first byte is set '\0' then strlen return 0 (which may happen pretty often if you use some autogenerated helper based on NSData random bytes)

sqlite3_key definition:

SQLITE_API int SQLITE_STDCALL sqlite3_key(sqlite3 *db, const void *pKey, int nKey)

It expects nKey bytes where "\0" is allowed too

Instead try:

 NSData *passBytes = [g_sqlite_key dataUsingEncoding:NSUTF8StringEncoding];
 int status = sqlite3_key(contactDB, passBytes.bytes, passBytes.length);
 if (status != SQLITE_OK) {
      // handle error and return
 }
 // continue...


来源:https://stackoverflow.com/questions/39916124/sqlite3-prepare-v2-exc-bad-access-in-ios-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!