sqlite3_prepare_v2 exc_bad_access in iOS 10

后端 未结 1 532
萌比男神i
萌比男神i 2021-01-13 01:01

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_

1条回答
  •  执念已碎
    2021-01-13 01:29

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

    0 讨论(0)
提交回复
热议问题