From owner-freebsd-arch@FreeBSD.ORG Mon Aug 23 21:10:25 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 BE4D716A4CE; Mon, 23 Aug 2004 21:10:25 +0000 (GMT) Received: from bgezal.rise.tuwien.ac.at (bgezal.rise.tuwien.ac.at [128.130.59.74]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5631E43D1D; Mon, 23 Aug 2004 21:10:25 +0000 (GMT) (envelope-from stefan@fafoe.narf.at) Received: from fafoe.narf.at (unknown [212.186.3.235]) by bgezal.rise.tuwien.ac.at (Postfix) with ESMTP id A529320AF; Mon, 23 Aug 2004 23:10:23 +0200 (CEST) Received: from wombat.fafoe.narf.at (wombat.fafoe.narf.at [192.168.1.42]) by fafoe.narf.at (Postfix) with ESMTP id 686FE40B6; Mon, 23 Aug 2004 23:09:52 +0200 (CEST) Received: by wombat.fafoe.narf.at (Postfix, from userid 1001) id B289DDD; Mon, 23 Aug 2004 23:09:49 +0200 (CEST) Date: Mon, 23 Aug 2004 23:09:49 +0200 From: Stefan Farfeleder To: John Baldwin Message-ID: <20040823210944.GC91753@wombat.fafoe.narf.at> References: <20040821191659.GA94336@gothmog.gr> <20040821202252.GB94336@gothmog.gr> <200408231141.25077.jhb@FreeBSD.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200408231141.25077.jhb@FreeBSD.org> User-Agent: Mutt/1.5.6i cc: Giorgos Keramidas cc: freebsd-arch@FreeBSD.org 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 21:10:25 -0000 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. Cheers, Stefan