From owner-freebsd-arch@FreeBSD.ORG Mon Aug 23 22:33:48 2004 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B0BB116A4CF for ; Mon, 23 Aug 2004 22:33:48 +0000 (GMT) Received: from mail4.speakeasy.net (mail4.speakeasy.net [216.254.0.204]) by mx1.FreeBSD.org (Postfix) with ESMTP id 836BE43D5D for ; Mon, 23 Aug 2004 22:33:48 +0000 (GMT) (envelope-from jhb@FreeBSD.org) Received: (qmail 20984 invoked from network); 23 Aug 2004 22:33:48 -0000 Received: from dsl027-160-063.atl1.dsl.speakeasy.net (HELO server.baldwin.cx) ([216.27.160.63]) (envelope-sender ) encrypted SMTP for ; 23 Aug 2004 22:33:47 -0000 Received: from [10.50.40.208] (gw1.twc.weather.com [216.133.140.1]) (authenticated bits=0) by server.baldwin.cx (8.12.11/8.12.11) with ESMTP id i7NMXdTr089863; Mon, 23 Aug 2004 18:33:39 -0400 (EDT) (envelope-from jhb@FreeBSD.org) From: John Baldwin To: freebsd-arch@FreeBSD.org Date: Mon, 23 Aug 2004 17:35:53 -0400 User-Agent: KMail/1.6.2 References: <20040821191659.GA94336@gothmog.gr> <200408231141.25077.jhb@FreeBSD.org> <20040823210944.GC91753@wombat.fafoe.narf.at> In-Reply-To: <20040823210944.GC91753@wombat.fafoe.narf.at> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200408231735.53831.jhb@FreeBSD.org> X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on server.baldwin.cx cc: Giorgos Keramidas cc: Stefan Farfeleder Subject: Re: Introducing a poweroff(8) command X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Aug 2004 22:33:48 -0000 On Monday 23 August 2004 05:09 pm, Stefan Farfeleder wrote: > On Mon, Aug 23, 2004 at 11:41:24AM -0400, John Baldwin wrote: > > On Saturday 21 August 2004 04:22 pm, Giorgos Keramidas wrote: > > > - if (strstr((p = rindex(*argv, '/')) ? p + 1 : *argv, "halt")) { > > > + p = rindex(*argv, '/') ? p + 1 : *argv; > > > + if (strcmp(p, "halt") == 0) { > > > > I think this is buggy in that p will point to the / character since you > > don't modify it in the second case. I.e. what you wrote is basically > > this: > > > > p = rindex(*argv, '/'); > > if (p != NULL) > > p + 1; /* does nothing */ > > else > > *argv; /* also does nothing */ > > No, > p = rindex(*argv, '/') ? p + 1 : *argv > is parsed as > p = (rindex(*argv, '/') ? p + 1 : *argv). > Your code is equivalent to > (p = rindex(*argv, '/')) ? p + 1 : *argv. In that case p's value is undefined when you do p + 1 and it's still a very broken piece of code. The deleted if statement from my original e-mail is not broken. :) It is true that = is parsed last though, I just misparsed operator(7). I wonder if the original code worked if you passed the full path since it would need to be your 3rd alternative. Actually, if you look at the original code, it did work as it used your 3rd alternative: - if (strstr((p = rindex(*argv, '/')) ? p + 1 : *argv, "halt")) { So my point about the new code having a but still stands, and to me it shows that the use of ?: instead of if-else only serves to obfuscate the code and lead to bugs. -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org