ios下一个4字节对齐引起崩溃的问题
2014-06-07 14:02
761 查看
staticvoid TEACore(unsignedint in[2], unsignedint out[2], unsignedint key[4], long rounds)
{
unsigned int y = in[0], z = in[1];
unsigned int limit = 0, sum = 0;
if(rounds > 0)// encrypt
{
limit = DELTA * rounds;
while(sum != limit)
{
y += ((z<<4)^(z>>5)) + (z^sum) + key[sum&3];
sum += DELTA;
z += ((y<<4)^(y>>5)) + (y^sum) + key[(sum>>11)&3];
}
}
else// decrypt
{
sum = DELTA * (-rounds);
while(sum)
{
z -= ((y<<4)^(y>>5)) + (y^sum) + key[(sum>>11)&3];
sum -= DELTA;
y -= ((z<<4)^(z>>5)) + (z^sum) + key[sum&3];
}
}
//arm 内存4字节对齐
//out[0] = y; out[1] = z;
memcpy((void*)&out[0], (void*)&y, sizeof(unsigned int));
memcpy((void*)&out[1], (void*)&z, sizeof(unsigned int));
}
在进行强制数据类型转换的时候,ios平台竟然要求内存字节对齐。而debug环境又不要求。如果两次强制类型转换用oc的代码隔开,release执行又是正确的,所以再次怀疑是xocde在编译的时候,编译器优化导致的。
{
unsigned int y = in[0], z = in[1];
unsigned int limit = 0, sum = 0;
if(rounds > 0)// encrypt
{
limit = DELTA * rounds;
while(sum != limit)
{
y += ((z<<4)^(z>>5)) + (z^sum) + key[sum&3];
sum += DELTA;
z += ((y<<4)^(y>>5)) + (y^sum) + key[(sum>>11)&3];
}
}
else// decrypt
{
sum = DELTA * (-rounds);
while(sum)
{
z -= ((y<<4)^(y>>5)) + (y^sum) + key[(sum>>11)&3];
sum -= DELTA;
y -= ((z<<4)^(z>>5)) + (z^sum) + key[sum&3];
}
}
//arm 内存4字节对齐
//out[0] = y; out[1] = z;
memcpy((void*)&out[0], (void*)&y, sizeof(unsigned int));
memcpy((void*)&out[1], (void*)&z, sizeof(unsigned int));
}
在进行强制数据类型转换的时候,ios平台竟然要求内存字节对齐。而debug环境又不要求。如果两次强制类型转换用oc的代码隔开,release执行又是正确的,所以再次怀疑是xocde在编译的时候,编译器优化导致的。
相关文章推荐
- ARM程序由于字节对齐引起的问题深入分析
- ios 11以上系统,tableview上啦刷新,indexPath.row,自动加5,引起数组越界的问题导致崩溃
- CORTEX-M3的字节对齐问题引起的Fault
- iOS UITableView 引起的崩溃问题
- PPM图像详解和P3图像引起iOS 9崩溃闪退问题解决方案
- 由字节对齐产生的一个应用崩溃的问题
- ARM程序由于字节对齐引起的问题深入分析
- ARM程序由于字节对齐引起的问题深入分析
- ios平台上一个由字节对齐问题导致的crash
- ARM程序由于字节对齐引起的问题深入分析[转]
- ARM平台 结构体字节对齐引起的一个问题
- 结构体字节对齐问题
- 关于struct结构中字节对齐问题
- C struct 中字节对齐问题
- C语言中的字节对齐问题
- 遭遇字节对齐的问题。
- struct的字节对齐问题(通过pragma pack(n)改变字节对齐的例子)
- 字节对齐的问题浅谈
- 结构体字节对齐问题
- struct 中字节对齐问题