qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] [TRIVIAL] usb-linux: remove unreachable default


From: Anthony Liguori
Subject: Re: [Qemu-devel] [PATCH] [TRIVIAL] usb-linux: remove unreachable default in switch statement
Date: Wed, 17 Mar 2010 15:41:18 -0500
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.5) Gecko/20091209 Fedora/3.0-4.fc12 Lightning/1.0pre Thunderbird/3.0

On 03/17/2010 03:15 PM, Blue Swirl wrote:
On 3/17/10, Paul Brook<address@hidden>  wrote:
If something should never happen (as in this case) then an abort/assert
  >  >  is completely appropriate. Once things get that screwed up there's no
  >  >  right answer, and the best thing we can do is terminate immediately to
  >  >  try and avoid further damage.
  >
  >  This case was:
  >
  >  switch (foo&  0x03) {
  >  case 0: case 1: case 2: case 3:
  >  default:
  >  }
  >
  >  The default is unreachable.  Having it there just introduces more code
  >  that serves no purpose.  Unless someone does something totally foolish
  >  and changes the mask in the switch statement, there's no way it will
  >  ever be reachable.


I mistakenly remembered this was using a symbolic mask rather than a literal
  0x03. In that case I'd argue it's much easier to make the dumb error you
  describe, and the assert can be a handy cluebat.

  I guess it's largely personal preference - I prefer to add the default case to
  make it clear that falling through is never gong to be the right answer.
This breaks build (gcc 4.3.2):
   CC    usb-linux.o
cc1: warnings being treated as errors
/src/qemu/usb-linux.c: In function 'usb_linux_update_endp_table':
/src/qemu/usb-linux.c:759: error: 'type' may be used uninitialized in
this function

That's unfortunate.  I'll revert.

Regards,

Anthony Liguori






reply via email to

[Prev in Thread] Current Thread [Next in Thread]