[avahi] arm memory alignment problems

pHilipp Zabel philipp.zabel at gmail.com
Wed Oct 5 06:04:15 PDT 2005


On 10/5/05, Lennart Poettering <lennart at poettering.de> wrote:
> The consume functions still don't look right to me.
>
> >  int avahi_dns_packet_consume_uint16(AvahiDnsPacket *p, uint16_t *ret_v) {
>
> [...]
>
> > +    d = (uint8_t*) (AVAHI_DNS_PACKET_DATA(p) + p->rindex);
> > +    tmp_v = (d[0] << 8) | d[1];
>
> First you disassemble the bytes in the packet. This looks right to me.
>
> > +    d = (uint8_t*) ret_v;
> > +    d[0] = ((uint8_t*)(&tmp_v))[0];
> > +    d[1] = ((uint8_t*)(&tmp_v))[1];
>
> And now you copy a 16 bit value to a 16 bit value?
>
> What about just using *ret_v = tmp_v? Or even shorter: dumping tmp_v
> and write directly to ret_v?

I can only do this on arm if ret_v is aligned. If ret_v is guaranteed
to be aligned, this is indeed superfluous.

> Please fix this and do some tests! I will then merge this into
> upstream Avahi.

I'll look into this again and report back.

--
Philipp


More information about the avahi mailing list