iOS 10中的sqlite3_prepare_v2 exc_bad_access [英] sqlite3_prepare_v2 exc_bad_access in iOS 10

查看:249
本文介绍了iOS 10中的sqlite3_prepare_v2 exc_bad_access的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS项目中使用sqlite作为数据库。在iOS 9中,所有东西都运行得很好。现在我更新了新的Xcode。但是应用程序在'sqlite3_prepare_v2'上多次崩溃。

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

此外,我还没有关闭数据库加班。并且只打开一次。
我已经在下面的代码中添加了DB打开b'acs在调试中我得到了DB关闭。但仍然崩溃。

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.

崩溃

任何人都可以帮助我吗?

Can anyone help me ?

提前致谢

推荐答案

我认为问题在第2592行。

I think issue is in line 2592.

将密钥传递给sqlite3_key时不要将密钥视为字符串( ...)
不确定如何生成密钥,但如果第一个字节设置为'\0',则strlen返回0
(如果你使用一些基于NSData随机字节的自动生成的帮助器,这可能经常发生)

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定义:

sqlite3_key definition:

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

它期望nKey字节,其中\0是也允许

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

请尝试:

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

这篇关于iOS 10中的sqlite3_prepare_v2 exc_bad_access的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆