[eggheads-patches] PATCH1.5: notes_lang_fix_1.5.patch

Fabian Knittel fknittel at gmx.de
Sun Oct 1 08:33:27 CST 2000


[ notes_lang_fix_1.5.patch ]

This patch fixes a bug caused by a formatting error in the notes
module:

   char	*name = "Fritz";
   int	 a = 398;

   printf("My name is %s and I'm %d years old.\n", a, name);

Wrap this into a language enhanced define and you don't easily see
the bug (and the compiler can't help you either).

In addition, I've cleaned up the code in a few places again.

Fabian

--
Fabian Knittel <fknittel at gmx.de> -- http://www.esc-web.de/fabian/
Signed or encrypted mail preferred.    PGP DSA key ID: 0x838B4D20
-------------- next part --------------
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/doc/UPDATES1.5 eggdrop1.5/doc/UPDATES1.5
--- eggdrop1.5~/doc/UPDATES1.5	Wed Sep 27 22:34:58 2000
+++ eggdrop1.5/doc/UPDATES1.5	Sun Oct  1 16:09:54 2000
@@ -5,6 +5,8 @@
 
 1.5.5
 Foundby   Fixedby   What....
+          Fabian    Generic cleanups.
+MsingLnk  Fabian    Fixed format-type bugs in notes.mod crashing the bot.
 various   Fabian    Added support for threaded tcl libs by implementing the
                       early-fork hack. Cleaner support will be possible in 1.7.
 Wiktor    Fabian    Disabled cycling for +a !channels. Minor cleanups.
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/scripts/getops.tcl eggdrop1.5/scripts/getops.tcl
--- eggdrop1.5~/scripts/getops.tcl	Wed Sep 27 22:34:58 2000
+++ eggdrop1.5/scripts/getops.tcl	Sat Sep 30 00:46:42 2000
@@ -367,4 +367,4 @@
 
 set getops_loaded 1
 
-putlog "GetOps v2.2f by Fabian, brainsick, Progfou, Cron at irc.pl, dtM, The_O, DarkDruid & Ernst loaded."
+putlog "GetOps v2.2f by brainsick, Progfou, Cron at irc.pl, dtM, The_O, DarkDruid & Ernst loaded."
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/chan.h eggdrop1.5/src/chan.h
--- eggdrop1.5~/src/chan.h	Wed Sep 27 22:34:58 2000
+++ eggdrop1.5/src/chan.h	Sun Oct  1 15:52:05 2000
@@ -219,8 +219,8 @@
 
 /* prototypes */
 memberlist *ismember(struct chanset_t *, char *);
-struct chanset_t *findchan();
-struct chanset_t *findchan_by_dname(char *name);
+struct chanset_t *findchan(const char *name);
+struct chanset_t *findchan_by_dname(const char *name);
 
 /* is this channel +s/+p? */
 #define channel_hidden(chan) (chan->channel.mode & (CHANPRIV | CHANSEC))
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/chanprog.c eggdrop1.5/src/chanprog.c
--- eggdrop1.5~/src/chanprog.c	Wed Sep 27 22:34:58 2000
+++ eggdrop1.5/src/chanprog.c	Sun Oct  1 15:52:51 2000
@@ -86,41 +86,35 @@
  */
 memberlist *ismember(struct chanset_t *chan, char *nick)
 {
-  memberlist *x;
+  register memberlist	*x;
 
-  x = chan->channel.member;
-  while (x && x->nick[0] && rfc_casecmp(x->nick, nick))
-    x = x->next;
-  if (!x->nick[0])
-    return NULL;
-  return x;
+  for (x = chan->channel.member; x && x->nick[0]; x = x->next)
+    if (rfc_casecmp(x->nick, nick))
+      return x;
+  return NULL;
 }
 
 /* Find a chanset by channel name as the server knows it (ie !ABCDEchannel)
  */
-struct chanset_t *findchan(char *name)
+struct chanset_t *findchan(const char *name)
 {
-  struct chanset_t *chan = chanset;
+  register struct chanset_t	*chan;
 
-  while (chan != NULL) {
+  for (chan = chanset; chan; chan = chan->next)
     if (!rfc_casecmp(chan->name, name))
       return chan;
-    chan = chan->next;
-  }
   return NULL;
 }
 
 /* Find a chanset by display name (ie !channel)
  */
-struct chanset_t *findchan_by_dname(char *name)
+struct chanset_t *findchan_by_dname(const char *name)
 {
-  struct chanset_t *chan = chanset;
+  register struct chanset_t	*chan;
 
-  while (chan != NULL) {
+  for (chan = chanset; chan; chan = chan->next)
     if (!rfc_casecmp(chan->dname, name))
       return chan;
-    chan = chan->next;
-  }
   return NULL;
 }
 
@@ -131,46 +125,33 @@
 /* Shortcut for get_user_by_host -- might have user record in one
  * of the channel caches.
  */
-struct userrec *check_chanlist(char *host)
+struct userrec *check_chanlist(const char *host)
 {
-  char *nick, *uhost, buf[UHOSTLEN];
-  memberlist *m;
-  struct chanset_t *chan;
-
-  strncpy(buf, host, UHOSTMAX);
-  buf[UHOSTMAX] = 0;	/* Why is this case sanely done, when there
-			 * are so many others? */
+  char				*nick, *uhost, buf[UHOSTLEN];
+  register memberlist		*m;
+  register struct chanset_t	*chan;
+
+  strncpy(buf, host, UHOSTMAX), buf[UHOSTMAX] = 0;
   uhost = buf;
   nick = splitnick(&uhost);
-  for (chan = chanset; chan; chan = chan->next) {
-    m = chan->channel.member;
-    while (m && m->nick[0]) {
-      if (!rfc_casecmp(nick, m->nick) &&
-	  !egg_strcasecmp(uhost, m->userhost))
+  for (chan = chanset; chan; chan = chan->next)
+    for (m = chan->channel.member; m && m->nick[0]; m = m->next)
+      if (!rfc_casecmp(nick, m->nick) && !egg_strcasecmp(uhost, m->userhost))
 	return m->user;
-      m = m->next;
-    }
-  }
   return NULL;
 }
 
 /* Shortcut for get_user_by_handle -- might have user record in channels
  */
-struct userrec *check_chanlist_hand(char *hand)
+struct userrec *check_chanlist_hand(const char *hand)
 {
-  struct chanset_t *chan = chanset;
-  memberlist *m;
+  register struct chanset_t	*chan;
+  register memberlist		*m;
 
-  while (chan) {
-    m = chan->channel.member;
-    while (m && m->nick[0]) {
-      if (m->user)
-	if (!egg_strcasecmp(m->user->handle, hand))
-	  return m->user;
-      m = m->next;
-    }
-    chan = chan->next;
-  }
+  for (chan = chanset; chan; chan = chan->next)
+    for (m = chan->channel.member; m && m->nick[0]; m = m->next)
+      if (m->user && !egg_strcasecmp(m->user->handle, hand))
+	return m->user;
   return NULL;
 }
 
@@ -179,63 +160,45 @@
  * Necessary when a hostmask is added/removed, a user is added or a new
  * userfile is loaded.
  */
-void clear_chanlist()
+void clear_chanlist(void)
 {
-  memberlist *m;
-  struct chanset_t *chan = chanset;
+  register memberlist		*m;
+  register struct chanset_t	*chan;
 
-  while (chan) {
-    m = chan->channel.member;
-    while (m && m->nick[0]) {
+  for (chan = chanset; chan; chan = chan->next)
+    for (m = chan->channel.member; m && m->nick[0]; m = m->next)
       m->user = NULL;
-      m = m->next;
-    }
-    chan = chan->next;
-  }
 }
 
 /* If this user at host is in a channel, set it (it was null)
  */
-void set_chanlist(char *host, struct userrec *rec)
+void set_chanlist(const char *host, struct userrec *rec)
 {
-  char *nick, *uhost, buf[UHOSTLEN];
-  memberlist *m;
-  struct chanset_t *chan = chanset;
+  char				*nick, *uhost, buf[UHOSTLEN];
+  register memberlist		*m;
+  register struct chanset_t	*chan;
 
-  Context;
-  strncpy(buf, host, UHOSTMAX);
-  buf[UHOSTMAX] = 0;
+  strncpy(buf, host, UHOSTMAX), buf[UHOSTMAX] = 0;
   uhost = buf;
   nick = splitnick(&uhost);
-  while (chan) {
-    m = chan->channel.member;
-    while (m && m->nick[0]) {
-      if (!rfc_casecmp(nick, m->nick) &&
-	  !egg_strcasecmp(uhost, m->userhost))
+  for (chan = chanset; chan; chan = chan->next)
+    for (m = chan->channel.member; m && m->nick[0]; m = m->next)
+      if (!rfc_casecmp(nick, m->nick) && !egg_strcasecmp(uhost, m->userhost))
 	m->user = rec;
-      m = m->next;
-    }
-    chan = chan->next;
-  }
 }
 
 /* Calculate the memory we should be using
  */
 int expmem_chanprog()
 {
-  int tot;
-  tcl_timer_t *t;
+  register int		 tot = 0;
+  register tcl_timer_t	*t;
 
   Context;
-  tot = 0;
-  for (t = timer; t; t = t->next) {
-    tot += sizeof(tcl_timer_t);
-    tot += strlen(t->cmd) + 1;
-  }
-  for (t = utimer; t; t = t->next) {
-    tot += sizeof(tcl_timer_t);
-    tot += strlen(t->cmd) + 1;
-  }
+  for (t = timer; t; t = t->next)
+    tot += sizeof(tcl_timer_t) + strlen(t->cmd) + 1;
+  for (t = utimer; t; t = t->next)
+    tot += sizeof(tcl_timer_t) + strlen(t->cmd) + 1;
   return tot;
 }
 
@@ -551,7 +514,7 @@
 
 /* Add a timer
  */
-unsigned long add_timer(tcl_timer_t ** stack, int elapse, char *cmd,
+unsigned long add_timer(tcl_timer_t **stack, int elapse, char *cmd,
 			unsigned long prev_id)
 {
   tcl_timer_t *old = (*stack);
@@ -573,7 +536,7 @@
 
 /* Remove a timer, by id
  */
-int remove_timer(tcl_timer_t ** stack, unsigned long id)
+int remove_timer(tcl_timer_t **stack, unsigned long id)
 {
   tcl_timer_t *old;
   int ok = 0;
@@ -593,7 +556,7 @@
 
 /* Check timers, execute the ones that have expired.
  */
-void do_check_timers(tcl_timer_t ** stack)
+void do_check_timers(tcl_timer_t **stack)
 {
   tcl_timer_t *mark = *stack, *old = NULL;
   char x[30];
@@ -622,7 +585,7 @@
 
 /* Wipe all timers.
  */
-void wipe_timers(Tcl_Interp * irp, tcl_timer_t ** stack)
+void wipe_timers(Tcl_Interp *irp, tcl_timer_t **stack)
 {
   tcl_timer_t *mark = *stack, *old;
 
@@ -637,7 +600,7 @@
 
 /* Return list of timers
  */
-void list_timers(Tcl_Interp * irp, tcl_timer_t * stack)
+void list_timers(Tcl_Interp *irp, tcl_timer_t *stack)
 {
   tcl_timer_t *mark = stack;
   char mins[10], id[20], *argv[3], *x;
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/mod/irc.mod/chan.c eggdrop1.5/src/mod/irc.mod/chan.c
--- eggdrop1.5~/src/mod/irc.mod/chan.c	Wed Sep 27 22:34:58 2000
+++ eggdrop1.5/src/mod/irc.mod/chan.c	Thu Sep 28 17:05:44 2000
@@ -1062,11 +1062,12 @@
   char *exempt, *who, *chname, buf[511], *msg;
   struct chanset_t *chan;
 
+  if (use_exempts == 0)
+    return 0;
+
   strncpy(buf, origmsg, 510);
   buf[510] = 0;
   msg = buf;
-  if (use_exempts == 0)
-    return 0;
   newsplit(&msg);
   chname = newsplit(&msg);
   chan = findchan(chname);
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/mod/notes.mod/notes.c eggdrop1.5/src/mod/notes.mod/notes.c
--- eggdrop1.5~/src/mod/notes.mod/notes.c	Wed Sep 27 22:34:58 2000
+++ eggdrop1.5/src/mod/notes.mod/notes.c	Sun Oct  1 15:44:27 2000
@@ -70,7 +70,7 @@
{
   Context;
   if (dcc[idx].user && (dcc[idx].user->flags & USER_BOTMAST))
-    dprintf(idx, "%s", NOTES_FORWARD_TO, e->u.string);
+    dprintf(idx, NOTES_FORWARD_TO, e->u.string);
 }
 
 /* Determine how many notes are waiting for a user.
@@ -653,8 +653,8 @@
 	dprintf(DP_HELP, "NOTICE %s :%s.\n", nick, NOTES_ERASED_ALL);
     } else {
       if (idx >= 0)
-	dprintf(idx, "%s %d note%s; %d %s.\n", NOTES_ERASED, er, (er > 1) ? "s" : "",
-		in - 1 - er, NOTES_LEFT);
+	dprintf(idx, "%s %d note%s; %d %s.\n", NOTES_ERASED, er,
+		er > 1 ? "s" : "", in - 1 - er, NOTES_LEFT);
       else
 	dprintf(DP_HELP, "NOTICE %s :%s %d note%s; %d %s.\n", nick, MISC_ERASED,
 		er, (er > 1) ? "s" : "", in - 1 - er, NOTES_LEFT);
@@ -828,37 +828,35 @@
 
 static void notes_hourly()
 {
-  int k, l;
-  struct chanset_t *chan;
-  memberlist *m;
-  char s1[256];
-  struct userrec *u;
-
   expire_notes();
   if (notify_users) {
-    chan = chanset;
-    while (chan != NULL) {
-      m = chan->channel.member;
-      while (m && m->nick[0]) {
+    register struct chanset_t	*chan;
+    register memberlist		*m;
+    int				 k;
+    register int		 l;
+    char			 s1[256];
+    struct userrec		*u;
+
+    for (chan = chanset; chan; chan = chan->next) {
+      for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
 	sprintf(s1, "%s!%s", m->nick, m->userhost);
 	u = get_user_by_host(s1);
 	if (u) {
 	  k = num_notes(u->handle);
-	  for (l = 0; l < dcc_total; l++) {
+	  for (l = 0; l < dcc_total; l++)
 	    if ((dcc[l].type->flags & DCT_CHAT) &&
-		(!egg_strcasecmp(dcc[l].nick, u->handle)))
+		!egg_strcasecmp(dcc[l].nick, u->handle)) {
 	      k = 0;		/* They already know they have notes */
-	  }
+	      break;
+	    }
 	  if (k) {
-	    dprintf(DP_HELP, NOTES_WAITING_ON, m->nick, k, k == 1 ? "" : "s",
+	    dprintf(DP_HELP, NOTES_WAITING_ON, k, k == 1 ? "" : "s",
                     origbotname);
 	    dprintf(DP_HELP, "NOTICE %s :%s /MSG %s NOTES [pass] INDEX\n",
 		        m->nick, NOTES_FORLIST, botname);
 	  }
 	}
-	m = m->next;
       }
-      chan = chan->next;
     }
     for (l = 0; l < dcc_total; l++) {
       k = num_notes(dcc[l].nick);
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/proto.h eggdrop1.5/src/proto.h
--- eggdrop1.5~/src/proto.h	Wed Sep 27 22:34:58 2000
+++ eggdrop1.5/src/proto.h	Sun Oct  1 15:54:07 2000
@@ -111,10 +111,10 @@
 void chanprog();
 void check_timers();
 void check_utimers();
-void rmspace(char *);
+void rmspace(char *s);
 void check_timers();
-void set_chanlist(char *host, struct userrec *rec);
-void clear_chanlist();
+void set_chanlist(const char *host, struct userrec *rec);
+void clear_chanlist(void);
 
 /* cmds.c */
 int check_dcc_attrs(struct userrec *, int);
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/userrec.c eggdrop1.5/src/userrec.c
--- eggdrop1.5~/src/userrec.c	Wed Sep 27 22:34:58 2000
+++ eggdrop1.5/src/userrec.c	Thu Sep 28 18:09:31 2000
@@ -534,7 +534,8 @@
   }
 }
 
-/* Rewrite the entire user file. Also write the channel file at the same time
+/* Rewrite the entire user file. Call USERFILE hook as well, probably
+ * causing the channel file to be rewritten as well.
  */
 void write_userfile(int idx)
 {
@@ -569,7 +570,7 @@
   Context;
   ok = 1;
   u = userlist;
-  while ((u != NULL) && (ok)) {
+  while (u != NULL && ok) {
     ok = write_user(u, f, idx);
     u = u->next;
   }
@@ -586,6 +587,7 @@
   Context;
   movefile(new_userfile, userfile);
   nfree(new_userfile);
+  Context;
 }
 
 int change_handle(struct userrec *u, char *newh)




More information about the Patches mailing list