hw/net/dp8393x: Avoid unintentional sign extensions on addresses
commit581f7b127dfe9ed10ce3216e440cc5be1582911b
authorPeter Maydell <peter.maydell@linaro.org>
Mon, 9 Jan 2017 18:43:57 +0000 (9 18:43 +0000)
committerJason Wang <jasowang@redhat.com>
Fri, 20 Jan 2017 02:36:38 +0000 (20 10:36 +0800)
tree778b6fcc6d21a2f46fbfa1ccdbc5bd73a30081f9
parent6ac38ed42b3468e37f9ce681b65c796a3be4e387
hw/net/dp8393x: Avoid unintentional sign extensions on addresses

The dp8393x has several 32-bit values which are formed by concatenating
two 16 bit device register values. Attempting to do these inline
with ((s->reg[HI] << 16) | s->reg[LO]) can result in an unintended
sign extension because "x << 16" is of type 'int' even though s->reg
is unsigned, and so if the expression is used in a context where
it is cast to uint64_t the value is incorrectly sign-extended.
Fix this by using accessor functions with a uint32_t return type;
this also makes the code a bit easier to read.

This should fix Coverity issues 1307765130776613077671307768.

(To avoid having a ctda read function only used in a DPRINTF,
we move the DPRINTF down slightly so it can use the ttda function.)

Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Tested-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Hervé Poussineau <hpoussin@reactos.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Jason Wang <jasowang@redhat.com>
hw/net/dp8393x.c