C语言关于指针释放问题
问题是这样的,我对pYaw指针申请完内存空间后,在函数的末尾释放该内存空间,结果出现了意想不到的debugerror:DAMAGE:afterNormalblock(#1...
问题是这样的,我对pYaw指针申请完内存空间后,在函数的末尾释放该内存空间,结果出现了意想不到的debug error :DAMAGE: after Normal block (#1459) at 0x00387230.
实在想不到哪错了,把这段代码单独提出来测试也是通过的。代码如下:
void AngleSinglStepCount( List *phead, unsigned int step)
{
unsigned int num_of_Yaw = g_NumOfNode;
double * pYaw = NULL;
Node * temp = * phead;
pYaw = ( double* )calloc( num_of_Yaw, sizeof(double) );
for( unsigned int i = 0; i < num_of_Yaw && temp->pNext != NULL; i++ )
{
pYaw[ i ] = temp->item.Rotation.Yaw;
temp = temp->pNext;
}
for( unsigned int j = 0; j < 10; j++ )
{
for( i = 1; i <= num_of_Yaw; i++ )
{
if( pYaw[ i ] - pYaw[ i - 1 ] < -200 )
pYaw[ i ] = 360 + pYaw[ i ];
if( pYaw[ i ] - pYaw[ i - 1 ] > 200 )
pYaw[ i ] = pYaw[ i ] - 360;
}
}
g_StepDirction = (double * )calloc( step, sizeof(double));
for( i = 0 ; i < step; i++ )
{
g_StepDirction[ i ] = pYaw[ g_StepArry[ i + 1 ] + 34 ] - pYaw[ g_StepArry[ 1 ] + 34 ];
printf("\n Step Direction %d: %f ", i, g_StepDirction[ i ] );
}
printf("\n");
free( pYaw );
} 展开
实在想不到哪错了,把这段代码单独提出来测试也是通过的。代码如下:
void AngleSinglStepCount( List *phead, unsigned int step)
{
unsigned int num_of_Yaw = g_NumOfNode;
double * pYaw = NULL;
Node * temp = * phead;
pYaw = ( double* )calloc( num_of_Yaw, sizeof(double) );
for( unsigned int i = 0; i < num_of_Yaw && temp->pNext != NULL; i++ )
{
pYaw[ i ] = temp->item.Rotation.Yaw;
temp = temp->pNext;
}
for( unsigned int j = 0; j < 10; j++ )
{
for( i = 1; i <= num_of_Yaw; i++ )
{
if( pYaw[ i ] - pYaw[ i - 1 ] < -200 )
pYaw[ i ] = 360 + pYaw[ i ];
if( pYaw[ i ] - pYaw[ i - 1 ] > 200 )
pYaw[ i ] = pYaw[ i ] - 360;
}
}
g_StepDirction = (double * )calloc( step, sizeof(double));
for( i = 0 ; i < step; i++ )
{
g_StepDirction[ i ] = pYaw[ g_StepArry[ i + 1 ] + 34 ] - pYaw[ g_StepArry[ 1 ] + 34 ];
printf("\n Step Direction %d: %f ", i, g_StepDirction[ i ] );
}
printf("\n");
free( pYaw );
} 展开
2个回答
展开全部
for( i = 1; i <= num_of_Yaw; i++ )
{
if( pYaw[ i ] - pYaw[ i - 1 ] < -200 )
pYaw[ i ] = 360 + pYaw[ i ];
if( pYaw[ i ] - pYaw[ i - 1 ] > 200 )
pYaw[ i ] = pYaw[ i ] - 360;
}
---------------------------------
当i==num_of_Yaw,对pYaw[i]赋值,你说是不是越界了
{
if( pYaw[ i ] - pYaw[ i - 1 ] < -200 )
pYaw[ i ] = 360 + pYaw[ i ];
if( pYaw[ i ] - pYaw[ i - 1 ] > 200 )
pYaw[ i ] = pYaw[ i ] - 360;
}
---------------------------------
当i==num_of_Yaw,对pYaw[i]赋值,你说是不是越界了
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询