Skip to contentSkip to conversation

display: avoid multi-statement macro

PATCH Superseded Paolo Bonzini 2 participants 4 messages Jan 24, 2014

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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
index a8a8899..b899a29 100644
@@ -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
index e738e4a..3ff42e0 100644
@@ -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
index 1cbe36c..806f573 100644
@@ -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
index 154aafd..8fbdd5c 100644
@@ -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
#1 lore raw
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!

---
 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
index a8a8899..b899a29 100644

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

#2 lore raw

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!

---
 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
index a8a8899..b899a29 100644
@@ -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

#3 lore raw
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