Introducing a poweroff(8) command
Stefan Farfeleder
stefanf at FreeBSD.org
Mon Aug 23 14:10:25 PDT 2004
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
More information about the freebsd-arch
mailing list