段错误问题——20190716
昨天在写代码的时候,碰到了编译成功,但是运行时显示段错误的问题。
添加打印定位到了1006行:
pstpdu_InitialUEMessage->protocolIEs->next->next->value.value.decoded.pdu_UserLocationInformation->choice = 2;
发现此处的pdu_UserLocationInformation是指针,而我没有给它申请内存就直接指向了choice,故发生了段错误,更改如下:
pstpdu_InitialUEMessage->protocolIEs->next->next->value.value.decoded.pdu_UserLocationInformation = ossGetInitializedMemory(pst0SS_world,sizeof(struct OSS_NGAP_UserLocationInformation));
pstTempIeUserLocationInformation = pstpdu_InitialUEMessage->protocolIEs->next->next->value.value.decoded.pdu_UserLocationInformation;
if ( Clfw_NULL == pstTempIeUserLocationInformation )
{
ossPrint(pst0SS_world, "TextEncodeInitialUEMsg-encode UserLocationInformation error\n");
return Clfw_ERROR;
}
pstTempIeUserLocationInformation->choice = OSS_NGAP_userLocationInformationNR_chosen;
更改后没有报错,以后碰到结构体中有指针类型的成员,需要给他申请内存后方可使用。