Re: Introducing a poweroff(8) command

From: Stefan Farfeleder (stefanf_at_FreeBSD.org)
Date: 08/23/04

  • Next message: John Polstra: "Re: Introducing a poweroff(8) command"
    Date: Mon, 23 Aug 2004 23:09:49 +0200
    To: John Baldwin <jhb@FreeBSD.org>
    
    

    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
    _______________________________________________
    freebsd-arch@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-arch
    To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"


  • Next message: John Polstra: "Re: Introducing a poweroff(8) command"

    Relevant Pages

    • Re: Introducing a poweroff(8) command
      ... > I think this is buggy in that p will point to the / character since you don't ... > modify it in the second case. ... To unsubscribe, ...
      (freebsd-arch)
    • Re: Introducing a poweroff(8) command
      ... On 23-Aug-2004 John Baldwin wrote: ... > I think this is buggy in that p will point to the / character since you don't ... > modify it in the second case. ...
      (freebsd-arch)
    • Re: Memory Manager DLL Validation
      ... > NOT modify any data beyond the last used character. ... safe. ... IMO reading past the end is fine, but writing is not acceptable. ...
      (borland.public.delphi.language.basm)
    • Re: How to change ALL comma in a CEdit into double byte comma?
      ... Then modify the strings to contain the characters you need before adding ... If you need to turn one character into two you could ... the user press the comma key or there is old data which has comma and needs ...
      (microsoft.public.vc.mfc)
    • Re: add a0 format to language to print trimmed character variables
      ... The i0 for integers doesn't modify the value printed out. ... For the character case, ... character variables produce an array in which each element could ... in an I/O list as otherwise an assignment would just get a new ...
      (comp.lang.fortran)