iOS next 4-byte alignment causes a crash problem

Source: Internet
Author: User
Tags rounds

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>> one) &3];

}

}

else//Decrypt

{

sum = DELTA * (-rounds);

while (sum)

{

Z-= ((y<<4) ^ (y>>5) + (y^sum) + key[(sum>>one) &3];

Sum-= DELTA;

Y-= ((z<<4) ^ (z>>5) + (z^sum) + key[sum&3];

}

}

//arm Memory 4- byte alignment

Out[0] = y; OUT[1] = Z;

memcpy (void*) &out[0], (void*) &y, sizeof(unsigned int));

memcpy (void*) &out[1], (void*) &z, sizeof(unsigned int ));

}

The iOS platform requires memory byte alignment when forcing data type conversions. And the debug environment is not required. If the two coercion type conversion is separated by the OC code, release execution is also correct, so again it is suspected that the compiler optimization is the result of XOCDE at compile time.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.