From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ns03R-00070o-Mp for qemu-devel@nongnu.org; Wed, 17 Mar 2010 16:41:25 -0400 Received: from [199.232.76.173] (port=46060 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ns03R-000707-2o for qemu-devel@nongnu.org; Wed, 17 Mar 2010 16:41:25 -0400 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Ns03P-0007MZ-GW for qemu-devel@nongnu.org; Wed, 17 Mar 2010 16:41:24 -0400 Received: from mail-pv0-f173.google.com ([74.125.83.173]:41120) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Ns03P-0007MV-6C for qemu-devel@nongnu.org; Wed, 17 Mar 2010 16:41:23 -0400 Received: by pvf33 with SMTP id 33so770746pvf.4 for ; Wed, 17 Mar 2010 13:41:21 -0700 (PDT) Message-ID: <4BA13E6E.4060708@codemonkey.ws> Date: Wed, 17 Mar 2010 15:41:18 -0500 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] [TRIVIAL] usb-linux: remove unreachable default in switch statement References: <1268053115.2130.4.camel@localhost.localdomain> <201003171708.04633.paul@codesourcery.com> <4BA10E49.90703@codemonkey.ws> <201003171743.06728.paul@codesourcery.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Blue Swirl Cc: Paul Bolle , Paul Brook , qemu-devel@nongnu.org On 03/17/2010 03:15 PM, Blue Swirl wrote: > On 3/17/10, Paul Brook 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