display: avoid multi-statement macro
PATCH 1/1 display: avoid multi-statement macro
For blizzard, pl110 and tc6393xb this is harmless, but for pxa2xx Coverity noticed that it is used inside an "if" statement. Fix it because it's the file with the highest number of defects in the whole QEMU tree!
--- hw/display/blizzard_template.h | 10 +++++----- hw/display/pl110_template.h | 6 +++--- hw/display/pxa2xx_template.h | 8 ++++---- hw/display/tc6393xb_template.h | 8 ++++---- 4 files changed, 22 insertions(+), 23 deletions(-)
hw/display/blizzard_template.h +5 -5
@@ -21,21 +21,21 @@#define SKIP_PIXEL (to) to += deststep#if DEPTH ==8 # define PIXEL_TYPE uint8_t -# define COPY_PIXEL (to, from) *to = from; SKIP_PIXEL(to) +# define COPY_PIXEL (to, from) *to = from, SKIP_PIXEL(to)# define COPY_PIXEL1 (to, from) *to ++ = from#elif DEPTH ==15 ||DEPTH ==16 # define PIXEL_TYPE uint16_t -# define COPY_PIXEL (to, from) *to = from; SKIP_PIXEL(to) +# define COPY_PIXEL (to, from) *to = from, SKIP_PIXEL(to)# define COPY_PIXEL1 (to, from) *to ++ = from#elif DEPTH ==24 # define PIXEL_TYPE uint8_t# define COPY_PIXEL (to, from) \ - to[0] = from; to[1] = (from) >> 8; to[2] = (from) >> 16; SKIP_PIXEL(to) + to[0] = from, to[1] = (from) >> 8, to[2] = (from) >> 16, SKIP_PIXEL(to)# define COPY_PIXEL1 (to, from) \ - *to ++ = from; *to ++ = (from) >> 8; *to ++ = (from) >> 16 + *to ++ = from, *to ++ = (from) >> 8, *to ++ = (from) >> 16#elif DEPTH ==32 # define PIXEL_TYPE uint32_t -# define COPY_PIXEL (to, from) *to = from; SKIP_PIXEL(to) +# define COPY_PIXEL (to, from) *to = from, SKIP_PIXEL(to)# define COPY_PIXEL1 (to, from) *to ++ = from#else # error unknown bit depth
hw/display/pl110_template.h +3 -3
@@ -14,12 +14,12 @@#if BITS ==8 #define COPY_PIXEL (to, from) *(to++) = from#elif BITS ==15 ||BITS ==16 -#define COPY_PIXEL (to, from) *(uint16_t *)to = from; to += 2; +#define COPY_PIXEL (to, from) *(uint16_t *)to = from, to += 2#elif BITS ==24 #define COPY_PIXEL (to, from) \ - *(to++) = from; *(to++) = (from) >> 8; *(to++) = (from) >> 16 + *(to++) = from, *(to++) = (from) >> 8, *(to++) = (from) >> 16#elif BITS ==32 -#define COPY_PIXEL (to, from) *(uint32_t *)to = from; to += 4; +#define COPY_PIXEL (to, from) *(uint32_t *)to = from, to += 4#else #error unknown bit depth#endif
hw/display/pxa2xx_template.h +4 -4
@@ -11,14 +11,14 @@# define SKIP_PIXEL (to) to += deststep#if BITS ==8 -# define COPY_PIXEL (to, from) *to = from; SKIP_PIXEL(to) +# define COPY_PIXEL (to, from) *to = from, SKIP_PIXEL(to)#elif BITS ==15 ||BITS ==16 -# define COPY_PIXEL (to, from) *(uint16_t *) to = from; SKIP_PIXEL(to) +# define COPY_PIXEL (to, from) *(uint16_t *) to = from, SKIP_PIXEL(to)#elif BITS ==24 # define COPY_PIXEL (to, from) \ - *(uint16_t *) to = from; *(to + 2) = (from) >> 16; SKIP_PIXEL(to) + *(uint16_t *) to = from, *(to + 2) = (from) >> 16, SKIP_PIXEL(to)#elif BITS ==32 -# define COPY_PIXEL (to, from) *(uint32_t *) to = from; SKIP_PIXEL(to) +# define COPY_PIXEL (to, from) *(uint32_t *) to = from, SKIP_PIXEL(to)#else # error unknown bit depth#endif
hw/display/tc6393xb_template.h +4 -4
@@ -22,14 +22,14 @@*/ #if BITS ==8 -# define SET_PIXEL (addr, color) *(uint8_t*)addr = color; +# define SET_PIXEL (addr, color) *(uint8_t*)addr = color#elif BITS ==15 ||BITS ==16 -# define SET_PIXEL (addr, color) *(uint16_t*)addr = color; +# define SET_PIXEL (addr, color) *(uint16_t*)addr = color#elif BITS ==24 # define SET_PIXEL (addr, color) \ - addr[0] = color; addr[1] = (color) >> 8; addr[2] = (color) >> 16; + addr[0] = color, addr[1] = (color) >> 8, addr[2] = (color) >> 16#elif BITS ==32 -# define SET_PIXEL (addr, color) *(uint32_t*)addr = color; +# define SET_PIXEL (addr, color) *(uint32_t*)addr = color#else # error unknown bit depth#endif
Signature · 1 line
1.8.4.2
Quoted 18 lines · Paolo Bonzini
For blizzard, pl110 and tc6393xb this is harmless, but for pxa2xx Coverity noticed that it is used inside an "if" statement. Fix it because it's the file with the highest number of defects in the whole QEMU tree!
Signed-off-by Paolo Bonzini <[email protected]>--- hw/display/blizzard_template.h | 10 +++++----- hw/display/pl110_template.h | 6 +++--- hw/display/pxa2xx_template.h | 8 ++++---- hw/display/tc6393xb_template.h | 8 ++++---- 4 files changed, 22 insertions(+), 23 deletions(-)hw/display/blizzard_template.h +0
-0
hw/display/blizzard_template.h line 24
Quoted 5 lines
hw/display/blizzard_template.h +1
-1@@ -21,21 +21,21 @@#define SKIP_PIXEL (to) to += deststep#if DEPTH ==8 # define PIXEL_TYPE uint8_t -# define COPY_PIXEL (to, from) *to = from; SKIP_PIXEL(to) +# define COPY_PIXEL (to, from) *to = from, SKIP_PIXEL(to)
Why not use the standard do { ... } while(0) idiom ?
thanks
-- PMM
Il 24/01/2014 18:52, Peter Maydell ha scritto:
Quoted 14 lines · Paolo Bonzini
Quoted 13 lines
For blizzard, pl110 and tc6393xb this is harmless, but for pxa2xx Coverity noticed that it is used inside an "if" statement. Fix it because it's the file with the highest number of defects in the whole QEMU tree!
Signed-off-by Paolo Bonzini <[email protected]>--- hw/display/blizzard_template.h | 10 +++++----- hw/display/pl110_template.h | 6 +++--- hw/display/pxa2xx_template.h | 8 ++++---- hw/display/tc6393xb_template.h | 8 ++++---- 4 files changed, 22 insertions(+), 23 deletions(-)
Quoted 12 lines
hw/display/blizzard_template.h line 24
Quoted 10 lines
hw/display/blizzard_template.h +1
-1@@ -21,21 +21,21 @@#define SKIP_PIXEL (to) to += deststep#if DEPTH ==8 # define PIXEL_TYPE uint8_t -# define COPY_PIXEL (to, from) *to = from; SKIP_PIXEL(to) +# define COPY_PIXEL (to, from) *to = from, SKIP_PIXEL(to)Why not use the standard do { ... } while(0) idiom ?
I figured that this would make the patch easier to review, but I can use "do {...} while(0)" too (either directly or as a follow up).
Paolo
Quoted 15 lines · Paolo Bonzini
Il 24/01/2014 18:52, Peter Maydell ha scritto:
Quoted 12 lines · Paolo Bonzini
hw/display/blizzard_template.h line 24
Quoted 8 lines
hw/display/blizzard_template.h +1
-1@@ -21,21 +21,21 @@#define SKIP_PIXEL (to) to += deststep#if DEPTH ==8 # define PIXEL_TYPE uint8_t -# define COPY_PIXEL (to, from) *to = from; SKIP_PIXEL(to) +# define COPY_PIXEL (to, from) *to = from, SKIP_PIXEL(to)Why not use the standard do { ... } while(0) idiom ?
Quoted 2 lines
I figured that this would make the patch easier to review, but I can use "do {...} while(0)" too (either directly or as a follow up).
I'd prefer do ... while(0), just as a single patch fix. I'm not convinced the average QEMU programmer could tell you whether comma is a sequence point without going and looking it up :-)
thanks
-- PMM