ios - sqlite3_step 在 iOS 12 中导致 EXC_BAD_INSTRUCTION 崩溃
问题描述
我继承了一些导致以下崩溃的代码,当我在应用程序中多次执行完全相同的操作时,大约 20 次调用该方法:
Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
这是在线上发生的int resultCode = sqlite3_step(compiledStatement)
。
我找不到任何其他有同样错误的帖子。谁能帮我弄清楚为什么会发生这种崩溃,以及为什么它不会一直发生?这似乎只在 iOS 12 上崩溃,我无法在 iOS 14.5 上的设备上重新创建崩溃
- (void) execSql:(NSString *) theSql
sqlArgs:(NSArray *) theArgs {
sqlite3_stmt *compiledStatment = [self _execRawSql:theSql
sqlArgs:theArgs];
int resultCode = sqlite3_step(compiledStatment);
if (resultCode == SQLITE_DONE) {
int finalizeResultCode = sqlite3_finalize(compiledStatment);
if (finalizeResultCode != SQLITE_OK) {
NSMutableString *errorReason = [NSMutableString string];
[errorReason appendFormat:@"result code: \"%d\".\n",finalizeResultCode];
[errorReason appendFormat:@"sqlite3_errmsg : \"%s\".\n",sqlite3_errmsg(myDatabase)];
NSException* exception = [NSException
exceptionWithName:@"SQLITE sqlite3_finalize EXCEPTION"
reason:errorReason
userInfo:nil];
@throw exception;
}
return;
}
NSMutableString *errorReason = [NSMutableString string];
[errorReason appendFormat:@"result code: \"%d\".\n",resultCode];
[errorReason appendFormat:@"sqlite3_errmsg : \"%s\".\n",sqlite3_errmsg(myDatabase)];
NSException* exception = [NSException
exceptionWithName:@"SQLITE sqlite3_step EXCEPTION"
reason:errorReason
userInfo:nil];
@throw exception;
}
如果它是相关的,这是execRawSql
在 sqlite3_step 之前调用的前面的方法:
- (sqlite3_stmt *) _execRawSql:(NSString *) theSql
sqlArgs:(NSArray *) theArgs {
sqlite3_stmt *compiledStatement;
int resultCode = sqlite3_prepare_v2(myDatabase,
[theSql UTF8String],-1,
&compiledStatement,
NULL);
if (resultCode == SQLITE_OK) {
if (theArgs!=NULL) {
for (int i = 0; i < [theArgs count]; i++ ) {
[self _bindObject:theArgs[i]
toColumn:i+1
inStatement:compiledStatement];
}
}
}
else {
NSMutableString *errorReason = [NSMutableString string];
[errorReason appendFormat:@"result code: \"%d\".\n",resultCode];
[errorReason appendFormat:@"sqlite3_errmsg : \"%s\".\n",sqlite3_errmsg(myDatabase)];
NSException* exception = [NSException
exceptionWithName:@"SQLITE sqlite3_prepare_v2 EXCEPTION"
reason:errorReason
userInfo:nil];
@throw exception;
}
return compiledStatement;
}
编辑:在 iOS 14 中发生崩溃,在上面的 execRawSql 方法中抛出异常sqlite3_errmsg : "no such function: COUNT".
解决方案
推荐阅读
- java - 比较密码
- python - 列表理解如何在此代码块中工作?
- vba - VBA 用户表单现在显示在 excel 2016 的快速访问工具栏中
- c++ - 使用 C++ 中的任何嵌套循环显示某个数字模式
- azure - 抛出异常:Microsoft.Extensions.DependencyInjection 中的“System.InvalidOperationException”
- android - 应用程序Android Studio中的语言没有改变
- javascript - Javascript 日期解析在 Chrome 中返回奇怪的结果
- biztalk - 生成的架构在构建期间发出警告
- python - 为什么全局变量 __metaclass__ 不起作用?
- wordpress - 修复 NGINX 中的“Access-Control-Allow-Origin”标头包含多个值错误