ios10中的sqlite3_prepare_v2 exc_bad_access

时间:2021-02-04 23:00:09

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

我在iOS项目中使用sqlite数据库。在iOS 9中,一切都运行得很好。现在我更新了新的Xcode。但是app会在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.

另外,我不会超时关闭数据库。只打开一次。我在下面的代码b'acs中添加了DB open,在调试中我得到了DB close。但仍有崩溃。

crash

崩溃

Can anyone help me ?

谁能帮帮我吗?

Thanks in advance

谢谢提前

1 个解决方案

#1


0  

I think issue is in line 2592.

问题在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)

在将key传递给sqlite3_key(…)时,不要将key视为string。不知道如何生成键,但是如果第一个字节被设置为'\0',那么strlen返回0(如果您使用一些基于NSData随机字节的自动生成助手,这可能会经常发生)

sqlite3_key definition:

sqlite3_key定义:

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

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

它期望nKey字节也允许使用“\0”

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

#1


0  

I think issue is in line 2592.

问题在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)

在将key传递给sqlite3_key(…)时,不要将key视为string。不知道如何生成键,但是如果第一个字节被设置为'\0',那么strlen返回0(如果您使用一些基于NSData随机字节的自动生成助手,这可能会经常发生)

sqlite3_key definition:

sqlite3_key定义:

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

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

它期望nKey字节也允许使用“\0”

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