Eggdev: stdarg broke rmspace() :P

stdarg stdarg at yahoo.com
Wed Feb 25 16:47:10 CST 2004


Yay somebody's testing! Well, the reason for the error isn't that rmspace is
broken but that it's being called with a constant argument (in this case,
"HQ"). Of course the argument to rmspace is char *, not const char *, so it's
clearly a bug to say rmspace("some constant string") because you simply can't
remove spaces from a constant string. But in the interests of not screwing
everything up I've put that workaround back.

Thanks lordares :)

Keep testing! It should be fixed now but who knows.

--- lordares <lordares at shatow.net> wrote:
> Placing the "if (p != s + strlen(s) - 1)" back above the *(p + 1) = 0,
> seems to fix it, although I don't know why you removed it in the first
> place so it might break something by placing it back...... so you can
> figure it out :P
> 
> On Wed, 25 Feb 2004, lordares wrote:
> 
> >
> > I've been testing your new functions and this has resulted in a segfault:
> >
> > Program terminated with signal 11, Segmentation fault.
> > #0  rmspace (s=0x81dbc13 "HQ") at _chanprog.c:65
> > 65   *(p + 1) = 0;
> > (gdb) bt
> > #0  rmspace (s=0x81dbc13 "HQ") at _chanprog.c:65
> > #1  0x0808857a in get_user_by_handle (bu=0x831ed40, handle=0x81dbc13 "HQ")
> > at _userrec.c:201
> > #2  0x08071803 in main (argc=2, argv=0x5fe4b1c4) at _main.c:1878
> >
> > Please note that the above output it not from a standard eggdrop, but
> > it shouldn't matter, it is using your new rmspace()
> >
> > Here is the patch that was applied:
> > diff -u -d -p -r1.47 -r1.49
> > --- a/src/chanprog.c    9 Jan 2004 05:56:36 -0000       1.47
> > +++ b/src/chanprog.c    10 Feb 2004 02:10:50 -0000      1.49
> > @@ -7,7 +7,7 @@
> >   *   telling the current programmed settings
> >   *   initializing a lot of stuff and loading the tcl scripts
> >   *
> > - * $Id: chanprog.c,v 1.47 2004/01/09 05:56:36 wcc Exp $
> > + * $Id: chanprog.c,v 1.49 2004/02/10 02:10:50 wcc Exp $
> >   */
> >  /*
> >   * Copyright (C) 1997 Robey Pointer
> > @@ -67,17 +67,21 @@ void rmspace(char *s)
> >  {
> >  #define whitespace(c) (((c) == 32) || ((c) == 9) || ((c) == 13) || ((c)
> > == 10))
> >    char *p;
> > +  int len;
> >
> > -  if (*s == '\0')
> > +  if (!*s)
> >      return;
> >
> >    /* Wipe end of string */
> >    for (p = s + strlen(s) - 1; ((whitespace(*p)) && (p >= s)); p--);
> > -  if (p != s + strlen(s) - 1)
> > -    *(p + 1) = 0;
> > +  *(p + 1) = 0;
> > +  len = p + 1 - s;
> >    for (p = s; ((whitespace(*p)) && (*p)); p++);
> > -  if (p != s)
> > -    strcpy(s, p);
> > +  len -= (p - s);
> > +  if (p != s) {
> > +    /* +1 to include the null in the copy */
> > +    memmove(s, p, len + 1);
> > +  }
> >  }
> >
> >
> > ------
> > Bryan Drewery
> >
> >


__________________________________
Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.
http://antispam.yahoo.com/tools



More information about the Eggdev mailing list