* [Qemu-devel] [6737] Sparse fixes: truncation by cast
@ 2009-03-07 15:46 Blue Swirl
2009-03-07 16:51 ` Luca Tettamanti
0 siblings, 1 reply; 3+ messages in thread
From: Blue Swirl @ 2009-03-07 15:46 UTC (permalink / raw)
To: qemu-devel
Revision: 6737
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6737
Author: blueswir1
Date: 2009-03-07 15:46:23 +0000 (Sat, 07 Mar 2009)
Log Message:
-----------
Sparse fixes: truncation by cast
Fix Sparse warnings about constant truncation caused by cast
Modified Paths:
--------------
trunk/bswap.h
trunk/hw/ide.c
trunk/hw/vga.c
trunk/tcg/x86_64/tcg-target.c
Modified: trunk/bswap.h
===================================================================
--- trunk/bswap.h 2009-03-07 15:32:56 UTC (rev 6736)
+++ trunk/bswap.h 2009-03-07 15:46:23 UTC (rev 6737)
@@ -151,7 +151,7 @@
{
uint8_t *p1 = (uint8_t *)p;
- p1[0] = v;
+ p1[0] = v & 0xff;
p1[1] = v >> 8;
}
@@ -159,7 +159,7 @@
{
uint8_t *p1 = (uint8_t *)p;
- p1[0] = v;
+ p1[0] = v & 0xff;
p1[1] = v >> 8;
p1[2] = v >> 16;
p1[3] = v >> 24;
@@ -188,7 +188,7 @@
uint8_t *p1 = (uint8_t *)p;
p1[0] = v >> 8;
- p1[1] = v;
+ p1[1] = v & 0xff;
}
static inline void cpu_to_be32wu(uint32_t *p, uint32_t v)
@@ -198,7 +198,7 @@
p1[0] = v >> 24;
p1[1] = v >> 16;
p1[2] = v >> 8;
- p1[3] = v;
+ p1[3] = v & 0xff;
}
#endif
Modified: trunk/hw/ide.c
===================================================================
--- trunk/hw/ide.c 2009-03-07 15:32:56 UTC (rev 6736)
+++ trunk/hw/ide.c 2009-03-07 15:46:23 UTC (rev 6737)
@@ -1210,7 +1210,7 @@
static inline void cpu_to_ube16(uint8_t *buf, int val)
{
buf[0] = val >> 8;
- buf[1] = val;
+ buf[1] = val & 0xff;
}
static inline void cpu_to_ube32(uint8_t *buf, unsigned int val)
@@ -1218,7 +1218,7 @@
buf[0] = val >> 24;
buf[1] = val >> 16;
buf[2] = val >> 8;
- buf[3] = val;
+ buf[3] = val & 0xff;
}
static inline int ube16_to_cpu(const uint8_t *buf)
Modified: trunk/hw/vga.c
===================================================================
--- trunk/hw/vga.c 2009-03-07 15:32:56 UTC (rev 6736)
+++ trunk/hw/vga.c 2009-03-07 15:46:23 UTC (rev 6737)
@@ -38,33 +38,33 @@
/* force some bits to zero */
const uint8_t sr_mask[8] = {
- (uint8_t)~0xfc,
- (uint8_t)~0xc2,
- (uint8_t)~0xf0,
- (uint8_t)~0xc0,
- (uint8_t)~0xf1,
- (uint8_t)~0xff,
- (uint8_t)~0xff,
- (uint8_t)~0x00,
+ 0x03,
+ 0x3d,
+ 0x0f,
+ 0x3f,
+ 0x0e,
+ 0x00,
+ 0x00,
+ 0xff,
};
const uint8_t gr_mask[16] = {
- (uint8_t)~0xf0, /* 0x00 */
- (uint8_t)~0xf0, /* 0x01 */
- (uint8_t)~0xf0, /* 0x02 */
- (uint8_t)~0xe0, /* 0x03 */
- (uint8_t)~0xfc, /* 0x04 */
- (uint8_t)~0x84, /* 0x05 */
- (uint8_t)~0xf0, /* 0x06 */
- (uint8_t)~0xf0, /* 0x07 */
- (uint8_t)~0x00, /* 0x08 */
- (uint8_t)~0xff, /* 0x09 */
- (uint8_t)~0xff, /* 0x0a */
- (uint8_t)~0xff, /* 0x0b */
- (uint8_t)~0xff, /* 0x0c */
- (uint8_t)~0xff, /* 0x0d */
- (uint8_t)~0xff, /* 0x0e */
- (uint8_t)~0xff, /* 0x0f */
+ 0x0f, /* 0x00 */
+ 0x0f, /* 0x01 */
+ 0x0f, /* 0x02 */
+ 0x1f, /* 0x03 */
+ 0x03, /* 0x04 */
+ 0x7b, /* 0x05 */
+ 0x0f, /* 0x06 */
+ 0x0f, /* 0x07 */
+ 0xff, /* 0x08 */
+ 0x00, /* 0x09 */
+ 0x00, /* 0x0a */
+ 0x00, /* 0x0b */
+ 0x00, /* 0x0c */
+ 0x00, /* 0x0d */
+ 0x00, /* 0x0e */
+ 0x00, /* 0x0f */
};
#define cbswap_32(__x) \
Modified: trunk/tcg/x86_64/tcg-target.c
===================================================================
--- trunk/tcg/x86_64/tcg-target.c 2009-03-07 15:32:56 UTC (rev 6736)
+++ trunk/tcg/x86_64/tcg-target.c 2009-03-07 15:46:23 UTC (rev 6737)
@@ -243,7 +243,7 @@
}
if (opc & P_EXT)
tcg_out8(s, 0x0f);
- tcg_out8(s, opc);
+ tcg_out8(s, opc & 0xff);
}
static inline void tcg_out_modrm(TCGContext *s, int opc, int r, int rm)
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [Qemu-devel] [6737] Sparse fixes: truncation by cast
2009-03-07 15:46 [Qemu-devel] [6737] Sparse fixes: truncation by cast Blue Swirl
@ 2009-03-07 16:51 ` Luca Tettamanti
2009-03-08 7:26 ` Blue Swirl
0 siblings, 1 reply; 3+ messages in thread
From: Luca Tettamanti @ 2009-03-07 16:51 UTC (permalink / raw)
To: qemu-devel
On Sat, Mar 7, 2009 at 4:46 PM, Blue Swirl <blauwirbel@gmail.com> wrote:
> Revision: 6737
> http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6737
> Author: blueswir1
> Date: 2009-03-07 15:46:23 +0000 (Sat, 07 Mar 2009)
> Log Message:
> -----------
> Sparse fixes: truncation by cast
>
> Fix Sparse warnings about constant truncation caused by cast
>
> Modified: trunk/bswap.h
> ===================================================================
> --- trunk/bswap.h 2009-03-07 15:32:56 UTC (rev 6736)
> +++ trunk/bswap.h 2009-03-07 15:46:23 UTC (rev 6737)
> @@ -151,7 +151,7 @@
> {
> uint8_t *p1 = (uint8_t *)p;
>
> - p1[0] = v;
> + p1[0] = v & 0xff;
> p1[1] = v >> 8;
Hum, by the same principle the last line should be:
p1[1] = (v >> 8) & 0xff;
no?
Luca
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [Qemu-devel] [6737] Sparse fixes: truncation by cast
2009-03-07 16:51 ` Luca Tettamanti
@ 2009-03-08 7:26 ` Blue Swirl
0 siblings, 0 replies; 3+ messages in thread
From: Blue Swirl @ 2009-03-08 7:26 UTC (permalink / raw)
To: qemu-devel
On 3/7/09, Luca Tettamanti <kronos.it@gmail.com> wrote:
> On Sat, Mar 7, 2009 at 4:46 PM, Blue Swirl <blauwirbel@gmail.com> wrote:
> > Revision: 6737
> > http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6737
> > Author: blueswir1
> > Date: 2009-03-07 15:46:23 +0000 (Sat, 07 Mar 2009)
> > Log Message:
> > -----------
> > Sparse fixes: truncation by cast
> >
> > Fix Sparse warnings about constant truncation caused by cast
> >
>
> > Modified: trunk/bswap.h
> > ===================================================================
> > --- trunk/bswap.h 2009-03-07 15:32:56 UTC (rev 6736)
> > +++ trunk/bswap.h 2009-03-07 15:46:23 UTC (rev 6737)
> > @@ -151,7 +151,7 @@
> > {
> > uint8_t *p1 = (uint8_t *)p;
> >
> > - p1[0] = v;
> > + p1[0] = v & 0xff;
> > p1[1] = v >> 8;
>
>
> Hum, by the same principle the last line should be:
> p1[1] = (v >> 8) & 0xff;
> no?
Maybe and there would be other similar places, but there is no warning
from Sparse except for this. Instead of "fix" I should have used
something like "suppress" because the code wasn't broken, it's just
that now Sparse is much more silent and real warnings are more visible
from the noise.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-03-08 7:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-07 15:46 [Qemu-devel] [6737] Sparse fixes: truncation by cast Blue Swirl
2009-03-07 16:51 ` Luca Tettamanti
2009-03-08 7:26 ` Blue Swirl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).