我正在尝试访问一个函数来检查条件,但是尽管起初我可以访问它,但经过几次迭代后,我得到了分割错误。我已经包含了一些WriteLogs来查看函数的返回值是什么。
这是我能够访问该功能的四次之一:
[Fri Jan 10 12:40:25:889]: [INFO][RouteInfoManager::UpdateRouteStatus] Driving Mode 2 passengers 0
[Fri Jan 10 12:40:25:889]: [INFO][RouteInfoManager::UpdateRouteStatus] IsAsva 1
[Fri Jan 10 12:40:26:060]: [INFO][DatasetParam::Int] DatasetParam_TypeException, setting speaker_gain
[Fri Jan 10 12:40:26:063]: [INFO][DatasetParam::Int] DatasetParam_TypeException, setting speaker_gain
[Fri Jan 10 12:40:26:175]: [INFO][DatasetParam::Str] DatasetParam_TypeException, setting cpu_version
而这个,分割错误错误:
[Fri Jan 10 12:40:26:901]: [INFO][RouteInfoManager::UpdateRouteStatus] Driving Mode 2 passengers 0
[Thread 0xaa3ebb40 (LWP 27594) exited]
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xa0f49b40 (LWP 27661)]
0x086d0273 in AlstomMP14::RouteInfoManager::UpdateRouteStatus (this=0x90889e8) at ../src/route/RouteInfoManager.cpp:283
283 WriteLog("[RouteInfoManager::UpdateRouteStatus] IsAsva %d", audioInfoProvider->IsAsvaAuthorisedInTrainCA());
这些是写入日志:
WriteLog("[RouteInfoManager::UpdateRouteStatus] Driving Mode %d passengers %d", trainDataProvider->GetDrivingMode(), trainDataProvider->GetDrivingMode() != DRIVING_MODE_AUTOMATIC
|| trainDataProvider->IsTrainWithoutPassengers());
WriteLog("[RouteInfoManager::UpdateRouteStatus] IsAsva %d", audioInfoProvider->IsAsvaAuthorisedInTrainCA());
这些功能涉及:
bool AudioManager::IsAsvaAuthorisedInTrainCA() {
/// 1) Return true if train CA is without passengers and driving mode is automatic.
return (!IsTrainCAWithoutPassengers() && trainDataProvider->GetDrivingMode() == DRIVING_MODE_AUTOMATIC);
}
bool AudioManager::IsTrainCAWithoutPassengers() {
/// 1) Return true if driving mode is not automatic and train is without passengers.
return (trainDataProvider->GetDrivingMode() != DRIVING_MODE_AUTOMATIC
|| trainDataProvider->IsTrainWithoutPassengers());
}
如您所见,WriteLogs 显示了 IsTrainCAWithoutPassengers(( 函数的返回,这是 IsAsvaAuthorisedInTrainCA(( 函数的条件之一。
我不明白为什么,每次(2 和 0(都有相同的值,有时我可以访问 IsAsvaAuthorisedInTrainCA((,有时我得到分段错误。
WriteLog("[RouteInfoManager::UpdateRouteStatus] IsAsva %d", audioInfoProvider->IsAsvaAuthorisedInTrainCA());
假设WriteLog
的工作方式类似于printf
(或转发到printf
(,您的格式说明符与参数不匹配。
%d
是为了int
,而不是bool
。
程序具有未定义的行为。
坚持一个石膏来int
.