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

unaligned access exception #27

Closed
szemzoa opened this issue Nov 12, 2018 · 2 comments
Closed

unaligned access exception #27

szemzoa opened this issue Nov 12, 2018 · 2 comments
Labels
bug Something isn't working

Comments

@szemzoa
Copy link

szemzoa commented Nov 12, 2018

Hi,

First, thanks for your work!

I try to use the client on a cortex-m0+ SoC, and it works great with QOS0.
With QOS1 it throws an unaligned exception, in function

ssize_t mqtt_pack_pubxxx_request(uint8_t *buf, size_t bufsz,
enum MQTTControlPacketType control_type,
uint16_t packet_id)

when packed_id is casted at (uint16_t) buf = (uint16_t) MQTT_PAL_HTONS(packet_id);

It tries to write to address buf + 67 an uint16 packed_id variable, what is an unaligned exception on some arch.
So my proposal is to change ALL uint16_t casts to uint8_t buf to use memcpy, or use some kind of put_unaligned macros.

Regards,
Andras

@LiamBindle
Copy link
Owner

LiamBindle commented Nov 16, 2018

Hi Andras,

Sorry for the delayed response. Glad to hear that QoS 0 is working okay. It's always good to get feedback from different platforms!

Oh yeah, I see what you mean. That was a bit of an oversight.

I like your solution though, that seems like a good way to solve it to me. Another option that pops into my head is keeping track of the byte index and setting the byte array with |= rather than = with the desired value bit-shifted by the byte index mod platform integer size.

Either solution seems good to me though. I have a really busy month, so I probably won't have time to implement this until Christmas. If you or anyone else would like to implement it though, I'd be more than happy to merge a pull request 😄

Thanks for raising this!

Liam

@LiamBindle LiamBindle mentioned this issue Nov 16, 2018
LiamBindle referenced this issue in jepaan/MQTT-C Feb 25, 2019
@LiamBindle LiamBindle added the bug Something isn't working label Mar 20, 2019
@LiamBindle
Copy link
Owner

Sorry that closing this issue took so long. Again, thanks to @jepaan for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants