[avahi] arm memory alignment problems
pHilipp Zabel
philipp.zabel at gmail.com
Fri Sep 23 01:53:50 PDT 2005
Hi Lennart,
On 9/22/05, Lennart Poettering <lennart at poettering.de> wrote:
> The corresponding code looks like this:
>
> <snip>
> uint8_t *avahi_dns_packet_append_uint32(AvahiDnsPacket *p, uint32_t v)
> {
> uint8_t *d;
> assert(p);
>
> if (!(d = avahi_dns_packet_extend(p, sizeof(uint32_t))))
> return NULL;
>
> *((uint32_t*) d) = htonl(v); /** SIGBUS HERE **/
>
> return d;
> }
> </snip>
>
> The pointer d is not necessarily aligned to 32bit multiples. The fix
> is easy: just write all four bytes of the uint32_t value seperately
> and manually to the memory d points to.
Do you mean something like this?
uint8_t *avahi_dns_packet_append_uint32(AvahiDnsPacket *p, uint32_t v) {
uint8_t *d;
uint32_t tmp_v;
assert(p);
if (!(d = avahi_dns_packet_extend(p, sizeof(uint32_t))))
return NULL;
tmp_v = htonl(v);
d[0] = tmp_v & 0xFF000000 >> 24;
d[1] = tmp_v & 0xFF0000 >> 16;
d[2] = tmp_v & 0xFF00 >> 8;
d[3] = tmp_v & 0xFF;
return d;
}
> lathiat showed some interest in fixing this?
--
Philipp
More information about the avahi
mailing list