qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/1] Avoid compiler error when building block/blkdebug.c with -Wtype-limits
@ 2010-09-10 14:04 Jes.Sorensen
  2010-09-10 14:04 ` [Qemu-devel] [PATCH 1/1] " Jes.Sorensen
  0 siblings, 1 reply; 4+ messages in thread
From: Jes.Sorensen @ 2010-09-10 14:04 UTC (permalink / raw)
  To: qemu-devel; +Cc: blauwirbel

From: Jes Sorensen <Jes.Sorensen@redhat.com>

Hi,

Back to the earlier discussion about building with -Wtype-limits. This
fixes the problem with block/blkdebug.c where it tries to compare an
enum against < 0. I looked at a couple of ways to do this, but I think
this is the least intrusive.

Let me know what you think.

Thanks,
Jes


Jes Sorensen (1):
  Avoid compiler error when building block/blkdebug.c with
    -Wtype-limits

 block/blkdebug.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Qemu-devel] [PATCH 1/1] Avoid compiler error when building block/blkdebug.c with -Wtype-limits
  2010-09-10 14:04 [Qemu-devel] [PATCH 0/1] Avoid compiler error when building block/blkdebug.c with -Wtype-limits Jes.Sorensen
@ 2010-09-10 14:04 ` Jes.Sorensen
  2010-09-10 17:05   ` [Qemu-devel] " Blue Swirl
  0 siblings, 1 reply; 4+ messages in thread
From: Jes.Sorensen @ 2010-09-10 14:04 UTC (permalink / raw)
  To: qemu-devel; +Cc: blauwirbel

From: Jes Sorensen <Jes.Sorensen@redhat.com>

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
---
 block/blkdebug.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/block/blkdebug.c b/block/blkdebug.c
index 2a63df9..17d796d 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -439,7 +439,12 @@ static void blkdebug_debug_event(BlockDriverState *bs, BlkDebugEvent event)
     struct BlkdebugRule *rule;
     BlkdebugVars old_vars = s->vars;
 
-    if (event < 0 || event >= BLKDBG_EVENT_MAX) {
+    /*
+     * enum is not guaranteed to be signed on all archs, so cast to
+     * int before the comparison against zero to avoid compiler
+     * warning when building with -Wtype-limits 
+     */
+    if ((int)event < 0 || event >= BLKDBG_EVENT_MAX) {
         return;
     }
 
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Qemu-devel] Re: [PATCH 1/1] Avoid compiler error when building block/blkdebug.c with -Wtype-limits
  2010-09-10 14:04 ` [Qemu-devel] [PATCH 1/1] " Jes.Sorensen
@ 2010-09-10 17:05   ` Blue Swirl
  2010-09-10 17:15     ` Jes Sorensen
  0 siblings, 1 reply; 4+ messages in thread
From: Blue Swirl @ 2010-09-10 17:05 UTC (permalink / raw)
  To: Jes.Sorensen; +Cc: qemu-devel

On Fri, Sep 10, 2010 at 2:04 PM,  <Jes.Sorensen@redhat.com> wrote:
> From: Jes Sorensen <Jes.Sorensen@redhat.com>
>
> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
> ---
>  block/blkdebug.c |    7 ++++++-
>  1 files changed, 6 insertions(+), 1 deletions(-)
>
> diff --git a/block/blkdebug.c b/block/blkdebug.c
> index 2a63df9..17d796d 100644
> --- a/block/blkdebug.c
> +++ b/block/blkdebug.c
> @@ -439,7 +439,12 @@ static void blkdebug_debug_event(BlockDriverState *bs, BlkDebugEvent event)
>     struct BlkdebugRule *rule;
>     BlkdebugVars old_vars = s->vars;
>
> -    if (event < 0 || event >= BLKDBG_EVENT_MAX) {
> +    /*
> +     * enum is not guaranteed to be signed on all archs, so cast to
> +     * int before the comparison against zero to avoid compiler
> +     * warning when building with -Wtype-limits
> +     */
> +    if ((int)event < 0 || event >= BLKDBG_EVENT_MAX) {

I changed 'if' to 'assert' in my version because the check could only
fail due to an internal error:
http://lists.nongnu.org/archive/html/qemu-devel/2010-09/msg00239.html

There's also Michael's version with a cast to unsigned int. It's a bit
simpler, the generated code is the same:
$ cat check.c
int f(int x)
{
        if (x < 0 || x > 1000)
                return 1;
        return 0;
}

int g(int x)
{
        if ((unsigned)x > 1000)
                return 1;
        return 0;
}

$ gcc -O -S check.c
$ head -20 check.s
        .file   "check.c"
        .text
.globl f
        .type   f, @function
f:
.LFB2:
        cmpl    $1000, %edi
        seta    %al
        movzbl  %al, %eax
        ret
.LFE2:
        .size   f, .-f
.globl g
        .type   g, @function
g:
.LFB3:
        cmpl    $1000, %edi
        seta    %al
        movzbl  %al, %eax
        ret

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Qemu-devel] Re: [PATCH 1/1] Avoid compiler error when building block/blkdebug.c with -Wtype-limits
  2010-09-10 17:05   ` [Qemu-devel] " Blue Swirl
@ 2010-09-10 17:15     ` Jes Sorensen
  0 siblings, 0 replies; 4+ messages in thread
From: Jes Sorensen @ 2010-09-10 17:15 UTC (permalink / raw)
  To: Blue Swirl; +Cc: qemu-devel

On 09/10/10 19:05, Blue Swirl wrote:
> On Fri, Sep 10, 2010 at 2:04 PM,  <Jes.Sorensen@redhat.com> wrote:
>> From: Jes Sorensen <Jes.Sorensen@redhat.com>
>>
>> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
>> ---
>>  block/blkdebug.c |    7 ++++++-
>>  1 files changed, 6 insertions(+), 1 deletions(-)
>>
>> diff --git a/block/blkdebug.c b/block/blkdebug.c
>> index 2a63df9..17d796d 100644
>> --- a/block/blkdebug.c
>> +++ b/block/blkdebug.c
>> @@ -439,7 +439,12 @@ static void blkdebug_debug_event(BlockDriverState *bs, BlkDebugEvent event)
>>     struct BlkdebugRule *rule;
>>     BlkdebugVars old_vars = s->vars;
>>
>> -    if (event < 0 || event >= BLKDBG_EVENT_MAX) {
>> +    /*
>> +     * enum is not guaranteed to be signed on all archs, so cast to
>> +     * int before the comparison against zero to avoid compiler
>> +     * warning when building with -Wtype-limits
>> +     */
>> +    if ((int)event < 0 || event >= BLKDBG_EVENT_MAX) {
> 
> I changed 'if' to 'assert' in my version because the check could only
> fail due to an internal error:
> http://lists.nongnu.org/archive/html/qemu-devel/2010-09/msg00239.html

Sorry I missed your posting. I am happy with your version too, ACK from me.

I did a pull before doing this patch and didn't see it, which is why I
posted my version, but your patch does the trick nicely.

Cheers,
Jes

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-09-10 17:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-10 14:04 [Qemu-devel] [PATCH 0/1] Avoid compiler error when building block/blkdebug.c with -Wtype-limits Jes.Sorensen
2010-09-10 14:04 ` [Qemu-devel] [PATCH 1/1] " Jes.Sorensen
2010-09-10 17:05   ` [Qemu-devel] " Blue Swirl
2010-09-10 17:15     ` Jes Sorensen

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).