[PATCH 2/5] Use correct swap{l,s} (or none at all for CARD8)

Matt Turner mattst88 at gmail.com
Fri Aug 5 07:14:10 PDT 2011


On Fri, Aug 5, 2011 at 10:07 AM, walter harms <wharms at bfs.de> wrote:
> hi matt,
>
> I am not sure if i understand the purpose of swap() really.
>
> do you generaly swap bytes ? then you may like a look at swab() (man 3 swab).
> On the other side when endianes is a problem ntoh() and friends may be more friendly.

I'm not an expert on this code, but what I learned yesterday is that a
lot of it is (only?) used for mixed-endian client/server situations.
For example, remotely displaying an application running on a
big-endian SPARC system on a little-endian amd64 system.

It looks like swab() is for byte-swapping strings of two-byte data, so
it's not really useful, I think.

The point of the patch is to correct problems caused by byte-swapping
the wrong sized data. Attempting to byte-swap a short when the datum
is only 8-bits is going to cause
 - the 8-bits to be extended to 16-bits
 - the two 8-bits swapped
 - the result truncated and the lower 8-bits (what was extended into!) saved

> the macro uses "sizeof((src)) != 2" perhaps you can use int16_t here better ?

Yes, good idea.

Matt


More information about the xorg-devel mailing list