简体   繁体   中英

sqlite3_prepare_v2 exc_bad_access in iOS 10

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

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...

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