Eggdev: stdarg broke rmspace() :P

lordares lordares at shatow.net
Wed Feb 25 15:55:25 CST 2004


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




More information about the Eggdev mailing list