[avahi] arm memory alignment problems

Lennart Poettering lennart at poettering.de
Tue Oct 4 17:34:49 PDT 2005


On Fri, 23.09.05 16:36, pHilipp Zabel (philipp.zabel at gmail.com) wrote:

> On 9/23/05, Lennart Poettering <lennart at poettering.de> wrote:
> > Unless I mixed up LE with BE, this should do it:
> >
> > d[0] = (uint8_t) (v >> 24);
> > d[1] = (uint8_t) (v >> 16);
> > d[2] = (uint8_t) (v >> 8);
> > d[3] = (uint8_t) v;
> 
> Hmm. What about this patch? Now the short packet error messages are gone, too.

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?

>  
> -    *ret_v = ntohl(*((uint32_t*) (AVAHI_DNS_PACKET_DATA(p) + p->rindex)));
> +    d = (uint8_t*) (AVAHI_DNS_PACKET_DATA(p) + p->rindex);
> +    tmp_v = (d[0] << 24) | (d[1] << 16) | (d[2] << 8) | d[3];
> +    d = (uint8_t*) ret_v;
> +    d[0] = ((uint8_t*)(&tmp_v))[0];
> +    d[1] = ((uint8_t*)(&tmp_v))[1];
> +    d[2] = ((uint8_t*)(&tmp_v))[2];
> +    d[3] = ((uint8_t*)(&tmp_v))[3];
>      p->rindex += sizeof(uint32_t);

Same here.

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

Lennart

-- 
Lennart Poettering; lennart [at] poettering [dot] de
ICQ# 11060553; GPG 0x1A015CC4; http://0pointer.de/lennart/


More information about the avahi mailing list