Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 23 Aug 2004 23:09:49 +0200
From:      Stefan Farfeleder <stefanf@FreeBSD.org>
To:        John Baldwin <jhb@FreeBSD.org>
Cc:        freebsd-arch@FreeBSD.org
Subject:   Re: Introducing a poweroff(8) command
Message-ID:  <20040823210944.GC91753@wombat.fafoe.narf.at>
In-Reply-To: <200408231141.25077.jhb@FreeBSD.org>
References:  <20040821191659.GA94336@gothmog.gr> <20040821202252.GB94336@gothmog.gr> <200408231141.25077.jhb@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040823210944.GC91753>