diff mbox

vga: squash build error in vga_update_memory_access()

Message ID 1314187627-20975-1-git-send-email-avi@redhat.com
State New
Headers show

Commit Message

Avi Kivity Aug. 24, 2011, 12:07 p.m. UTC
Newer gcc complains that base and size may be used uninitialized, even though
it is clearly a false warning.  Silence the warning by indicating to gcc that
the code path triggering the warning cannot happen.

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 hw/vga.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

Comments

Jan Kiszka Aug. 24, 2011, 12:46 p.m. UTC | #1
On 2011-08-24 14:07, Avi Kivity wrote:
> Newer gcc complains that base and size may be used uninitialized, even though
> it is clearly a false warning.

Mmh, gcc is getting dumber again.

>  Silence the warning by indicating to gcc that
> the code path triggering the warning cannot happen.
> 
> Signed-off-by: Avi Kivity <avi@redhat.com>
> ---
>  hw/vga.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
> 
> diff --git a/hw/vga.c b/hw/vga.c
> index 851fd68..b74e6e8 100644
> --- a/hw/vga.c
> +++ b/hw/vga.c
> @@ -179,6 +179,8 @@ static void vga_update_memory_access(VGACommonState *s)
>              base = 0xb8000;
>              size = 0x8000;
>              break;
> +        default:
> +            abort();
>          }
>          region = g_malloc(sizeof(*region));
>          memory_region_init_alias(region, "vga.chain4", &s->vram, offset, size);

...or just make the last case default?

Jan
Avi Kivity Aug. 24, 2011, 12:58 p.m. UTC | #2
On 08/24/2011 03:46 PM, Jan Kiszka wrote:
> >  +++ b/hw/vga.c
> >  @@ -179,6 +179,8 @@ static void vga_update_memory_access(VGACommonState *s)
> >               base = 0xb8000;
> >               size = 0x8000;
> >               break;
> >  +        default:
> >  +            abort();
> >           }
> >           region = g_malloc(sizeof(*region));
> >           memory_region_init_alias(region, "vga.chain4",&s->vram, offset, size);
>
> ...or just make the last case default?
>

No reason to make the code unobvious in this path, IMO.  Eventually gcc 
will be able to drop the 4/5 bytes this patch adds to the object code.
diff mbox

Patch

diff --git a/hw/vga.c b/hw/vga.c
index 851fd68..b74e6e8 100644
--- a/hw/vga.c
+++ b/hw/vga.c
@@ -179,6 +179,8 @@  static void vga_update_memory_access(VGACommonState *s)
             base = 0xb8000;
             size = 0x8000;
             break;
+        default:
+            abort();
         }
         region = g_malloc(sizeof(*region));
         memory_region_init_alias(region, "vga.chain4", &s->vram, offset, size);