[avahi] arm memory alignment problems
Trent Lloyd
lathiat at bur.st
Fri Sep 23 02:38:44 PDT 2005
On Fri, Sep 23, 2005 at 10:53:50AM +0200, pHilipp Zabel wrote:
> 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;
> }
Well, I have no idea if this is correct, but it seems to work, does it
work on arm?
Trent
>
> > lathiat showed some interest in fixing this?
>
> --
> Philipp
> _______________________________________________
> avahi mailing list
> avahi at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/avahi
--
Trent Lloyd <lathiat at bur.st>
Bur.st Networking Inc.
More information about the avahi
mailing list