Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

double may cause crash on some phone #16

Open
kueiwoodwolf opened this issue Sep 16, 2014 · 0 comments
Open

double may cause crash on some phone #16

kueiwoodwolf opened this issue Sep 16, 2014 · 0 comments

Comments

@kueiwoodwolf
Copy link

When parse message with a double field, it may cause crash, because incorrect data alignment will send signal sigbus in these machines.So modify lua_pb.c to use follow functions to parse float and double:
static float unpack_float(const uint8_t* buffer)
{

ifdef IS_LITTLE_ENDIAN

float fvalue;
memcpy(&fvalue, buffer, sizeof(float));
return fvalue;

else

uint32_t uvalue;
memcpy(&uvalue, buffer, sizeof(uint32_t));
uvalue = le32toh(uvalue);
return *(*float)&uvalue;

endif

}

static double unpack_double(const uint8_t* buffer)
{

ifdef IS_LITTLE_ENDIAN

double dvalue;
memcpy(&dvalue, buffer, sizeof(double));
return dvalue;

else

uint64_t uvalue;
memcpy(&uvalue, buffer, sizeof(uint64_t));
uvalue = le64toh(uvalue);
return *(*double)&uvalue;

endif

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant