Xtonlsab bug

Ondrej Zajicek santiago at crfreenet.org
Thu Apr 29 23:15:22 CEST 2010


On Thu, Apr 29, 2010 at 11:03:32PM +0200, Joakim Tjernlund wrote:
> 
> Ondrej, this looks buggy:
> 
> +static inline void htonlsab(void *h, void *n, u16 len) { memcpy(n, h, len); };
> +static inline void ntohlsab(void *n, void *h, u16 len) { memcpy(h, n, len); };
> 
> memcpy is not defined to handle overlapping memory. Best to add:
> if (n != h)
>   memcpy(...)

Yes, but all usages of htonlsab()/ntohlsab() are non-overlapping.
(overlapping/on place usage was replaced with htonlsab1()/ntohlsab1()).

> Might as well do that for these too:
> +static inline void htonlsah(struct ospf_lsa_header *h, struct ospf_lsa_header *n) { *n = *h; };
> +static inline void ntohlsah(struct ospf_lsa_header *n, struct ospf_lsa_header *h) { *h = *n; };

*n = *h should be OK even if n == h, AFAIK.

-- 
Elen sila lumenn' omentielvo

Ondrej 'SanTiago' Zajicek (email: santiago at crfreenet.org)
OpenPGP encrypted e-mails preferred (KeyID 0x11DEADC3, wwwkeys.pgp.net)
"To err is human -- to blame it on a computer is even more so."
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
URL: <http://trubka.network.cz/pipermail/bird-users/attachments/20100429/69ee6882/attachment-0001.asc>


More information about the Bird-users mailing list