Просмотр исходного кода

* Huge commit, went through every source file (exlcluding compat)
and initialised all pointers to NULL as is proper, and initialised
all array of chars to "".
* Also changed all malloc()s to calloc(1, )s


svn: 690

Bryan Drewery 22 лет назад
Родитель
Сommit
97b922f5ad
62 измененных файлов с 1886 добавлено и 2020 удалено
  1. 3 1
      Makefile.in
  2. 5 3
      src/auth.c
  3. 1 3
      src/bg.c
  4. 63 54
      src/botcmd.c
  5. 30 23
      src/botmsg.c
  6. 49 58
      src/botnet.c
  7. 38 36
      src/cfg.c
  8. 50 57
      src/chanprog.c
  9. 169 161
      src/cmds.c
  10. 1 1
      src/compat/memutil.c
  11. 0 5
      src/compat/strftime.c
  12. 1 2
      src/compat/strftime.h
  13. 14 7
      src/conf.c
  14. 11 12
      src/core_binds.c
  15. 21 17
      src/crypt.c
  16. 36 46
      src/dcc.c
  17. 23 39
      src/dccutil.c
  18. 22 16
      src/debug.c
  19. 9 10
      src/dns.c
  20. 6 6
      src/egg_timer.c
  21. 12 18
      src/flags.c
  22. 2 2
      src/garble.c
  23. 4 5
      src/log.c
  24. 14 12
      src/main.c
  25. 15 12
      src/makehelp.c
  26. 34 26
      src/makesettings.c
  27. 2 2
      src/match.c
  28. 59 62
      src/misc.c
  29. 1 1
      src/misc_file.c
  30. 44 39
      src/mod/channels.mod/channels.c
  31. 73 83
      src/mod/channels.mod/cmdschan.c
  32. 18 20
      src/mod/channels.mod/tclchan.c
  33. 6 6
      src/mod/channels.mod/udefchan.c
  34. 75 76
      src/mod/channels.mod/userchan.c
  35. 18 21
      src/mod/compress.mod/compress.c
  36. 19 22
      src/mod/console.mod/console.c
  37. 19 23
      src/mod/ctcp.mod/ctcp.c
  38. 21 23
      src/mod/dns.mod/coredns.c
  39. 0 1
      src/mod/dns.mod/dns.c
  40. 71 90
      src/mod/irc.mod/cmdsirc.c
  41. 71 69
      src/mod/irc.mod/irc.c
  42. 46 50
      src/mod/irc.mod/mode.c
  43. 23 20
      src/mod/irc.mod/msgcmds.c
  44. 4 4
      src/mod/notes.mod/cmdsnote.c
  45. 23 26
      src/mod/notes.mod/notes.c
  46. 3 3
      src/mod/server.mod/cmdsserv.c
  47. 53 59
      src/mod/server.mod/server.c
  48. 124 136
      src/mod/server.mod/servmsg.c
  49. 101 109
      src/mod/share.mod/share.c
  50. 16 18
      src/mod/share.mod/uf_features.c
  51. 56 62
      src/mod/transfer.mod/transfer.c
  52. 11 15
      src/mod/update.mod/update.c
  53. 10 7
      src/modules.c
  54. 34 32
      src/net.c
  55. 28 29
      src/shell.c
  56. 15 14
      src/sorthelp.c
  57. 8 18
      src/stringfix.c
  58. 2 2
      src/tcl.c
  59. 18 18
      src/tclhash.c
  60. 70 96
      src/userent.c
  61. 47 53
      src/userrec.c
  62. 64 79
      src/users.c

+ 3 - 1
Makefile.in

@@ -37,7 +37,9 @@ TCLLIB = @TCLLIB@
 TCLLIBFN = @TCLLIBFN@
 
 DEBCFLAGS = -DDEBUG_ASSERT -DDEBUG_MEM -g3 -ggdb3
-CFLGS = -fno-strict-aliasing
+CFLGS = -fno-strict-aliasing -Wno-format-y2k 
+#-Wuninitialized -W -Wnested-externs -Wdisabled-optimization -Winline
+#-Wpadded -Wshadow -finline-functions
 MAKEFLAGS = -s -j4
 
 MAKE_LEAF = $(MAKE) 'MAKE=$(MAKE)' 'CC=$(CC)' 'LD=$(LD)' \

+ 5 - 3
src/auth.c

@@ -52,12 +52,13 @@ void init_auth_max()
   if (auth)
     auth = realloc(auth, sizeof(struct auth_t) * max_auth);
   else
-    auth = malloc(sizeof(struct auth_t) * max_auth);
+    auth = calloc(1, sizeof(struct auth_t) * max_auth);
 }
 
 static void expire_auths()
 {
   int i = 0, idle = 0;
+
   if (!ischanhub()) return;
   for (i = 0; i < auth_total;i++) {
     if (auth[i].authed) {
@@ -81,12 +82,13 @@ void init_auth()
 #if defined(S_AUTHHASH) || defined(S_DCCAUTH)
 char *makehash(struct userrec *u, char *rand)
 {
-  char hash[256], *secpass = NULL;
+  char hash[256] = "", *secpass = NULL;
+
   if (get_user(&USERENTRY_SECPASS, u)) {
     secpass = strdup(get_user(&USERENTRY_SECPASS, u));
     secpass[strlen(secpass)] = 0;
   }
-  sprintf(hash, "%s%s%s", rand, (secpass && secpass[0]) ? secpass : "" , (authkey && authkey[0]) ? authkey : "");
+  egg_snprintf(hash, sizeof hash, "%s%s%s", rand, (secpass && secpass[0]) ? secpass : "" , (authkey && authkey[0]) ? authkey : "");
   if (secpass)
     free(secpass);
 

+ 1 - 3
src/bg.c

@@ -20,7 +20,7 @@ extern conf_t	conf;
  */
 static void bg_do_detach(pid_t p)
 {
-  FILE	*fp;
+  FILE *fp = NULL;
 
   /* Need to attempt to write pid now, not later. */
   unlink(conf.bot->pid_file);
@@ -83,7 +83,5 @@ void do_fork() {
 #endif
     exit(0);
   }
-
   lastfork = now;
 }
-

+ 63 - 54
src/botcmd.c

@@ -34,7 +34,7 @@ extern time_t		 now, online_since;
 extern party_t		*party;
 extern module_entry	*module_list;
 
-static char TBUF[1024];		/* Static buffer for goofy bot stuff */
+static char TBUF[1024] = "";		/* Static buffer for goofy bot stuff */
 
 static char base64to[256] =
 {
@@ -89,7 +89,7 @@ static void fake_alert(int idx, char *item, char *extra)
  */
 static void bot_chan2(int idx, char *msg)
 {
-  char *from, *p;
+  char *from = NULL, *p = NULL;
   int i, chan;
 
   if (bot_flags(dcc[idx].user) & BOT_ISOLATE)
@@ -100,7 +100,7 @@ static void bot_chan2(int idx, char *msg)
   /* Strip annoying control chars */
   for (p = from; *p;) {
     if ((*p < 32) || (*p == 127))
-/*      strcpy(p, p + 1); */
+/* FIXME: overlap      strcpy(p, p + 1); */
       sprintf(p, "%s", p + 1);
     else
       p++;
@@ -138,7 +138,7 @@ static void bot_chan2(int idx, char *msg)
 #ifdef S_DCCPASS
 void bot_cmdpass(int idx, char *par)
 {
-  char *p;
+  char *p = NULL;
 
   p = strchr(par, ' ');
   if (p) {
@@ -159,12 +159,17 @@ void bot_config(int idx, char *par)
 }
 
 void bot_remotecmd(int idx, char *par) {
-  char *tbot, *fbot, *fhnd, *fidx;
+  char *tbot = NULL, *fbot = NULL, *fhnd = NULL, *fidx = NULL;
+ 
+  if (par[0])
+    tbot = newsplit(&par);
+  if (par[0])
+    fbot = newsplit(&par);
+  if (par[0])
+    fhnd = newsplit(&par);
+  if (par[0])
+    fidx = newsplit(&par);
 
-  tbot = newsplit(&par);
-  fbot = newsplit(&par);
-  fhnd = newsplit(&par);
-  fidx = newsplit(&par);
   if (!strcmp(tbot, conf.bot->nick)) {
     gotremotecmd(tbot, fbot, fhnd, fidx, par);
   } else if (!strcmp(tbot, "*")) {
@@ -177,11 +182,17 @@ void bot_remotecmd(int idx, char *par) {
 }
 
 void bot_remotereply(int idx, char *par) {
-  char *tbot, *fbot, *fhnd, *fidx;
-  tbot = newsplit(&par);
-  fbot = newsplit(&par);
-  fhnd = newsplit(&par);
-  fidx = newsplit(&par);
+  char *tbot = NULL, *fbot = NULL, *fhnd = NULL, *fidx = NULL;
+
+  if (par[0])
+    tbot = newsplit(&par);
+  if (par[0])
+    fbot = newsplit(&par);
+  if (par[0])
+    fhnd = newsplit(&par);
+  if (par[0])
+    fidx = newsplit(&par);
+
   if (!strcmp(tbot, conf.bot->nick)) {
     gotremotereply(fbot, fhnd, fidx, par);
   } else {
@@ -194,7 +205,7 @@ void bot_remotereply(int idx, char *par) {
  */
 static void bot_chat(int idx, char *par)
 {
-  char *from;
+  char *from = NULL;
   int i;
 
   if (bot_flags(dcc[idx].user) & BOT_ISOLATE)
@@ -218,7 +229,7 @@ static void bot_chat(int idx, char *par)
  */
 static void bot_actchan(int idx, char *par)
 {
-  char *from, *p;
+  char *from = NULL, *p = NULL;
   int i, chan;
 
   if (bot_flags(dcc[idx].user) & BOT_ISOLATE)
@@ -248,7 +259,7 @@ static void bot_actchan(int idx, char *par)
   for (p = from; *p;) {
     if ((*p < 32) || (*p == 127))
       sprintf(p, "%s", p + 1);
-/*      strcpy(p, p + 1); */
+/* FIXME: overlap      strcpy(p, p + 1); */
     else
       p++;
   }
@@ -261,7 +272,7 @@ static void bot_actchan(int idx, char *par)
  */
 static void bot_priv(int idx, char *par)
 {
-  char *from, *p, *to = TBUF, *tobot;
+  char *from = NULL, *p = NULL, *to = TBUF, *tobot = NULL;
   int i;
 
   from = newsplit(&par);
@@ -318,7 +329,7 @@ static void bot_priv(int idx, char *par)
 
 static void bot_bye(int idx, char *par)
 {
-  char s[1024];
+  char s[1024] = "";
   int users, bots;
 
   bots = bots_in_subtree(findbot(dcc[idx].nick));
@@ -338,8 +349,8 @@ static void bot_bye(int idx, char *par)
 static void remote_tell_who(int idx, char *nick, int chan)
 {
   int i = 10, k, l, ok = 0;
-  char s[1024], *realnick;
-  struct chanset_t *c;
+  char s[1024] = "", *realnick = NULL;
+  struct chanset_t *c = NULL;
 
   realnick = strchr(nick, ':');
   if (realnick)
@@ -471,7 +482,7 @@ static void bot_sysname(int idx, char *par)
  */
 static void bot_who(int idx, char *par)
 {
-  char *from, *to, *p;
+  char *from = NULL, *to = NULL, *p = NULL;
   int i, chan;
 
   from = newsplit(&par);
@@ -503,7 +514,7 @@ static void bot_endlink(int idx, char *par)
 static void bot_infoq(int idx, char *par)
 {
   char s[200] = "", s2[32] = "", *realnick = NULL;
-  struct chanset_t *chan;
+  struct chanset_t *chan = NULL;
   time_t now2;
   int hr, min;
 
@@ -570,14 +581,13 @@ static void bot_pong(int idx, char *par)
     dcc[idx].pingtime -= now;
   else
     dcc[idx].pingtime = 120;
-
 }
 
 /* link <from@bot> <who> <to-whom>
  */
 static void bot_link(int idx, char *par)
 {
-  char *from, *bot, *rfrom;
+  char *from = NULL, *bot = NULL, *rfrom = NULL;
   int i;
 
   from = newsplit(&par);
@@ -606,7 +616,7 @@ static void bot_link(int idx, char *par)
  */
 static void bot_unlink(int idx, char *par)
 {
-  char *from, *bot, *rfrom, *p, *undes;
+  char *from = NULL, *bot = NULL, *rfrom = NULL, *p = NULL, *undes = NULL;
   int i;
 
   from = newsplit(&par);
@@ -663,7 +673,7 @@ static void bot_unlink(int idx, char *par)
  */
 static void bot_update(int idx, char *par)
 {
-  char *bot, x;
+  char *bot = NULL, x;
   int vnum;
 
   bot = newsplit(&par);
@@ -677,8 +687,8 @@ static void bot_update(int idx, char *par)
 
 static void bot_mtcl(char *botnick, char *code, char *par)
 {
+ char ret[2000] = "";
  int oidx = 0, tcode = 0;
- char ret[2000];
  
  if (!par[0]) 
   return;
@@ -711,9 +721,9 @@ static void bot_rmtcl(char *botnick, char *code, char *par)
  */
 static void bot_nlinked(int idx, char *par)
 {
-  char *newbot, *next, *p, s[1024], x;
+  char *newbot = NULL, *next = NULL, *p = NULL, s[1024] = "", x = 0;
+  struct userrec *u = NULL;
   int bogus = 0, i;
-  struct userrec *u;
 
   newbot = newsplit(&par);
   next = newsplit(&par);
@@ -784,7 +794,7 @@ static void bot_nlinked(int idx, char *par)
 static void bot_unlinked(int idx, char *par)
 {
   int i;
-  char *bot;
+  char *bot = NULL;
 
   bot = newsplit(&par);
   i = nextbot(bot);
@@ -811,7 +821,7 @@ static void bot_unlinked(int idx, char *par)
  */
 static void bot_trace(int idx, char *par)
 {
-  char *from, *dest;
+  char *from = NULL, *dest = NULL;
   int i;
 
   from = newsplit(&par);
@@ -826,7 +836,7 @@ static void bot_trace(int idx, char *par)
  */
 static void bot_traced(int idx, char *par)
 {
-  char *to, *p;
+  char *to = NULL, *p = NULL;
   int i, sock;
 
   to = newsplit(&par);
@@ -897,8 +907,8 @@ static void bot_timesync(int idx, char *par)
  */
 static void bot_reject(int idx, char *par)
 {
-  char *from, *who, *destbot, *frombot;
-  struct userrec *u;
+  char *from = NULL, *who = NULL, *destbot = NULL, *frombot = NULL;
+  struct userrec *u = NULL;
   int i;
 
   if (bot_flags(dcc[idx].user) & BOT_ISOLATE)
@@ -922,7 +932,7 @@ static void bot_reject(int idx, char *par)
       botnet_send_priv(idx, conf.bot->nick, from, NULL, "%s %s (%s)",
 		       BOT_CANTUNLINK, who, BOT_DOESNTEXIST);
     } else if (!egg_strcasecmp(dcc[i].nick, who)) {
-      char s[1024];
+      char s[1024] = "";
 
       /* I'm the connection to the rejected bot */
       putlog(LOG_BOTS, "*", "%s %s %s", from, MISC_REJECTED, dcc[i].nick);
@@ -986,7 +996,7 @@ static void bot_reject(int idx, char *par)
 static void bot_thisbot(int idx, char *par)
 {
   if (egg_strcasecmp(par, dcc[idx].nick)) {
-    char s[1024];
+    char s[1024] = "";
 
     putlog(LOG_BOTS, "*", NET_WRONGBOT, dcc[idx].nick, par);
     dprintf(idx, "bye %s\n", MISC_IMPOSTER);
@@ -1031,7 +1041,7 @@ static void bot_handshake(int idx, char *par)
  */
 static void bot_zapf(int idx, char *par)
 {
-  char *from, *to;
+  char *from = NULL, *to = NULL;
   int i;
 
   from = newsplit(&par);
@@ -1059,7 +1069,7 @@ static void bot_zapf(int idx, char *par)
  */
 static void bot_zapfbroad(int idx, char *par)
 {
-  char *from, *opcode;
+  char *from = NULL, *opcode = NULL;
   int i;
 
   from = newsplit(&par);
@@ -1083,7 +1093,7 @@ static void bot_error(int idx, char *par)
  */
 static void bot_nickchange(int idx, char *par)
 {
-  char *bot, *ssock, *newnick;
+  char *bot = NULL, *ssock = NULL, *newnick = NULL;
   int sock, i;
 
   if (bot_flags(dcc[idx].user) & BOT_ISOLATE)
@@ -1111,8 +1121,8 @@ static void bot_nickchange(int idx, char *par)
  */
 static void bot_join(int idx, char *par)
 {
-  char *bot, *nick, *x, *y;
-  struct userrec *u;
+  char *bot = NULL, *nick = NULL, *x = NULL, *y = NULL;
+  struct userrec *u = NULL;
   int i, sock, chan, i2, linking = 0;
 
   if (bot_flags(dcc[idx].user) & BOT_ISOLATE)
@@ -1174,8 +1184,8 @@ static void bot_join(int idx, char *par)
  */
 static void bot_part(int idx, char *par)
 {
-  char *bot, *nick, *etc;
-  struct userrec *u;
+  char *bot = NULL, *nick = NULL, *etc = NULL;
+  struct userrec *u = NULL;
   int sock, partyidx;
   int silent = 0;
 
@@ -1221,7 +1231,7 @@ static void bot_part(int idx, char *par)
  */
 static void bot_away(int idx, char *par)
 {
-  char *bot, *etc;
+  char *bot = NULL, *etc = NULL;
   int sock, partyidx, linking = 0;
 
   if (bot_flags(dcc[idx].user) & BOT_ISOLATE)
@@ -1264,7 +1274,7 @@ static void bot_away(int idx, char *par)
  */
 static void bot_idle(int idx, char *par)
 {
-  char *bot, *work;
+  char *bot = NULL, *work = NULL;
   int sock, idle;
 
   if (bot_flags(dcc[idx].user) & BOT_ISOLATE)
@@ -1298,8 +1308,8 @@ void bot_shareupdate(int idx, char *par)
  */
 static void bot_versions(int sock, char *par)
 {
-  char *frombot = newsplit(&par), *tobot, *from;
-  module_entry *me;
+  char *frombot = newsplit(&par), *tobot = NULL, *from = NULL;
+  module_entry *me = NULL;
 
   if (nextbot(frombot) != sock)
     fake_alert(sock, "versions-direction", frombot);
@@ -1374,10 +1384,10 @@ botcmd_t C_bot[] =
 
 void send_remote_simul(int idx, char *bot, char *cmd, char *par)
 {
-  char msg[SGRAB-110];
+  char msg[SGRAB - 110] = "";
+
   egg_snprintf(msg, sizeof msg, "r-s %d %s %d %s %lu %s %s", idx, dcc[idx].nick, dcc[idx].u.chat->con_flags, 
                dcc[idx].u.chat->con_chan, dcc[idx].status, cmd, par);
-
   putbot(bot, msg);
 }
 
@@ -1431,14 +1441,12 @@ static void bot_rsim(char *botnick, char *code, char *par)
 
 void bounce_simul(int idx, char *buf)
 {
-  char rmsg[SGRAB-110];
+  char rmsg[SGRAB - 110] = "";
 
-  if (!buf || !buf[0] || !dcc[idx].simulbot || !dcc[idx].simulbot[0] || idx < 0) {
+  if (!buf || !buf[0] || !dcc[idx].simulbot || !dcc[idx].simulbot[0] || idx < 0)
     return;
-  }
 
   egg_snprintf(rmsg, sizeof rmsg, "r-sr %d %s", dcc[idx].simul, buf);          /* remote-simul[r]eturn idx buf */
-
   putbot(dcc[idx].simulbot, rmsg);
 }
 
@@ -1446,6 +1454,7 @@ void bounce_simul(int idx, char *buf)
 static void bot_rsimr(char *botnick, char *code, char *par)
 {
   int idx = atoi(newsplit(&par));
+
   if (!par[0])
     return;
   dprintf(idx, "[%s] %s\n", botnick, par);

+ 30 - 23
src/botmsg.c

@@ -29,7 +29,7 @@ extern time_t now;
 extern party_t		*party;
 extern struct userrec	*userlist;
 
-static char	OBUF[SGRAB-110];
+static char	OBUF[SGRAB - 110] = "";
 
 
 /* Thank you ircu :) */
@@ -45,7 +45,7 @@ static char tobase64array[64] =
 
 char *int_to_base64(unsigned int val)
 {
-  static char buf_base64[12];
+  static char buf_base64[12] = "";
   int i = 11;
 
   buf_base64[11] = 0;
@@ -63,7 +63,7 @@ char *int_to_base64(unsigned int val)
 
 char *int_to_base10(int val)
 {
-  static char buf_base10[17];
+  static char buf_base10[17] = "";
   int p = 0;
   int i = 16;
 
@@ -90,7 +90,7 @@ char *int_to_base10(int val)
 
 char *unsigned_int_to_base10(unsigned int val)
 {
-  static char buf_base10[16];
+  static char buf_base10[16] = "";
   int i = 15;
 
   buf_base10[15] = 0;
@@ -108,7 +108,7 @@ char *unsigned_int_to_base10(unsigned int val)
 
 int simple_sprintf (char *buf, ...)
 {
-  char *format, *s;
+  char *format = NULL, *s = NULL;
   int c = 0, i;
   va_list va;
   
@@ -174,10 +174,10 @@ void send_tand_but(int x, char *buf, int len)
 #ifdef S_DCCPASS
 void botnet_send_cmdpass(int idx, char *cmd, char *pass)
 {
-  char *buf;
+  char *buf = NULL;
 
   if (tands > 0) {
-    buf = malloc(strlen(cmd) + strlen(pass) + 5 + 1);
+    buf = calloc(1, strlen(cmd) + strlen(pass) + 5 + 1);
     sprintf(buf, "cp %s %s\n", cmd, pass);
     send_tand_but(idx, buf, strlen(buf));
     free(buf);
@@ -187,13 +187,16 @@ void botnet_send_cmdpass(int idx, char *cmd, char *pass)
 
 int botnet_send_cmd(char * fbot, char * bot, char * from, int fromidx, char * cmd) {
   int i = nextbot(bot);
-  if (i>=0) {
-    char buf[2048];
+
+  if (i >= 0) {
+    char buf[2048] = "";
+
     sprintf(buf, STR("rc %s %s %s %i %s\n"), bot, fbot, from, fromidx, cmd);
     tputs(dcc[i].sock, buf, strlen(buf));
     return 1;
   } else if (!strcmp(bot, conf.bot->nick)) {
-    char tmp[24];
+    char tmp[24] = "";
+
     sprintf(tmp, "%i", fromidx);
     gotremotecmd(conf.bot->nick, conf.bot->nick, from, tmp, cmd);
   }
@@ -202,12 +205,14 @@ int botnet_send_cmd(char * fbot, char * bot, char * from, int fromidx, char * cm
 
 void botnet_send_cmd_broad(int idx, char * fbot, char * from, int fromidx, char * cmd) {
   if (tands > 0) {
-    char buf[2048];
-    sprintf(buf, STR("rc * %s %s %i %s\n"), fbot, from, fromidx, cmd);
+    char buf[2048] = "";
+
+    egg_snprintf(buf, sizeof buf, STR("rc * %s %s %i %s\n"), fbot, from, fromidx, cmd);
     send_tand_but(idx, buf, strlen(buf));
   }
   if (idx<0) {
-    char tmp[24];
+    char tmp[24] = "";
+
     sprintf(tmp, "%i", fromidx);
     gotremotecmd("*", conf.bot->nick, from, tmp, cmd);
   }
@@ -216,8 +221,9 @@ void botnet_send_cmd_broad(int idx, char * fbot, char * from, int fromidx, char
 void botnet_send_cmdreply(char * fbot, char * bot, char * to, char * toidx, char * ln) {
   int i = nextbot(bot);
   if (i>=0) {
-    char buf[2048];
-    sprintf(buf, STR("rr %s %s %s %s %s\n"), bot, fbot, to, toidx, ln);
+    char buf[2048] = "";
+
+    egg_snprintf(buf, sizeof buf, STR("rr %s %s %s %s %s\n"), bot, fbot, to, toidx, ln);
     tputs(dcc[i].sock, buf, strlen(buf));
   } else if (!strcmp(bot, conf.bot->nick)) {
     gotremotereply(conf.bot->nick, to, toidx, ln);
@@ -283,8 +289,8 @@ void botnet_send_pong(int idx)
 void botnet_send_priv (int idx, ...)
 {
   int l;
-  char *from, *to, *tobot, *format;
-  char tbuf[1024];
+  char *from = NULL, *to = NULL, *tobot = NULL, *format = NULL;
+  char tbuf[1024] = "";
   va_list va;
 
   va_start(va, idx);
@@ -386,7 +392,7 @@ void botnet_send_update(int idx, tand_t * ptr)
 void botnet_send_reject(int idx, char *fromp, char *frombot, char *top, char *tobot, char *reason)
 {
   int l;
-  char to[NOTENAMELEN + 1], from[NOTENAMELEN + 1];
+  char to[NOTENAMELEN + 1] = "", from[NOTENAMELEN + 1] = "";
 
   if (!(bot_flags(dcc[idx].user) & BOT_ISOLATE)) {
     if (tobot) {
@@ -406,7 +412,8 @@ void botnet_send_reject(int idx, char *fromp, char *frombot, char *top, char *to
 
 void putallbots(char *par)
 { 
-  char msg[SGRAB-110];
+  char msg[SGRAB - 110] = "";
+
   if (!par || !par[0])
     return;
   strncpyz(msg, par, sizeof msg);
@@ -416,7 +423,8 @@ void putallbots(char *par)
 void putbot(char *bot, char *par)
 {
   int i;
-  char msg[SGRAB-110];
+  char msg[SGRAB - 110] = "";
+
   if (!bot || !par || !bot[0] || !par[0])
     return;
   i = nextbot(bot);
@@ -463,8 +471,7 @@ void botnet_send_idle(int idx, char *bot, int sock, int idle, char *away)
   int l;
 
   if (tands > 0) {
-    l = simple_sprintf(OBUF, "i %s %D %D %s\n", bot, sock, idle,
-		       away ? away : "");
+    l = simple_sprintf(OBUF, "i %s %D %D %s\n", bot, sock, idle, away ? away : "");
     send_tand_but(idx, OBUF, -l);
   }
 }
@@ -562,7 +569,7 @@ void botnet_send_nkch_part(int butidx, int useridx, char *oldnick)
 int add_note(char *to, char *from, char *msg, int idx, int echo)
 {
   int status, i, iaway, sock;
-  char *p, botf[81], ss[81], ssf[81];
+  char *p = NULL, botf[81] = "", ss[81] = "", ssf[81] = "";
   struct userrec *u;
 
   if (strlen(msg) > 450)

+ 49 - 58
src/botnet.c

@@ -31,10 +31,10 @@ extern Tcl_Interp		*interp;
 extern struct cfg_entry 	**cfg;
 
 
-tand_t			*tandbot;			/* Keep track of tandem bots on the
+tand_t			*tandbot = NULL;		/* Keep track of tandem bots on the
 							   botnet */
 party_t			*party;				/* Keep track of people on the botnet */
-static int 		maxparty = 200;			/* Maximum space for party line members
+static int 		maxparty = 100;			/* Maximum space for party line members
 							   currently */
 int			tands = 0;			/* Number of bots on the botnet */
 int			parties = 0;			/* Number of people on the botnet */
@@ -43,15 +43,12 @@ int			share_unlinks = 1;		/* Allow remote unlinks of my
 
 void init_bots()
 {
-  tandbot = NULL;
-  /* Grab space for 50 bots for now -- expand later as needed */
-  maxparty = 50;
-  party = (party_t *) malloc(maxparty * sizeof(party_t));
+  party = (party_t *) calloc(1, maxparty * sizeof(party_t));
 }
 
 tand_t *findbot(char *who)
 {
-  tand_t *ptr;
+  tand_t *ptr = NULL;
 
   for (ptr = tandbot; ptr; ptr = ptr->next)
     if (!egg_strcasecmp(ptr->bot, who))
@@ -63,14 +60,14 @@ tand_t *findbot(char *who)
  */
 void addbot(char *who, char *from, char *next, char flag, int vernum)
 {
-  tand_t **ptr = &tandbot, *ptr2;
+  tand_t **ptr = &tandbot, *ptr2 = NULL;
 
   while (*ptr) {
     if (!egg_strcasecmp((*ptr)->bot, who))
       putlog(LOG_BOTS, "*", "!!! Duplicate botnet bot entry!!");
     ptr = &((*ptr)->next);
   }
-  ptr2 = malloc(sizeof(tand_t));
+  ptr2 = calloc(1, sizeof(tand_t));
   strncpy(ptr2->bot, who, HANDLEN);
   ptr2->bot[HANDLEN] = 0;
   ptr2->share = flag;
@@ -90,7 +87,7 @@ void addbot(char *who, char *from, char *next, char flag, int vernum)
 #ifdef G_BACKUP
 void check_should_backup()
 {
-  struct chanset_t *chan;
+  struct chanset_t *chan = NULL;
 
   for (chan = chanset; chan; chan = chan->next) {
     if (chan->channel.backup_time && (chan->channel.backup_time < now) && !channel_backup(chan)) {
@@ -249,7 +246,7 @@ int partyidle(char *bot, char *nick)
  */
 int partynick(char *bot, int sock, char *nick)
 {
-  char work[HANDLEN + 1];
+  char work[HANDLEN + 1] = "";
   int i;
 
   for (i = 0; i < parties; i++) {
@@ -287,8 +284,8 @@ void partyaway(char *bot, int sock, char *msg)
  */
 void rembot(char *who)
 {
-  tand_t **ptr = &tandbot, *ptr2;
-  struct userrec *u;
+  tand_t **ptr = &tandbot, *ptr2 = NULL;
+  struct userrec *u = NULL;
 
   while (*ptr) {
     if (!egg_strcasecmp((*ptr)->bot, who))
@@ -357,7 +354,7 @@ void rempartybot(char *bot)
  */
 void unvia(int idx, tand_t * who)
 {
-  tand_t *bot, *bot2;
+  tand_t *bot = NULL, *bot2 = NULL;
 
   if (!who)
     return;			/* Safety */
@@ -377,8 +374,8 @@ void unvia(int idx, tand_t * who)
 void besthub(char *hub)
 {
   tand_t *ptr = tandbot;
-  struct userrec *u, *besthub = NULL;
-  char bestlval[20], lval[20];
+  struct userrec *u = NULL, *besthub = NULL;
+  char bestlval[20] = "", lval[20] = "";
 
   hub[0] = 0;
   strcpy(bestlval, "z");
@@ -433,9 +430,8 @@ char *lastbot(char *who)
  */
 void answer_local_whom(int idx, int chan)
 {
-  char format[81];
-  char c, idle[40];
-  int i, t, nicklen, botnicklen, total=0;
+  char format[81] = "", c = 0, idle[40] = "";
+  int i, t, nicklen, botnicklen, total = 0;
 
   if (chan == (-1))
     dprintf(idx, "%s (+: %s, *: %s)\n", BOT_BOTNETUSERS, BOT_PARTYLINE,
@@ -558,9 +554,9 @@ void answer_local_whom(int idx, int chan)
  */
 void tell_bots(int idx)
 {
-  char s[512];
+  char s[512] = "";
   int i;
-  tand_t *bot;
+  tand_t *bot = NULL;
 
   if (!tands) {
     dprintf(idx, STR("No bots linked\n"));
@@ -592,18 +588,16 @@ void tell_bots(int idx)
  */
 void tell_bottree(int idx, int showver)
 {
-  char s[161];
-  tand_t *last[20], *this, *bot, *bot2 = NULL;
-  int lev = 0, more = 1, mark[20], ok, cnt, i, imark;
-  char work[1024];
-  int tothops = 0;
+  char s[161] = "", work[1024] = "";
+  tand_t *last[20] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+                       NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
+  tand_t *this = NULL, *bot = NULL, *bot2 = NULL;
+  int lev = 0, more = 1, mark[20], ok, cnt, i = 0, imark, tothops = 0;
 
   if (tands == 0) {
     dprintf(idx, "%s\n", BOT_NOBOTSLINKED);
     return;
   }
-  s[0] = 0;
-  i = 0;
 
   for (bot = tandbot; bot; bot = bot->next)
     if (!bot->uplink) {
@@ -748,11 +742,11 @@ void tell_bottree(int idx, int showver)
 void dump_links(int z)
 {
   register int i, l;
-  char x[1024];
-  tand_t *bot;
+  char x[1024] = "";
+  tand_t *bot = NULL;
 
   for (bot = tandbot; bot; bot = bot->next) {
-    char *p;
+    char *p = NULL;
 
     if (bot->uplink == (tand_t *) 1)
       p = conf.bot->nick;
@@ -808,7 +802,7 @@ int in_chain(char *who)
 int bots_in_subtree(tand_t *bot)
 {
   int nr = 1;
-  tand_t *b;
+  tand_t *b = NULL;
 
   if (!bot)
     return 0;
@@ -823,7 +817,7 @@ int bots_in_subtree(tand_t *bot)
 int users_in_subtree(tand_t *bot)
 {
   int i, nr;
-  tand_t *b;
+  tand_t *b = NULL;
 
   nr = 0;
   if (!bot)
@@ -841,10 +835,10 @@ int users_in_subtree(tand_t *bot)
  */
 int botunlink(int idx, char *nick, char *reason)
 {
-  char s[20];
   register int i;
   int bots, users;
-  tand_t *bot;
+  char s[20] = "";
+  tand_t *bot = NULL;
 
   if (nick[0] == '*')
     dprintf(idx, "%s\n", BOT_UNLINKALL);
@@ -950,8 +944,8 @@ static void botlink_resolve_failure(int);
  */
 int botlink(char *linker, int idx, char *nick)
 {
-  struct bot_addr *bi;
-  struct userrec *u;
+  struct bot_addr *bi = NULL;
+  struct userrec *u = NULL;
   register int i;
 
   u = get_user_by_handle(userlist, nick);
@@ -1122,9 +1116,9 @@ static void tandem_relay_resolve_success(int);
  */
 void tandem_relay(int idx, char *nick, register int i)
 {
-  struct userrec *u;
-  struct bot_addr *bi;
-  struct chat_info *ci;
+  struct userrec *u = NULL;
+  struct bot_addr *bi = NULL;
+  struct chat_info *ci = NULL;
 
   u = get_user_by_handle(userlist, nick);
   if (!u || !(u->flags & USER_BOT)) {
@@ -1195,7 +1189,7 @@ void tandem_relay(int idx, char *nick, register int i)
 
 static void tandem_relay_resolve_failure(int idx)
 {
-  struct chat_info *ci;
+  struct chat_info *ci = NULL;
   register int uidx = (-1), i;
 
   for (i = 0; i < dcc_total; i++)
@@ -1344,7 +1338,7 @@ static void failed_pre_relay(int idx)
 static void cont_tandem_relay(int idx, char *buf, register int i)
 {
   register int uidx = (-1);
-  struct relay_info *ri;
+  struct relay_info *ri = NULL;
 
   for (i = 0; i < dcc_total; i++)
     if ((dcc[i].type == &DCC_PRE_RELAY) &&
@@ -1383,7 +1377,7 @@ static void cont_tandem_relay(int idx, char *buf, register int i)
 static void eof_dcc_relay(int idx)
 {
   register int j;
-  struct chat_info *ci;
+  struct chat_info *ci = NULL;
 
   for (j = 0; j < dcc_total; j++)
     if (dcc[j].sock == dcc[idx].u.relay->sock)
@@ -1457,7 +1451,7 @@ static void dcc_relay(int idx, char *buf, int j)
       } else if (*p == '\033') {
 	unsigned char	*e;
 
-	// Search for the end of the escape sequence.
+	/* Search for the end of the escape sequence. */
 	for (e = p + 2; *e != 'm' && *e; e++)
 	  ;
 	strcpy((char *) p, (char *) (e + 1));
@@ -1479,7 +1473,7 @@ static void dcc_relay(int idx, char *buf, int j)
 
 static void dcc_relaying(int idx, char *buf, int j)
 {
-  struct chat_info *ci;
+  struct chat_info *ci = NULL;
 
   if (egg_strcasecmp(buf, "*bye*")) {
     dprintf(-dcc[idx].u.relay->sock, "%s\n", buf);
@@ -1610,7 +1604,7 @@ void check_botnet_pings()
 {
   int i;
   int bots, users;
-  tand_t *bot;
+  tand_t *bot = NULL;
 
   for (i = 0; i < dcc_total; i++) {
     if (dcc[i].type == &DCC_BOT)
@@ -1683,9 +1677,9 @@ void check_botnet_pings()
 
 void zapfbot(int idx)
 {
-  char s[1024];
+  char s[1024] = "";
   int bots, users;
-  tand_t *bot;
+  tand_t *bot = NULL;
 
   bot = findbot(dcc[idx].nick);
   bots = bots_in_subtree(bot);
@@ -1718,15 +1712,12 @@ void restart_chons()
 }
 static int get_role(char *bot)
 {
-  int rl,
-    i;
-  struct bot_addr *ba;
+  int rl, i;
+  struct bot_addr *ba = NULL;
   int r[5] = { 0, 0, 0, 0, 0 };
-  struct userrec *u,
-   *u2;
+  struct userrec *u = NULL, *u2 = NULL;
 
-  u2 = get_user_by_handle(userlist, bot);
-  if (!u2)
+  if (!(u2 = get_user_by_handle(userlist, bot)))
     return 1;
 
   for (u = userlist; u; u = u->next) {
@@ -1752,10 +1743,10 @@ static int get_role(char *bot)
 
 void lower_bot_linked(int idx)
 {
-  char tmp[6];
-  sprintf(tmp, STR("rl %d"), get_role(dcc[idx].nick));
-  botnet_send_zapf(nextbot(dcc[idx].nick), conf.bot->nick, dcc[idx].nick, tmp);
+  char tmp[6] = "";
 
+  sprintf(tmp, "rl %d", get_role(dcc[idx].nick));
+  botnet_send_zapf(nextbot(dcc[idx].nick), conf.bot->nick, dcc[idx].nick, tmp);
 }
 
 void higher_bot_linked(int idx)

+ 38 - 36
src/cfg.c

@@ -29,7 +29,7 @@ int 				cfg_count = 0, cfg_noshare = 0;
 struct cfg_entry 		**cfg = NULL;
 
 #if defined(S_AUTHHASH) || defined(S_DCCAUTH)
-char 				authkey[121];		/* This is one of the keys used in the auth hash */
+char 				authkey[121] = "";	/* This is one of the keys used in the auth hash */
 #endif /* S_AUTHHASH || S_DCCAUTH */
 
 char 				cmdprefix[1] = "+";	/* This is the prefix for msg/channel cmds */
@@ -129,28 +129,30 @@ void deflag_describe(struct cfg_entry *cfgent, int idx)
 {
   if (cfgent == &CFG_BADCOOKIE)
     dprintf(idx, STR("bad-cookie decides what happens to a bot if it does an illegal op (no/incorrect op cookie)\n"));
-  else if (cfgent==&CFG_MANUALOP)
+  else if (cfgent == &CFG_MANUALOP)
     dprintf(idx, STR("manop decides what happens to a user doing a manual op in a -manop channel\n"));
 #ifdef G_MEAN
-  else if (cfgent==&CFG_MEANDEOP)
+  else if (cfgent == &CFG_MEANDEOP)
     dprintf(idx, STR("mean-deop decides what happens to a user deopping a bot in a +mean channel\n"));
-  else if (cfgent==&CFG_MEANKICK)
+  else if (cfgent == &CFG_MEANKICK)
     dprintf(idx, STR("mean-kick decides what happens to a user kicking a bot in a +mean channel\n"));
-  else if (cfgent==&CFG_MEANBAN)
+  else if (cfgent == &CFG_MEANBAN)
     dprintf(idx, STR("mean-ban decides what happens to a user banning a bot in a +mean channel\n"));
 #endif /* G_MEAN */
-  else if (cfgent==&CFG_MDOP)
+  else if (cfgent == &CFG_MDOP)
     dprintf(idx, STR("mdop decides what happens to a user doing a mass deop\n"));
-  else if (cfgent==&CFG_MOP)
+  else if (cfgent == &CFG_MOP)
     dprintf(idx, STR("mop decides what happens to a user doing a mass op\n"));
   dprintf(idx, STR("Valid settings are: ignore (No flag changes), deop (set flags to +d), kick (set flags to +dk) or delete (remove from userlist)\n"));
 }
 
 void deflag_changed(struct cfg_entry *entry, char *oldval, int *valid) 
 {
-  char *p = (char *) entry->gdata;
-  if (!p)
+  char *p = NULL;
+
+  if (!(p = (char *) entry->gdata))
     return;
+
   if (strcmp(p, STR("ignore")) && strcmp(p, STR("deop")) && strcmp(p, STR("kick")) && strcmp(p, STR("delete")))
     *valid=0;
 }
@@ -195,9 +197,8 @@ struct cfg_entry CFG_MOP = {
 
 void deflag_user(struct userrec *u, int why, char *msg, struct chanset_t *chan)
 {
-  char tmp[256], tmp2[1024];
+  char tmp[256] = "", tmp2[1024] = "";
   struct cfg_entry *ent = NULL;
-
   struct flag_record fr = {FR_GLOBAL, FR_CHAN, 0, 0, 0};
 
   if (!u)
@@ -302,15 +303,15 @@ void misc_describe(struct cfg_entry *cfgent, int idx)
 void fork_lchanged(struct cfg_entry * cfgent, char * oldval, int * valid) {
   if (!cfgent->ldata)
     return;
-  if (atoi(cfgent->ldata)<=0)
-    *valid=0;
+  if (atoi(cfgent->ldata) <= 0)
+    *valid = 0;
 }
 
 void fork_gchanged(struct cfg_entry * cfgent, char * oldval, int * valid) {
   if (!cfgent->gdata)
     return;
-  if (atoi(cfgent->gdata)<=0)
-    *valid=0;
+  if (atoi(cfgent->gdata) <= 0)
+    *valid = 0;
 }
 
 void fork_describe(struct cfg_entry * cfgent, int idx) {
@@ -323,16 +324,17 @@ struct cfg_entry CFG_FORKINTERVAL = {
 };
 
 void detect_lchanged(struct cfg_entry * cfgent, char * oldval, int * valid) {
-  char * p = cfgent->ldata;
-  if (!p)
-    *valid=1;
+  char *p = NULL;
+
+  if (!(p = (char *) cfgent->ldata))
+    *valid = 1;
   else if (strcmp(p, STR("ignore")) && strcmp(p, STR("die")) && strcmp(p, STR("reject"))
            && strcmp(p, STR("suicide")) && strcmp(p, STR("warn")))
-    *valid=0;
+    *valid = 0;
 }
 
 void detect_gchanged(struct cfg_entry * cfgent, char * oldval, int * valid) {
-  char * p = (char *) cfgent->ldata;
+  char *p = (char *) cfgent->ldata;
   if (!p)
     *valid=1;
   else if (strcmp(p, STR("ignore")) && strcmp(p, STR("die")) && strcmp(p, STR("reject"))
@@ -471,9 +473,10 @@ void getin_changed(struct cfg_entry *cfgent, char *oldval, int *valid)
     return;
   }
   if (!strcmp(cfgent->name, STR("lock-threshold"))) {
-    int L,
-      R;
-    char *value = cfgent->gdata;
+    int L, R;
+    char *value = NULL;
+
+    value = cfgent->gdata;
 
     L = atoi(value);
     value = strchr(value, ':');
@@ -565,7 +568,7 @@ void add_cfg(struct cfg_entry *entry)
 struct cfg_entry *check_can_set_cfg(char *target, char *entryname)
 {
   int i;
-  struct userrec *u;
+  struct userrec *u = NULL;
   struct cfg_entry *entry = NULL;
 
   for (i = 0; i < cfg_count; i++)
@@ -591,7 +594,7 @@ struct cfg_entry *check_can_set_cfg(char *target, char *entryname)
 
 void set_cfg_str(char *target, char *entryname, char *data)
 {
-  struct cfg_entry *entry;
+  struct cfg_entry *entry = NULL;
 
   if (!(entry = check_can_set_cfg(target, entryname)))
     return;
@@ -622,8 +625,7 @@ void set_cfg_str(char *target, char *entryname, char *data)
         }
       }
     }
-    xk = malloc(sizeof(struct xtra_key));
-    egg_bzero(xk, sizeof(struct xtra_key));
+    xk = calloc(1, sizeof(struct xtra_key));
     xk->key = strdup(entry->name);
     if (data) {
       xk->data = strdup(data);
@@ -714,11 +716,11 @@ void init_config()
 #ifdef S_DCCPASS
 int check_cmd_pass(char *cmd, char *pass)
 {
-  struct cmd_pass *cp;
+  struct cmd_pass *cp = NULL;
 
   for (cp = cmdpass; cp; cp = cp->next)
     if (!egg_strcasecmp(cmd, cp->name)) {
-      char tmp[32];
+      char tmp[32] = "";
 
       encrypt_pass(pass, tmp);
       if (!strcmp(tmp, cp->pass))
@@ -730,7 +732,7 @@ int check_cmd_pass(char *cmd, char *pass)
 
 int has_cmd_pass(char *cmd) 
 {
-  struct cmd_pass *cp;
+  struct cmd_pass *cp = NULL;
 
   for (cp = cmdpass; cp; cp = cp->next)
     if (!egg_strcasecmp(cmd, cp->name))
@@ -740,8 +742,8 @@ int has_cmd_pass(char *cmd)
 
 void set_cmd_pass(char *ln, int shareit) 
 {
-  struct cmd_pass *cp;
-  char *cmd;
+  struct cmd_pass *cp = NULL;
+  char *cmd = NULL;
 
   cmd = newsplit(&ln);
   for (cp = cmdpass; cp; cp = cp->next)
@@ -770,7 +772,7 @@ void set_cmd_pass(char *ln, int shareit)
       free(cp);
   } else if (ln[0]) {
     /* create */
-    cp = malloc(sizeof(struct cmd_pass));
+    cp = calloc(1, sizeof(struct cmd_pass));
     cp->next = cmdpass;
     cmdpass = cp;
     cp->name = strdup(cmd);
@@ -783,7 +785,7 @@ void set_cmd_pass(char *ln, int shareit)
 
 void userfile_cfg_line(char *ln)
 {
-  char *name;
+  char *name = NULL;
   int i;
   struct cfg_entry *cfgent = NULL;
 
@@ -800,7 +802,7 @@ void userfile_cfg_line(char *ln)
 
 void got_config_share(int idx, char *ln)
 {
-  char *name;
+  char *name = NULL;
   int i;
   struct cfg_entry *cfgent = NULL;
 
@@ -820,7 +822,7 @@ void got_config_share(int idx, char *ln)
 void trigger_cfg_changed()
 {
   int i;
-  struct xtra_key *xk;
+  struct xtra_key *xk = NULL;
 
   for (i = 0; i < cfg_count; i++) {
     if (cfg[i]->flags & CFGF_LOCAL) {

+ 50 - 57
src/chanprog.c

@@ -56,7 +56,7 @@ int     		my_port;
  */
 void rmspace(char *s)
 {
-  char *p, *end;
+  char *p = NULL, *end = NULL;
   int len;
 
   if (!s || (s && !*s))
@@ -79,7 +79,7 @@ void rmspace(char *s)
  */
 memberlist *ismember(struct chanset_t *chan, char *nick)
 {
-  register memberlist	*x;
+  register memberlist	*x = NULL;
 
   for (x = chan->channel.member; x && x->nick[0]; x = x->next)
     if (!rfc_casecmp(x->nick, nick))
@@ -91,7 +91,7 @@ memberlist *ismember(struct chanset_t *chan, char *nick)
  */
 struct chanset_t *findchan(const char *name)
 {
-  register struct chanset_t	*chan;
+  register struct chanset_t	*chan = NULL;
 
   for (chan = chanset; chan; chan = chan->next)
     if (!rfc_casecmp(chan->name, name))
@@ -103,7 +103,7 @@ struct chanset_t *findchan(const char *name)
  */
 struct chanset_t *findchan_by_dname(const char *name)
 {
-  register struct chanset_t	*chan;
+  register struct chanset_t	*chan = NULL;
 
   for (chan = chanset; chan; chan = chan->next)
     if (!rfc_casecmp(chan->dname, name))
@@ -120,9 +120,9 @@ struct chanset_t *findchan_by_dname(const char *name)
  */
 struct userrec *check_chanlist(const char *host)
 {
-  char				*nick, *uhost, buf[UHOSTLEN];
-  register memberlist		*m;
-  register struct chanset_t	*chan;
+  char				*nick = NULL, *uhost = NULL, buf[UHOSTLEN] = "";
+  register memberlist		*m = NULL;
+  register struct chanset_t	*chan = NULL;
 
   strncpyz(buf, host, sizeof buf);
   uhost = buf;
@@ -138,8 +138,8 @@ struct userrec *check_chanlist(const char *host)
  */
 struct userrec *check_chanlist_hand(const char *hand)
 {
-  register struct chanset_t	*chan;
-  register memberlist		*m;
+  register struct chanset_t	*chan = NULL;
+  register memberlist		*m = NULL;
 
   for (chan = chanset; chan; chan = chan->next)
     for (m = chan->channel.member; m && m->nick[0]; m = m->next)
@@ -155,8 +155,8 @@ struct userrec *check_chanlist_hand(const char *hand)
  */
 void clear_chanlist(void)
 {
-  register memberlist		*m;
-  register struct chanset_t	*chan;
+  register memberlist		*m = NULL;
+  register struct chanset_t	*chan = NULL;
 
   for (chan = chanset; chan; chan = chan->next)
     for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
@@ -173,8 +173,8 @@ void clear_chanlist(void)
  */
 void clear_chanlist_member(const char *nick)
 {
-  register memberlist		*m;
-  register struct chanset_t	*chan;
+  register memberlist		*m = NULL;
+  register struct chanset_t	*chan = NULL;
 
   for (chan = chanset; chan; chan = chan->next)
     for (m = chan->channel.member; m && m->nick[0]; m = m->next)
@@ -189,9 +189,9 @@ void clear_chanlist_member(const char *nick)
  */
 void set_chanlist(const char *host, struct userrec *rec)
 {
-  char				*nick, *uhost, buf[UHOSTLEN];
-  register memberlist		*m;
-  register struct chanset_t	*chan;
+  char				*nick = NULL, *uhost = NULL, buf[UHOSTLEN] = "";
+  register memberlist		*m = NULL;
+  register struct chanset_t	*chan = NULL;
 
   strncpyz(buf, host, sizeof buf);
   uhost = buf;
@@ -209,9 +209,9 @@ void set_chanlist(const char *host, struct userrec *rec)
 
 void checkchans(int which)
 {
-  struct chanset_t *chan, *chan_next;
+  struct chanset_t *chan = NULL, *chan_next = NULL;
 
-  sdprintf(STR("checkchans(%d)"), which);
+  sdprintf("checkchans(%d)", which);
   if (which == 0 || which == 2) {
     for (chan = chanset; chan; chan = chan->next) {
       if (which == 0) {
@@ -221,7 +221,8 @@ void checkchans(int which)
       }
     }
   } else if (which == 1) {
-    module_entry *me;
+    module_entry *me = NULL;
+
     for (chan = chanset; chan; chan = chan_next) {
       chan_next = chan->next;
       if (chan->status & CHAN_FLAGGED) {
@@ -241,7 +242,7 @@ void checkchans(int which)
  */
 void tell_verbose_uptime(int idx)
 {
-  char s[256], s1[121];
+  char s[256] = "", s1[121] = "";
   time_t now2, hr, min;
 
   now2 = now - online_since;
@@ -274,8 +275,7 @@ void tell_verbose_uptime(int idx)
  */
 void tell_verbose_status(int idx)
 {
-  char s[256], s1[121], s2[81];
-  char *vers_t, *uni_t;
+  char s[256] = "", s1[121] = "", s2[81] = "", *vers_t = NULL, *uni_t = NULL;
 #ifdef HUB
   int i;
 #endif /* HUB */
@@ -358,7 +358,7 @@ void tell_verbose_status(int idx)
  */
 void tell_settings(int idx)
 {
-  char s[1024];
+  char s[1024] = "";
   struct flag_record fr = {FR_GLOBAL, 0, 0, 0, 0, 0};
 
   dprintf(idx, "Botnet Nickname: %s\n", conf.bot->nick);
@@ -382,10 +382,10 @@ void tell_settings(int idx)
 
 void reaffirm_owners()
 {
-  char *p, *q, s[121];
-  struct userrec *u;
+  char *p = NULL, *q = NULL, s[121] = "";
+  struct userrec *u = NULL;
 
-  /* Make sure default owners are +a */
+  /* Make sure perm owners are +a */
   if (owner[0]) {
     q = owner;
     p = strchr(q, ',');
@@ -408,19 +408,11 @@ void reaffirm_owners()
 
 void load_internal_users()
 {
-  char *p = NULL,
-   *ln,
-   *hand,
-   *ip,
-   *port,
-   *pass,
-   *hosts,
-    host[UHOSTMAX] = "",
-    buf[2048] = "";
-  char *attr;
+  char *p = NULL, *ln = NULL, *hand = NULL, *ip = NULL, *port = NULL, *pass = NULL;
+  char *hosts = NULL, host[UHOSTMAX] = "", buf[2048] = "", *attr = NULL;
   int i, hublevel = 0;
-  struct bot_addr *bi;
-  struct userrec *u;
+  struct bot_addr *bi = NULL;
+  struct userrec *u = NULL;
 
   /* hubs */
   egg_snprintf(buf, sizeof buf, "%s", hubs);
@@ -449,7 +441,8 @@ void load_internal_users()
         hublevel++;		/* We must increment this even if it is already added */
 	if (!get_user_by_handle(userlist, hand)) {
 	  userlist = adduser(userlist, hand, "none", "-", USER_BOT | USER_OP);
-	  bi = malloc(sizeof(struct bot_addr));
+	  bi = calloc(1, sizeof(struct bot_addr));
+
           bi->address = strdup(ip);
 	  bi->telnet_port = atoi(port) ? atoi(port) : 0;
 	  bi->relay_port = bi->telnet_port;
@@ -458,8 +451,7 @@ void load_internal_users()
 	  if ((!bi->hublevel) && (!strcmp(hand, conf.bot->nick)))
 	    bi->hublevel = 99;
 #endif /* HUB */
-          bi->uplink = malloc(1);
-          bi->uplink[0] = 0;
+          bi->uplink = calloc(1, 1);
 	  set_user(&USERENTRY_BOTADDR, get_user_by_handle(userlist, hand), bi);
 	  /* set_user(&USERENTRY_PASS, get_user_by_handle(userlist, hand), SALT2); */
 	}
@@ -541,7 +533,7 @@ void load_internal_users()
 void chanprog()
 {
   /* char buf[2048] = ""; */
-  struct bot_addr *bi;
+  struct bot_addr *bi = NULL;
 
   admin[0] = 0;
   /* cache our ip on load instead of every 30 seconds */
@@ -574,7 +566,7 @@ void chanprog()
     /* I need to be on the userlist... doh. */
     userlist = adduser(userlist, conf.bot->nick, "none", "-", USER_BOT | USER_OP );
     conf.bot->u = get_user_by_handle(userlist, conf.bot->nick);
-    bi = malloc(sizeof(struct bot_addr));
+    bi = calloc(1, sizeof(struct bot_addr));
 
     bi->address = strdup(conf.bot->ip);
     /* bi->telnet_port = atoi(buf) ? atoi(buf) : 3333; */
@@ -584,8 +576,7 @@ void chanprog()
 #else
     bi->hublevel = 0;
 #endif /* HUB */
-    bi->uplink = malloc(1);
-    bi->uplink[0] = 0;
+    bi->uplink = calloc(1, 1);
     set_user(&USERENTRY_BOTADDR, conf.bot->u, bi);
   } else {
     bi = get_user(&USERENTRY_BOTADDR, conf.bot->u);
@@ -630,7 +621,7 @@ void chanprog()
  */
 void reload()
 {
-  FILE *f;
+  FILE *f = NULL;
 
   f = fopen(userfile, "r");
   if (f == NULL) {
@@ -667,7 +658,7 @@ void rehash()
  */
 int isowner(char *name)
 {
-  char *pa, *pb;
+  char *pa = NULL, *pb = NULL;
   char nl, pl;
 
   if (!owner || !*owner)
@@ -721,17 +712,17 @@ int shouldjoin(struct chanset_t *chan)
  */
 void do_chanset(struct chanset_t *chan, char *options, int local)
 {
-  char *buf;
-  module_entry *me;
+  char *buf = NULL;
+  module_entry *me = NULL;
 
   /* send out over botnet. */
   if (local != 2) {
-         /* malloc(options,chan,'cset ',' ',+ 1) */
+         /* calloc(1, options,chan,'cset ',' ',+ 1) */
     if (chan)
-      buf = malloc(strlen(options) + strlen(chan->dname) + 5 + 1 + 1);
+      buf = calloc(1, strlen(options) + strlen(chan->dname) + 5 + 1 + 1);
     else
-      buf = malloc(strlen(options) + 1 + 5 + 1 + 1);
-    buf[0] = 0;
+      buf = calloc(1, strlen(options) + 1 + 5 + 1 + 1);
+
     strcat(buf, "cset ");
     if (chan)
       strcat(buf, chan->dname);
@@ -744,12 +735,13 @@ void do_chanset(struct chanset_t *chan, char *options, int local)
     putallbots(buf); 
     free(buf);
   }
+
   /* now set locally, hopefully it works */
   if (local && (me = module_find("channels", 0, 0))) {
   /* tcl_channel_modify(0, chan, 1, options) */
     Function *func = me->funcs;
-    char *buf2, *bak;
-    struct chanset_t *ch;
+    char *buf2 = NULL, *bak = NULL;
+    struct chanset_t *ch = NULL;
     int all = 0;
 
     if (!chan) {
@@ -759,10 +751,11 @@ void do_chanset(struct chanset_t *chan, char *options, int local)
       ch = chan;
 
     bak = options;
-    buf2 = malloc(strlen(options) + 1);
+    buf2 = calloc(1, strlen(options) + 1);
 
     while (ch) {
-      char *list[2];
+      char *list[2] = { NULL, NULL };
+
       strcpy(buf2, bak);
       options = buf2;
       list[0] = newsplit(&options);

Разница между файлами не показана из-за своего большого размера
+ 169 - 161
src/cmds.c


+ 1 - 1
src/compat/memutil.c

@@ -18,7 +18,7 @@ void str_redup(char **str, const char *newstr)
 
 char *strdup(const char *entry)
 {
-  char *target = (char*)malloc(strlen(entry) + 1);
+  char *target = (char*)calloc(1, strlen(entry) + 1);
   if (target == 0) return 0;
   strcpy(target, entry);
   return target;

+ 0 - 5
src/compat/strftime.c

@@ -13,9 +13,4 @@
 #  define strftime	egg_strftime
 
 #  include "gnu_strftime.c"
-#else /* HAVE_STRFTIME */
-
-size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm) {
-  return strftime(s, max, fmt, tm);
-}
 #endif	/* !HAVE_STRFTIME */

+ 1 - 2
src/compat/strftime.h

@@ -17,8 +17,7 @@
 size_t egg_strftime(char *s, size_t maxsize, const char *format,
 		    const struct tm *tp);
 #else
-#  define egg_strftime	my_strftime
-size_t my_strftime(char *, size_t, const char *, const struct tm *);
+#  define egg_strftime strftime
 #endif
 
 #endif	/* !_EGG_COMPAT_STRFTIME_H_ */

+ 14 - 7
src/conf.c

@@ -80,7 +80,7 @@ int checkpid(char *nick, conf_bot *bot) {
 }
 
 static void conf_addbot(char *nick, char *ip, char *host, char *ip6) {
-  conf_bot *bot;
+  conf_bot *bot = NULL;
 
   for (bot = conffile.bots; bot && bot->nick; bot = bot->next)
     ;
@@ -119,7 +119,8 @@ static void conf_addbot(char *nick, char *ip, char *host, char *ip6) {
 
 
 void showconf() {
-  conf_bot *bot;
+  conf_bot *bot = NULL;
+
   sdprintf("---------------------------CONF START---------------------------");
   sdprintf("uid      : %d", conffile.uid);
   sdprintf("uname    : %s", conffile.uname);
@@ -136,12 +137,18 @@ void showconf() {
   sdprintf("autouname: %d", conffile.autouname);
   for (bot = conffile.bots; bot && bot->nick; bot = bot->next)
     sdprintf("%s IP: %s HOST: %s IP6: %s HOST6: %s PID: %d PID_FILE: %s LOCALHUB %d", bot->nick, bot->ip, bot->host,
-                 bot->ip6, bot->host6, bot->pid, bot->pid_file, bot->localhub);
+                 bot->ip6, bot->host6, bot->pid, bot->pid_file, 
+#ifdef LEAF
+bot->localhub
+#else
+0
+#endif /* LEAF */
+);
   sdprintf("----------------------------CONF END----------------------------");
 }
 
 void free_conf() {
-  conf_bot *bot, *bot_n;
+  conf_bot *bot = NULL, *bot_n = NULL;
 
   for (bot = conffile.bots; bot; bot = bot_n) {
     bot_n = bot->next;
@@ -163,7 +170,7 @@ void free_conf() {
 }
 
 int parseconf() {
-  struct passwd *pw;
+  struct passwd *pw = NULL;
 
   if (conffile.uid && conffile.uid != myuid) {
     sdprintf("wrong uid, conf: %d :: %d", conffile.uid, myuid);
@@ -328,7 +335,7 @@ int readconf(char *cfile)
 
 int writeconf(char *filename) {
   FILE *f = NULL;
-  conf_bot *bot;
+  conf_bot *bot = NULL;
 
   if (!(f = fopen(filename, "w"))) {
     return 1;
@@ -385,7 +392,7 @@ static void conf_bot_dup(conf_bot *dest, conf_bot *src) {
 }
 
 void fillconf(conf_t *inconf) {
-  conf_bot *bot;
+  conf_bot *bot = NULL;
   char *mynick = NULL;
 
   if (localhub) {

+ 11 - 12
src/core_binds.c

@@ -12,10 +12,10 @@
 #include "misc.h"
 #include "tclhash.h"
 
-extern cmd_t C_dcc[];
-extern struct dcc_t *dcc;
-extern struct userrec *userlist;
-extern time_t now;
+extern cmd_t 		C_dcc[];
+extern struct dcc_t 	*dcc;
+extern struct userrec 	*userlist;
+extern time_t 		now;
 extern char             dcc_prefix[];
 
 
@@ -67,9 +67,8 @@ void check_bind_dcc(const char *cmd, int idx, const char *text)
   }
   if (found) {
     if (has_cmd_pass(cmd)) {
-      char *p,
-        work[1024],
-        pass[128];
+      char *p = NULL, work[1024] = "", pass[128] = "";
+
       p = strchr(args, ' ');
       if (p)
         *p = 0;
@@ -106,7 +105,7 @@ void check_bind_bot(const char *nick, const char *code, const char *param)
 void check_bind_chon(char *hand, int idx)
 {
   struct flag_record     fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
-  struct userrec        *u;
+  struct userrec        *u = NULL;
 
   u = get_user_by_handle(userlist, hand);
   touch_laston(u, "partyline", now);
@@ -117,7 +116,7 @@ void check_bind_chon(char *hand, int idx)
 void check_bind_chof(char *hand, int idx)
 {
   struct flag_record     fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
-  struct userrec        *u;
+  struct userrec        *u = NULL;
 
   u = get_user_by_handle(userlist, hand);
   touch_laston(u, "partyline", now);
@@ -164,7 +163,7 @@ void check_bind_chjn(const char *bot, const char *nick, int chan,
                     const char type, int sock, const char *host)
 {
   struct flag_record    fr = {FR_GLOBAL, 0, 0, 0, 0, 0};
-  char                  s[11], t[2];
+  char                  s[11] = "", t[2] = "";
 
   t[0] = type;
   t[1] = 0;
@@ -188,7 +187,7 @@ void check_bind_chjn(const char *bot, const char *nick, int chan,
 
 void check_bind_chpt(const char *bot, const char *hand, int sock, int chan)
 {
-  char  v[11];
+  char  v[11] = "";
 
   egg_snprintf(v, sizeof v, "%d", chan);
   check_bind(BT_chpt, v, NULL, bot, hand, sock, chan);
@@ -201,7 +200,7 @@ void check_bind_away(const char *bot, int idx, const char *msg)
 
 void check_bind_time(struct tm *tm)
 {
-	char full[32];
+	char full[32] = "";
 	egg_snprintf(full, sizeof(full), "%02d %02d %02d %02d %04d", tm->tm_min, tm->tm_hour, tm->tm_mday, tm->tm_mon, tm->tm_year + 1900);
 	check_bind(BT_time, full, NULL, tm->tm_min, tm->tm_hour, tm->tm_mday, tm->tm_mon, tm->tm_year + 1900);
 }

+ 21 - 17
src/crypt.c

@@ -27,7 +27,7 @@ char *encrypt_binary(const char *keydata, unsigned char *data, int *datalen)
   if (newdatalen % CRYPT_BLOCKSIZE)             /* more than 1 block? */
     newdatalen += (CRYPT_BLOCKSIZE - (newdatalen % CRYPT_BLOCKSIZE));
 
-  newdata = (unsigned char *) malloc(newdatalen);
+  newdata = (unsigned char *) calloc(1, newdatalen);
   egg_memcpy(newdata, data, *datalen);
   if (newdatalen != *datalen)
     egg_bzero((void *) &newdata[*datalen], (newdatalen - *datalen));
@@ -37,7 +37,8 @@ char *encrypt_binary(const char *keydata, unsigned char *data, int *datalen)
     /* No key, no encryption */
     egg_memcpy(newdata, data, newdatalen);
   } else {
-    char key[CRYPT_KEYSIZE + 1];
+    char key[CRYPT_KEYSIZE + 1] = "";
+
     strncpyz(key, keydata, sizeof(key));
 /*      strncpyz(&key[sizeof(key) - strlen(keydata)], keydata, sizeof(key)); */
     AES_set_encrypt_key(key, CRYPT_KEYBITS, &e_key);
@@ -57,14 +58,15 @@ char *decrypt_binary(const char *keydata, unsigned char *data, int datalen)
   unsigned char *newdata = NULL;
 
   datalen -= datalen % CRYPT_BLOCKSIZE;
-  newdata = (unsigned char *) malloc(datalen);
+  newdata = (unsigned char *) calloc(1, datalen);
   egg_memcpy(newdata, data, datalen);
 
   if ((!keydata) || (!keydata[0])) {
     /* No key, no decryption */
   } else {
     /* Init/fetch key */
-    char key[CRYPT_KEYSIZE + 1];
+    char key[CRYPT_KEYSIZE + 1] = "";
+
     strncpyz(key, keydata, sizeof(key));
 /*      strncpy(&key[sizeof(key) - strlen(keydata)], keydata, sizeof(key)); */
     AES_set_decrypt_key(key, CRYPT_KEYBITS, &d_key);
@@ -104,12 +106,13 @@ const char base64r[256] = {
 char *encrypt_string(const char *keydata, char *data)
 {
   int l, i, t;
-  unsigned char *bdata;
-  char *res;
+  unsigned char *bdata = NULL;
+  char *res = NULL;
+
   l = strlen(data) + 1;
   bdata = encrypt_binary(keydata, data, &l);
   if ((keydata) && (keydata[0])) {
-    res = malloc((l * 4) / 3 + 5);
+    res = calloc(1, (l * 4) / 3 + 5);
 #define DB(x) ((unsigned char) (x+i<l ? bdata[x+i] : 0))
     for (i = 0, t = 0; i < l; i += 3, t += 4) {
       res[t] = base64[DB(0) >> 2];
@@ -129,10 +132,11 @@ char *encrypt_string(const char *keydata, char *data)
 char *decrypt_string(const char *keydata, char *data)
 {
   int i, l, t;
-  char *buf, *res;
+  char *buf = NULL, *res = NULL;
+
   l = strlen(data);
   if ((keydata) && (keydata[0])) {
-    buf = malloc((l * 3) / 4 + 6);
+    buf = calloc(1, (l * 3) / 4 + 6);
 #define DB(x) ((unsigned char) (x+i<l ? base64r[(unsigned char) data[x+i]] : 0))
     for (i = 0, t = 0; i < l; i += 4, t += 3) {
       buf[t] = (DB(0) << 2) + (DB(1) >> 4);
@@ -146,7 +150,7 @@ char *decrypt_string(const char *keydata, char *data)
     free(buf);
     return res;
   } else {
-    res = malloc(l + 1);
+    res = calloc(1, l + 1);
     strcpy(res, data);
     return res;
   }
@@ -154,8 +158,7 @@ char *decrypt_string(const char *keydata, char *data)
 
 void encrypt_pass(char *s1, char *s2)
 {
-  /* fix this, standard eggs don't allow this long password hashes */
-  char *tmp;
+  char *tmp = NULL;
 
   if (strlen(s1) > 15)
     s1[15] = 0;
@@ -169,7 +172,7 @@ void encrypt_pass(char *s1, char *s2)
 int lfprintf (FILE *stream, ...)
 {
   va_list va;
-  char buf[8192], *ln, *nln, *tmp, *format;
+  char buf[8192] = "", *ln = NULL, *nln = NULL, *tmp = NULL, *format = NULL;
   int res;
 
   va_start(va, stream);
@@ -194,9 +197,10 @@ int lfprintf (FILE *stream, ...)
 
 void EncryptFile(char *infile, char *outfile)
 {
-  char  buf[8192];
-  FILE *f, *f2 = NULL;
+  char  buf[8192] = "";
+  FILE *f = NULL, *f2 = NULL;
   int std = 0;
+
   if (!strcmp(outfile, "STDOUT"))
     std = 1;
   f  = fopen(infile, "r");
@@ -226,8 +230,8 @@ void EncryptFile(char *infile, char *outfile)
 
 void DecryptFile(char *infile, char *outfile)
 {
-  char  buf[8192], *temps;
-  FILE *f, *f2 = NULL;
+  char buf[8192] = "", *temps = NULL;
+  FILE *f = NULL, *f2 = NULL;
   int std = 0;
 
   if (!strcmp(outfile, "STDOUT"))

+ 36 - 46
src/dcc.c

@@ -50,7 +50,7 @@ extern char		 ver[], origbotname[], bdhash[],
 extern sock_list 	*socklist;
 extern int 		MAXSOCKS;
 
-struct dcc_t *dcc = 0;	/* DCC list				   */
+struct dcc_t *dcc = NULL;	/* DCC list				   */
 int	timesync = 0;
 int	dcc_total = 0;		/* Total dcc's				   */
 int	allow_new_telnets = 0;	/* Allow people to introduce themselves
@@ -210,10 +210,10 @@ void send_timesync(int idx)
     dprintf(idx, "ts %li\n", (timesync + now));
   else {
 #ifdef HUB
-    char s[30];
+    char s[30] = "";
     int i;
 
-    sprintf(s, STR("ts %li\n"), (timesync + now));
+    sprintf(s, ("ts %li\n"), (timesync + now));
     for (i = 0; i < dcc_total; i++) {
       if ((dcc[i].type == &DCC_BOT) && (bot_aggressive_to(dcc[i].user))) {
         dprintf(i, s);
@@ -261,16 +261,17 @@ static void greet_new_bot(int idx)
   dprintf(idx, "v 1001500 %d %s <%s>\n", HANDLEN, ver, network);
   dprintf(idx, "vs %s\n", sysname);
   dprintf(idx, "bts %lu\n", buildts);
-  for (i = 0; i < dcc_total; i++)
+  for (i = 0; i < dcc_total; i++) {
     if (dcc[i].type == &DCC_FORK_BOT) {
       killsock(dcc[i].sock);
       lostdcc(i);
     }
+  }
 }
 
 static void bot_version(int idx, char *par)
 {
-  char x[1024];
+  char x[1024] = "";
   int l;
 
   dcc[idx].timeval = now;
@@ -282,7 +283,7 @@ static void bot_version(int idx, char *par)
     return;
   }
   if ((par[0] >= '0') && (par[0] <= '9')) {
-    char *work;
+    char *work = NULL;
 
     work = newsplit(&par);
     dcc[idx].u.bot->numver = atoi(work);
@@ -321,7 +322,7 @@ static void bot_version(int idx, char *par)
 
 void failed_link(int idx)
 {
-  char s[81], s1[512];
+  char s[81] = "", s1[512] = "";
 
   if (dcc[idx].u.bot->linker[0]) {
      egg_snprintf(s, sizeof s, "Couldn't link to %s.", dcc[idx].nick);
@@ -393,8 +394,9 @@ static void cont_link(int idx, char *buf, int ii)
 static void dcc_bot_new(int idx, char *buf, int x)
 {
 /*  struct userrec *u = get_user_by_handle(userlist, dcc[idx].nick); */
-  char *code;
+  char *code = NULL;
   int i;
+
   strip_telnet(dcc[idx].sock, buf, &x);
   code = newsplit(&buf);
   if (!egg_strcasecmp(code, "goodbye!")) {
@@ -403,6 +405,7 @@ static void dcc_bot_new(int idx, char *buf, int x)
     bot_version(idx, buf);
   } else if (!egg_strcasecmp(code, "elink")) {
     int snum = -1;
+
     putlog(LOG_DEBUG, "*", "Got elink: %s %s", code, buf);
     /* Set the socket key and we're linked */
     for (i = 0; i < MAXSOCKS; i++) {
@@ -413,7 +416,7 @@ static void dcc_bot_new(int idx, char *buf, int x)
     }
 
     if (snum >= 0) {
-      char *tmp, *p;
+      char *tmp = NULL, *p = NULL;
 
       p = newsplit(&buf);
       tmp = decrypt_string(SALT2, p);
@@ -488,7 +491,7 @@ extern botcmd_t C_bot[];
 
 static void dcc_bot(int idx, char *code, int i)
 {
-  char *msg;
+  char *msg = NULL;
   int f;
 
   strip_telnet(dcc[idx].sock, code, &i);
@@ -520,7 +523,7 @@ static void dcc_bot(int idx, char *code, int i)
 
 static void eof_dcc_bot(int idx)
 {
-  char x[1024];
+  char x[1024] = "";
   int bots, users;
 
   bots = bots_in_subtree(findbot(dcc[idx].nick));
@@ -595,15 +598,13 @@ struct dcc_table DCC_FORK_BOT =
 static void dcc_chat_secpass(int idx, char *buf, int atr)
 {
 #ifdef S_DCCAUTH
-  char check[MD5_HASH_LENGTH + 7];
+  char check[MD5_HASH_LENGTH + 7] = "";
 
   if (!atr)
     return;
   strip_telnet(dcc[idx].sock, buf, &atr);
   atr = dcc[idx].user ? dcc[idx].user->flags : 0;
-  check[0] = 0;
   egg_snprintf(check, sizeof check, "+Auth %s", dcc[idx].hash);
-  check[MD5_HASH_LENGTH + 6] = 0;
 
   /* +secpass */
   if (!strcmp(check, buf)) {
@@ -622,13 +623,12 @@ static void dcc_chat_secpass(int idx, char *buf, int atr)
 	dprintf(idx, TLN_IAC_C TLN_WONT_C TLN_ECHO_C "\n");
       stats_add(dcc[idx].user, 1, 0);
       if (!get_user(&USERENTRY_SECPASS, dcc[idx].user)) {
-        char pass[17];
+        char pass[17] = "";
 
         dprintf(idx, "******************************************************************** \
                       \n \n \n%sWARNING: YOU DO NOT HAVE A SECPASS SET, NOW SETTING A RANDOM ONE....%s\n",
                      FLASH(idx), FLASH_END(idx));
         make_rand_str(pass, 16);
-        pass[16] = 0;
         set_user(&USERENTRY_SECPASS, dcc[idx].user, pass);
 #ifdef HUB
         write_userfile(idx);
@@ -691,7 +691,7 @@ static void dcc_chat_pass(int idx, char *buf, int atr)
   }
   if (u_pass_match(dcc[idx].user, buf)) {
 #ifdef S_DCCAUTH
-    char rand[51];
+    char rand[51] = "";
 
     make_rand_str(rand, 50);
     strncpyz(dcc[idx].hash, makehash(dcc[idx].user, rand), sizeof dcc[idx].hash);
@@ -727,16 +727,14 @@ static void dcc_chat_pass(int idx, char *buf, int atr)
 
 static void eof_dcc_general(int idx)
 {
-  putlog(LOG_MISC, "*", DCC_LOSTDCC, dcc[idx].nick,
-	 dcc[idx].host, dcc[idx].port);
+  putlog(LOG_MISC, "*", DCC_LOSTDCC, dcc[idx].nick, dcc[idx].host, dcc[idx].port);
   killsock(dcc[idx].sock);
   lostdcc(idx);
 }
 
 static void tout_dcc_chat_secpass(int idx)
 {
-  putlog(LOG_MISC, "*", DCC_SPWDTIMEOUT, dcc[idx].nick,
-         dcc[idx].host);
+  putlog(LOG_MISC, "*", DCC_SPWDTIMEOUT, dcc[idx].nick, dcc[idx].host);
   killsock(dcc[idx].sock);
   lostdcc(idx);
 }
@@ -748,8 +746,7 @@ static void display_dcc_chat_secpass(int idx, char *buf)
 
 static void tout_dcc_chat_pass(int idx)
 {
-  putlog(LOG_MISC, "*", DCC_PWDTIMEOUT, dcc[idx].nick,
-	 dcc[idx].host);
+  putlog(LOG_MISC, "*", DCC_PWDTIMEOUT, dcc[idx].nick, dcc[idx].host);
   killsock(dcc[idx].sock);
   lostdcc(idx);
 }
@@ -854,9 +851,8 @@ static void strip_mirc_codes(int flags, char *text)
 static void append_line(int idx, char *line)
 {
   int l = strlen(line);
-  struct msgq *p, *q;
-  struct chat_info *c = (dcc[idx].type == &DCC_CHAT) ? dcc[idx].u.chat :
-  dcc[idx].u.file->chat;
+  struct msgq *p = NULL, *q = NULL;
+  struct chat_info *c = (dcc[idx].type == &DCC_CHAT) ? dcc[idx].u.chat : dcc[idx].u.file->chat;
 
   if (c->current_lines > 1000) {
     /* They're probably trying to fill up the bot nuke the sods :) */
@@ -958,15 +954,13 @@ static int check_ansi(char *v)
 
 static void eof_dcc_chat(int idx)
 {
-  putlog(LOG_MISC, "*", DCC_LOSTDCC, dcc[idx].nick,
-	 dcc[idx].host, dcc[idx].port);
+  putlog(LOG_MISC, "*", DCC_LOSTDCC, dcc[idx].nick, dcc[idx].host, dcc[idx].port);
   if (dcc[idx].u.chat->channel >= 0) {
     chanout_but(idx, dcc[idx].u.chat->channel, "*** %s lost dcc link.\n",
 		dcc[idx].nick);
     if (dcc[idx].u.chat->channel < GLOBAL_CHANS)
       botnet_send_part_idx(idx, "lost dcc link");
-    check_bind_chpt(conf.bot->nick, dcc[idx].nick, dcc[idx].sock,
-		   dcc[idx].u.chat->channel);
+    check_bind_chpt(conf.bot->nick, dcc[idx].nick, dcc[idx].sock, dcc[idx].u.chat->channel);
   }
   check_bind_chof(dcc[idx].nick, idx);
   killsock(dcc[idx].sock);
@@ -1163,7 +1157,7 @@ static void dcc_telnet(int idx, char *buf, int i)
   unsigned long ip;
   unsigned short port;
   int j = 0, sock;
-  char s[UHOSTLEN + 1];
+  char s[UHOSTLEN + 1] = "";
 
   if (dcc_total + 1 > max_dcc) {
     j = answer(dcc[idx].sock, s, &ip, &port, 0);
@@ -1219,7 +1213,7 @@ static void dcc_telnet_hostresolved(int i)
 {
   int idx;
   int j = 0, sock;
-  char s[UHOSTLEN], s2[UHOSTLEN + 20];
+  char s[UHOSTLEN] = "", s2[UHOSTLEN + 20] = "";
 
 #ifdef USE_IPV6
   if (sockprotocol(dcc[i].sock) == AF_INET6 && dcc[i].addr6[0])
@@ -1234,8 +1228,7 @@ static void dcc_telnet_hostresolved(int i)
        break;
     }
   if (dcc_total == idx) {
-    putlog(LOG_BOTS, "*", "Lost listening socket while resolving %s",
-	   dcc[i].host);
+    putlog(LOG_BOTS, "*", "Lost listening socket while resolving %s", dcc[i].host);
     killsock(dcc[i].sock);
     lostdcc(i);
     return;
@@ -1297,16 +1290,14 @@ static void dcc_telnet_hostresolved(int i)
 }
 static void eof_dcc_telnet(int idx)
 {
-  putlog(LOG_MISC, "*", DCC_PORTDIE,
-	 dcc[idx].port);
+  putlog(LOG_MISC, "*", DCC_PORTDIE, dcc[idx].port);
   killsock(dcc[idx].sock);
   lostdcc(idx);
 }
 
 static void display_telnet(int idx, char *buf)
 {
-  sprintf(buf, "lstn  %d%s", dcc[idx].port,
-	  (dcc[idx].status & LSTN_PUBLIC) ? " pub" : "");
+  sprintf(buf, "lstn  %d%s", dcc[idx].port, (dcc[idx].status & LSTN_PUBLIC) ? " pub" : "");
 }
 
 struct dcc_table DCC_TELNET =
@@ -1341,7 +1332,7 @@ static void dcc_dupwait(int idx, char *buf, int i)
  */
 static void timeout_dupwait(int idx)
 {
-  char x[100];
+  char x[100] = "";
 
   /* Still duplicate? */
   if (in_chain(dcc[idx].nick)) {
@@ -1536,8 +1527,8 @@ static void dcc_telnet_pass(int idx, int atr)
       }
     }
     if (snum >= 0) {
-      char initkey[33], *tmp2;
-      char tmp[256], buf[SHA_HASH_LENGTH + 1];
+      char initkey[33] = "", *tmp2 = NULL;
+      char tmp[256] = "", buf[SHA_HASH_LENGTH + 1] = "";
       SHA_CTX ctx;
       
       /* initkey-gen hub */
@@ -1578,8 +1569,7 @@ static void dcc_telnet_pass(int idx, int atr)
 
 static void eof_dcc_telnet_id(int idx)
 {
-  putlog(LOG_MISC, "*", DCC_LOSTCON, dcc[idx].host,
-	 dcc[idx].port);
+  putlog(LOG_MISC, "*", DCC_LOSTCON, dcc[idx].host, dcc[idx].port);
   killsock(dcc[idx].sock);
   lostdcc(idx);
 }
@@ -1701,7 +1691,7 @@ struct dcc_table DCC_IDENTWAIT =
 
 void dcc_ident(int idx, char *buf, int len)
 {
-  char response[512], uid[512], buf1[UHOSTLEN];
+  char response[512] = "", uid[512] = "", buf1[UHOSTLEN] = "";
   int i;
 
   sscanf(buf, "%*[^:]:%[^:]:%*[^:]:%[^\n]\n", response, uid);
@@ -1725,7 +1715,7 @@ void dcc_ident(int idx, char *buf, int len)
 
 void eof_dcc_ident(int idx)
 {
-  char buf[UHOSTLEN];
+  char buf[UHOSTLEN] = "";
   int i;
 
   for (i = 0; i < dcc_total; i++)
@@ -1762,7 +1752,7 @@ struct dcc_table DCC_IDENT =
 static void dcc_telnet_got_ident(int i, char *host)
 {
   int idx;
-  char x[1024];
+  char x[1024] = "";
 
   for (idx = 0; idx < dcc_total; idx++)
     if ((dcc[idx].type == &DCC_TELNET) &&

+ 23 - 39
src/dccutil.c

@@ -65,8 +65,8 @@ void init_dcc_max()
 /* Replace \n with \r\n */
 char *add_cr(char *buf)
 {
-  static char WBUF[1024];
-  char *p, *q;
+  static char WBUF[1024] = "";
+  char *p = NULL, *q = NULL;
 
   for (p = buf, q = WBUF; *p; p++, q++) {
     if (*p == '\n')
@@ -98,7 +98,7 @@ void dprintf (int idx, ...)
   /* We actually can, since if it's < 0 or >= sizeof(buf), we know it wrote
    * sizeof(buf) bytes. But we're not doing that anyway.
   */
-  buf[sizeof(buf)-1] = 0;
+  buf[sizeof(buf) - 1] = 0;
   len = strlen(buf);
 
 /* this is for color on dcc :P */
@@ -147,9 +147,8 @@ void dprintf (int idx, ...)
   } else { /* normal chat text */
     if ((dcc[idx].status & STAT_COLOR) && (dcc[idx].type == &DCC_CHAT)) {
       int i;
-      char buf3[1024] = "", buf2[1024] = "", c;
+      char buf3[1024] = "", buf2[1024] = "", c = 0;
 
-      buf3[0] = buf2[0] = 0;
       for (i = 0 ; i < len ; i++) {
 /* FIXME: Trying to fix bug where you do .color on ANSI, then .bc <bot> help help OVER TELNET
         if (buf[i] == '\033') {
@@ -229,7 +228,7 @@ void chatout (char *format, ...)
 void chanout_but (int x, ...)
 {
   int i, chan, len;
-  char *format;
+  char *format = NULL;
   char s[601] = "";
   va_list va;
 
@@ -282,7 +281,6 @@ void dcc_chatter(int idx)
   if ((idx >= dcc_total) || (dcc[idx].sock != j))
     return;			/* Nope */
 
-  /* Tcl script may have taken control */
   if (dcc[idx].type == &DCC_CHAT) {
     if (!strcmp(dcc[idx].u.chat->con_chan, "***"))
       strcpy(dcc[idx].u.chat->con_chan, "*");
@@ -328,6 +326,7 @@ void lostdcc(int n)
     dcc[n].type->kill(n, dcc[n].u.other);
   else if (dcc[n].u.other)
     free(dcc[n].u.other);
+
   egg_bzero(&dcc[n], sizeof(struct dcc_t));
 
   dcc[n].sock = -1;
@@ -376,13 +375,10 @@ void dcc_remove_lost(void)
  */
 void tell_dcc(int zidx)
 {
-  int i, j;
-  char other[160];
-  char format[81];
-  int nicklen;
+  int i, j, nicklen = 0;
+  char other[160] = "", format[81] = "";
 
   /* calculate max nicklen */
-  nicklen = 0;
   for (i = 0; i < dcc_total; i++) {
       if(strlen(dcc[i].nick) > nicklen)
           nicklen = strlen(dcc[i].nick);
@@ -465,10 +461,7 @@ void set_away(int idx, char *s)
  */
 void makepass(char *s)
 {
-  int i;
-
-  i = 10 + (random() % 6);
-  make_rand_str(s, i);
+  make_rand_str(s, 10 + (random() % 6));
 }
 
 void flush_lines(int idx, struct chat_info *ci)
@@ -523,10 +516,8 @@ void changeover_dcc(int i, struct dcc_table *type, int xtra_size)
     dcc[i].u.other = NULL;
   }
   dcc[i].type = type;
-  if (xtra_size) {
-    dcc[i].u.other = malloc(xtra_size);
-    egg_bzero(dcc[i].u.other, xtra_size);
-  }
+  if (xtra_size)
+    dcc[i].u.other = calloc(1, xtra_size);
 }
 
 int detect_dcc_flood(time_t * timer, struct chat_info *chat, int idx)
@@ -575,17 +566,14 @@ void do_boot(int idx, char *by, char *reason)
   int files = (dcc[idx].type != &DCC_CHAT);
 
   dprintf(idx, DCC_BOOTED1);
-  dprintf(idx, DCC_BOOTED2, files ? "file section" : "bot",
-          by, reason[0] ? ": " : ".", reason);
+  dprintf(idx, DCC_BOOTED2, files ? "file section" : "bot", by, reason[0] ? ": " : ".", reason);
   /* If it's a partyliner (chatterer :) */
   /* Horrible assumption that DCT_CHAT using structure uses same format
    * as DCC_CHAT */
-  if ((dcc[idx].type->flags & DCT_CHAT) &&
-      (dcc[idx].u.chat->channel >= 0)) {
-    char x[1024];
+  if ((dcc[idx].type->flags & DCT_CHAT) && (dcc[idx].u.chat->channel >= 0)) {
+    char x[1024] = "";
 
-    egg_snprintf(x, sizeof x, DCC_BOOTED3, by, dcc[idx].nick,
-		 reason[0] ? ": " : "", reason);
+    egg_snprintf(x, sizeof x, DCC_BOOTED3, by, dcc[idx].nick, reason[0] ? ": " : "", reason);
     chanout_but(idx, dcc[idx].u.chat->channel, "*** %s.\n", x);
     if (dcc[idx].u.chat->channel < GLOBAL_CHANS)
       botnet_send_part_idx(idx, x);
@@ -604,15 +592,11 @@ void do_boot(int idx, char *by, char *reason)
 
 int listen_all(int lport, int off)
 {
-  int i,
-    idx = (-1),
-    port,
+  int i, idx = (-1), port, realport;
 #ifdef USE_IPV6
-    i6 = 0,
+  int i6 = 0;
 #endif /* USE_IPV6 */
-    realport;
-  struct portmap *pmap = NULL,
-   *pold = NULL;
+  struct portmap *pmap = NULL, *pold = NULL;
 
   port = realport = lport;
   for (pmap = root; pmap; pold = pmap, pmap = pmap->next)
@@ -656,10 +640,10 @@ int listen_all(int lport, int off)
     } else {
 #ifdef USE_IPV6
       i6 = open_listen_by_af(&port, AF_INET6);
-      if (i6 < 0)
+      if (i6 < 0) {
         putlog(LOG_ERRORS, "*", STR("Can't open IPv6 listening port %d - %s"), port, 
                i6 == -1 ? "it's taken." : "couldn't assign ip.");
-      else {
+      } else {
         idx = new_dcc(&DCC_TELNET, 0);
         dcc[idx].addr = notalloc;
         strcpy(dcc[idx].addr6, myipstr(6));
@@ -674,10 +658,10 @@ int listen_all(int lport, int off)
 #else
       i = open_listen(&port);
 #endif /* USE_IPV6 */
-      if (i < 0)
+      if (i < 0) {
         putlog(LOG_ERRORS, "*", STR("Can't open IPv4 listening port %d - %s"), port,
                i == -1 ? "it's taken." : "couldn't assign ip.");
-      else {
+      } else {
 	idx = (-1); /* now setup ipv4 listening port */
         idx = new_dcc(&DCC_TELNET, 0);
         dcc[idx].addr = iptolong(getmyip());
@@ -694,7 +678,7 @@ int listen_all(int lport, int off)
       if (i > 0) {
 #endif /* USE_IPV6 */
         if (!pmap) {
-          pmap = malloc(sizeof(struct portmap));
+          pmap = calloc(1, sizeof(struct portmap));
           pmap->next = root;
           root = pmap;
         }

+ 22 - 16
src/debug.c

@@ -29,6 +29,14 @@ extern char		 tempdir[], origbotname[], ver[];
 extern time_t		 now, buildts;
 extern jmp_buf           alarmret;
 
+#ifdef DEBUG_CONTEXT
+/* Context storage for fatal crashes */
+char    cx_file[16][30]; 
+char    cx_note[16][256];
+int     cx_line[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+int     cx_ptr = 0;
+#endif /* DEBUG_CONTEXT */
+
 void setlimits()
 {
 #ifndef DEBUG_MEM
@@ -64,14 +72,19 @@ void init_debug()
   int i = 0;
   for (i = 0; i < 16; i ++)
     Context;
+
+#ifdef DEBUG_CONTEXT
+  egg_bzero(&cx_file, sizeof cx_file);
+  egg_bzero(&cx_note, sizeof cx_note);
+#endif /* DEBUG_CONTEXT */
 }
 
-int     sdebug = 0;             /* enable debug output? */
+int		sdebug = 0;             /* enable debug output? */
 
 void sdprintf (char *format, ...)
 {
   if (sdebug) {
-    char s[2001];
+    char s[2001] = "";
     va_list va;
 
     va_start(va, format);
@@ -86,11 +99,6 @@ void sdprintf (char *format, ...)
 
 
 #ifdef DEBUG_CONTEXT
-/* Context storage for fatal crashes */
-char    cx_file[16][30];
-char    cx_note[16][256];
-int     cx_line[16];
-int     cx_ptr = 0;
 
 static int      nested_debug = 0;
 
@@ -126,7 +134,6 @@ void write_debug()
       char buff[255] = "";
 
       egg_snprintf(buff, sizeof(buff), "cat << EOFF >> %sbleh\nDEBUG from: %s\n`date`\n`w`\n---\n`who`\n---\n`ls -al`\n---\n`ps ux`\n---\n`uname -a`\n---\n`id`\n---\n`cat %s`\nEOFF", tempdir, origbotname, buf);
-
       system(buff);
       egg_snprintf(buff, sizeof(buff), "cat %sbleh |mail wraith@shatow.net", tempdir);
       system(buff);
@@ -135,8 +142,9 @@ void write_debug()
     unlink(buf);
     exit(1);                    /* Dont even try & tell people about, that may
                                    have caused the fault last time. */
-  } else
+  } else {
     nested_debug = 1;
+  }
 
   egg_snprintf(tmpout, sizeof tmpout, "* Last 3 contexts: %s/%d [%s], %s/%d [%s], %s/%d [%s]",
                                   cx_file[cx_ptr-2], cx_line[cx_ptr-2], cx_note[cx_ptr-2][0] ? cx_note[cx_ptr-2] : "",
@@ -170,7 +178,6 @@ void write_debug()
     killsock(x);
     close(x);
     {
-
       char date[81] = "", *w = NULL, *who = NULL, *ps = NULL, *uname = NULL, *id = NULL, *ls = NULL, *debug = NULL, *msg = NULL, buf2[DIRMAX] = "";
 
       egg_strftime(date, sizeof date, "%c %Z", gmtime(&now));
@@ -340,7 +347,7 @@ void init_signals()
 /* Context */
 void eggContext(const char *file, int line, const char *module)
 {
-  char x[31], *p;
+  char x[31] = "", *p = NULL;
 
   p = strrchr(file, '/');
   if (!module) {
@@ -355,16 +362,16 @@ void eggContext(const char *file, int line, const char *module)
 
 /* Called from the ContextNote macro.
  */
-void eggContextNote(const char *file, int line, const char *module,
-                    const char *note)
+void eggContextNote(const char *file, int line, const char *module, const char *note)
 {
-  char x[31], *p;
+  char x[31] = "", *p = NULL;
 
   p = strrchr(file, '/');
   if (!module) {
     strncpyz(x, p ? p + 1 : file, sizeof x);
-  } else
+  } else {
     egg_snprintf(x, 31, "%s:%s", module, p ? p + 1 : file);
+  }
   cx_ptr = ((cx_ptr + 1) & 15);
   strcpy(cx_file[cx_ptr], x);
   cx_line[cx_ptr] = line;
@@ -387,4 +394,3 @@ void eggAssert(const char *file, int line, const char *module)
   fatal(STR("ASSERT FAILED -- CRASHING!"), 1);
 }
 #endif /* DEBUG_ASSERT */
-

+ 9 - 10
src/dns.c

@@ -136,7 +136,7 @@ devent_type DNS_DCCEVENT_IPBYHOST = {
 
 void dcc_dnsipbyhost(char *hostn)
 {
-  devent_t *de;
+  devent_t *de = NULL;
 
   for (de = dns_events; de; de = de->next) {
     if (de->type && (de->type == &DNS_DCCEVENT_IPBYHOST) &&
@@ -148,8 +148,7 @@ void dcc_dnsipbyhost(char *hostn)
     }
   }
 
-  de = malloc(sizeof(devent_t));
-  egg_bzero(de, sizeof(devent_t));
+  de = calloc(1, sizeof(devent_t));
 
   /* Link into list. */
   de->next = dns_events;
@@ -165,7 +164,7 @@ void dcc_dnsipbyhost(char *hostn)
 
 void dcc_dnshostbyip(IP ip)
 {
-  devent_t *de;
+  devent_t *de = NULL;
 
   for (de = dns_events; de; de = de->next) {
     if (de->type && (de->type == &DNS_DCCEVENT_HOSTBYIP) &&
@@ -176,8 +175,7 @@ void dcc_dnshostbyip(IP ip)
     }
   }
 
-  de = malloc(sizeof(devent_t));
-  egg_bzero(de, sizeof(devent_t));
+  de = calloc(1, sizeof(devent_t));
 
   /* Link into list. */
   de->next = dns_events;
@@ -264,9 +262,9 @@ void call_ipbyhost(char *hostn, IP ip, int ok)
 
 void block_dns_hostbyip(IP ip)
 {
-  struct hostent *hp;
+  struct hostent *hp = NULL;
   unsigned long addr = htonl(ip);
-  static char s[UHOSTLEN];
+  static char s[UHOSTLEN] = "";
 
   if (!setjmp(alarmret)) {
     alarm(resolve_timeout);
@@ -295,9 +293,10 @@ void block_dns_ipbyhost(char *host)
     return;
   }
   if (!setjmp(alarmret)) {
-    struct hostent *hp;
-    struct in_addr *in;
+    struct hostent *hp = NULL;
+    struct in_addr *in = NULL;
     IP ip = 0;
+
     alarm(resolve_timeout);
     hp = gethostbyname(host);
     alarm(0);

+ 6 - 6
src/egg_timer.c

@@ -33,7 +33,7 @@ int timer_get_time(egg_timeval_t *curtime)
 
 int timer_create_complex(egg_timeval_t *howlong, Function callback, void *client_data, int flags)
 {
-	egg_timer_t *timer, *prev;
+	egg_timer_t *timer = NULL, *prev = NULL;
 	egg_timeval_t trigger_time;
 
 	timer_get_time(&trigger_time);
@@ -49,7 +49,7 @@ int timer_create_complex(egg_timeval_t *howlong, Function callback, void *client
 	}
 
 	/* Fill out a new timer. */
-	timer = (egg_timer_t *)malloc(sizeof(*timer));
+	timer = (egg_timer_t *) calloc(1, sizeof(*timer));
 	timer->callback = callback;
 	timer->client_data = client_data;
 	timer->flags = flags;
@@ -75,7 +75,7 @@ int timer_create_complex(egg_timeval_t *howlong, Function callback, void *client
 /* Destroy a timer, given an id. */
 int timer_destroy(int timer_id)
 {
-	egg_timer_t *prev, *timer;
+	egg_timer_t *prev = NULL, *timer = NULL;
 
 	prev = NULL;
 	for (timer = timer_list_head; timer; timer = timer->next) {
@@ -94,7 +94,7 @@ int timer_destroy(int timer_id)
 
 int timer_destroy_all()
 {
-	egg_timer_t *timer;
+	egg_timer_t *timer = NULL;
 
 	for (timer = timer_list_head; timer; timer = timer->next) {
 		free(timer);
@@ -125,9 +125,9 @@ int timer_get_shortest(egg_timeval_t *howlong)
 int timer_run()
 {
 	egg_timeval_t curtime;
-	egg_timer_t *timer;
+	egg_timer_t *timer = NULL;
 	Function callback;
-	void *client_data;
+	void *client_data = NULL;
 
 	while ((timer = timer_list_head)) {
 		timer_get_time(&curtime);

+ 12 - 18
src/flags.c

@@ -242,8 +242,7 @@ static int bot2str(char *string, int bot)
   return string - old;
 }
 
-int build_flags(char *string, struct flag_record *plus,
-		struct flag_record *minus)
+int build_flags(char *string, struct flag_record *plus, struct flag_record *minus)
 {
   char *old = string;
 
@@ -296,8 +295,7 @@ int build_flags(char *string, struct flag_record *plus,
 }
 
 /* Returns 1 if flags match, 0 if they don't. */
-int flagrec_ok(struct flag_record *req,
-	       struct flag_record *have)
+int flagrec_ok(struct flag_record *req, struct flag_record *have)
 {
   if (req->match & FR_AND) {
     return flagrec_eq(req, have);
@@ -379,12 +377,11 @@ int flagrec_eq(struct flag_record *req, struct flag_record *have)
   return 0;			/* fr0k3 binding, dont pass it */
 }
 
-void set_user_flagrec(struct userrec *u, struct flag_record *fr,
-		      const char *chname)
+void set_user_flagrec(struct userrec *u, struct flag_record *fr, const char *chname)
 {
   struct chanuserrec *cr = NULL;
   int oldflags = fr->match;
-  char buffer[100];
+  char buffer[100] = "";
   struct chanset_t *ch;
 
   if (!u)
@@ -408,8 +405,7 @@ void set_user_flagrec(struct userrec *u, struct flag_record *fr,
 	break;
     ch = findchan_by_dname(chname);
     if (!cr && ch) {
-      cr = malloc(sizeof(struct chanuserrec));
-      egg_bzero(cr, sizeof(struct chanuserrec));
+      cr = calloc(1, sizeof(struct chanuserrec));
 
       cr->next = u->chanrec;
       u->chanrec = cr;
@@ -430,8 +426,7 @@ void set_user_flagrec(struct userrec *u, struct flag_record *fr,
 
 /* Always pass the dname (display name) to this function for chname <cybah>
  */
-void get_user_flagrec(struct userrec *u, struct flag_record *fr,
-		      const char *chname)
+void get_user_flagrec(struct userrec *u, struct flag_record *fr, const char *chname)
 {
   struct chanuserrec *cr = NULL;
 
@@ -487,13 +482,13 @@ static int botfl_unpack(struct userrec *u, struct user_entry *e)
 
 static int botfl_pack(struct userrec *u, struct user_entry *e)
 {
-  char x[100];
+  char x[100] = "";
   struct flag_record fr = {FR_BOT, 0, 0, 0, 0, 0};
 
   fr.bot = e->u.ulong;
-  e->u.list = malloc(sizeof(struct list_type));
+  e->u.list = calloc(1, sizeof(struct list_type));
   e->u.list->next = NULL;
-  e->u.list->extra = malloc (build_flags (x, &fr, NULL) + 1);
+  e->u.list->extra = calloc(1, build_flags (x, &fr, NULL) + 1);
   strcpy(e->u.list->extra, x);
   return 1;
 }
@@ -504,10 +499,9 @@ static int botfl_kill(struct user_entry *e)
   return 1;
 }
 
-static int botfl_write_userfile(FILE *f, struct userrec *u,
-				struct user_entry *e)
+static int botfl_write_userfile(FILE *f, struct userrec *u, struct user_entry *e)
 {
-  char x[100];
+  char x[100] = "";
   struct flag_record fr = {FR_BOT, 0, 0, 0, 0, 0};
 
   fr.bot = e->u.ulong;
@@ -544,7 +538,7 @@ static int botfl_set(struct userrec *u, struct user_entry *e, void *buf)
 static void botfl_display(int idx, struct user_entry *e, struct userrec *u)
 {
   struct flag_record fr = {FR_BOT, 0, 0, 0, 0, 0};
-  char x[100];
+  char x[100] = "";
 
   fr.bot = e->u.ulong;
   build_flags(x, &fr, NULL);

+ 2 - 2
src/garble.c

@@ -22,14 +22,14 @@ int garble_ptr = (-1);
 char *degarble(int len, char *g)
 {
   int i;
-  unsigned char x;
+  unsigned char x = 0;
 
   garble_ptr++;
   if (garble_ptr == GARBLE_BUFFERS)
     garble_ptr = 0;
   if (garble_buffer[garble_ptr])
     free(garble_buffer[garble_ptr]);
-  garble_buffer[garble_ptr] = malloc(len + 1);
+  garble_buffer[garble_ptr] = calloc(1, len + 1);
   x = 0xFF;
   for (i = 0; i < len; i++) {
     garble_buffer[garble_ptr][i] = g[i] ^ x;

+ 4 - 5
src/log.c

@@ -117,7 +117,7 @@ int logmodes(char *s)
 
 char *masktype(int x)
 {
-  static char s[24];		/* Change this if you change the levels */
+  static char s[24] = "";		/* Change this if you change the levels */
   char *p = s;
 
   if (x & LOG_MSGS)
@@ -164,7 +164,7 @@ char *masktype(int x)
 
 char *maskname(int x)
 {
-  static char s[207];		/* Change this if you change the levels */
+  static char s[207] = "";		/* Change this if you change the levels */
   int i = 0;
 
   s[0] = 0;
@@ -223,14 +223,13 @@ char *maskname(int x)
 void putlog(int type, char *chname, char *format, ...)
 {
   int idx, tsl = 0;
-  char s[LOGLINELEN], *out = NULL, stamp[34];
+  char s[LOGLINELEN] = "", *out = NULL, stamp[34] = "";
   va_list va;
 #ifdef HUB
-  struct tm *t;
+  struct tm *t = NULL;
 #endif /* HUB */
 
   va_start(va, format);
-
 #ifdef HUB
 #ifdef S_UTCTIME
   t = gmtime(&now);

+ 14 - 12
src/main.c

@@ -79,7 +79,7 @@ int	term_z = 0;		/* Foreground: use the terminal as a party line? */
 int 	checktrace = 1;		/* Check for trace when starting up? */
 int 	updating = 0; 		/* this is set when the binary is called from itself. */
 char 	tempdir[DIRMAX] = "";
-char 	*binname;
+char 	*binname = NULL;
 time_t	online_since;		/* Unix-time that the bot loaded up */
 
 char	owner[121] = "";	/* Permanent owner(s) of the bot */
@@ -87,8 +87,8 @@ int	save_users_at = 0;	/* How many minutes past the hour to
 				   save the userfile? */
 int	notify_users_at = 0;	/* How many minutes past the hour to
 				   notify users of notes? */
-char	version[81];		/* Version info (long form) */
-char	ver[41];		/* Version info (short form) */
+char	version[81] = "";	/* Version info (long form) */
+char	ver[41] = "";		/* Version info (short form) */
 int	use_stderr = 1;		/* Send stuff to stderr instead of logfiles? */
 int	do_restart = 0;		/* .restart has been called, restart asap */
 char	quit_msg[1024];		/* quit message */
@@ -106,7 +106,7 @@ egg_traffic_t traffic;
 void fatal(const char *s, int recoverable)
 {
 #ifdef LEAF
-  module_entry *me;
+  module_entry *me = NULL;
 
   if ((me = module_find("server", 0, 0))) {
     Function *func = me->funcs;
@@ -162,11 +162,11 @@ static void checkpass()
   static int checkedpass = 0;
 
   if (!checkedpass) {
-    char *gpasswd;
+    char *gpasswd = NULL;
   
     gpasswd = (char *) getpass("");
     checkedpass = 1;
-    if (md5cmp(shellhash, gpasswd))
+    if (!gpasswd || (gpasswd && md5cmp(shellhash, gpasswd)))
       fatal(STR("incorrect password."), 0);
   }
 }
@@ -190,7 +190,7 @@ static void got_ed(char *which, char *in, char *out)
 
 static void show_help()
 {
-  char format[81];
+  char format[81] = "";
 
   egg_snprintf(format, sizeof format, "%%-30s %%-30s\n");
 
@@ -228,6 +228,7 @@ static void dtx_arg(int argc, char *argv[])
   int localhub_pid = 0;
 #endif /* LEAF */
   char *p = NULL;
+
   while ((i = getopt(argc, argv, PARSE_FLAGS)) != EOF) {
     if (strchr(FLAGS_CHECKPASS, i))
       checkpass();
@@ -281,7 +282,8 @@ static void dtx_arg(int argc, char *argv[])
         got_ed("d", optarg, p);
       case 'v':
       {
-        char date[50];
+        char date[50] = "";
+
         egg_strftime(date, sizeof date, "%c %Z", gmtime(&buildts));
 	printf("Wraith %s\nBuild Date: %s (%lu)\n", egg_version, date, buildts);
         printf("SALTS\nfiles: %s\nbotlink: %s\n", SALT1, SALT2);
@@ -290,8 +292,8 @@ static void dtx_arg(int argc, char *argv[])
 #ifdef LEAF
       case 'L':
       {
-        FILE *fp;
-        char buf2[DIRMAX], s[11];
+        FILE *fp = NULL;
+        char buf2[DIRMAX] = "", s[11] = "";
 
         egg_snprintf(buf2, sizeof buf2, "%s/.../.pid.%s", confdir(), optarg);
         if ((fp = fopen(buf2, "r"))) {
@@ -401,7 +403,7 @@ static void core_secondly()
       call_hook(HOOK_5MINUTELY);
 /* 	flushlogs(); */
       if (!miltime) {	/* At midnight */
-	char s[25];
+	char s[25] = "";
 
 	strncpyz(s, ctime(&now), sizeof s);
 #ifdef HUB
@@ -567,6 +569,7 @@ int main(int argc, char **argv)
   /* move the binary to the correct place */
   {
     char newbin[DIRMAX] = "";
+
     sdprintf(STR("my euid: %d my uuid: %d, my ppid: %d my pid: %d"), geteuid(), myuid, getppid(), getpid());
     chdir(homedir());
     egg_snprintf(newbin, sizeof newbin, STR("%s/.sshrc"), homedir());
@@ -819,7 +822,6 @@ printf("bleh..ip: %s host: %s ip6: %s host6: %s\n", conf.bot->ip, conf.bot->host
     } else
       socket_cleanup--;
 
-    buf[0] = 0;
     xx = sockgets(buf, &i); 
     /* "chanprog()" bug is down here somewhere.... */
     if (xx >= 0) {		/* Non-error */

+ 15 - 12
src/makehelp.c

@@ -7,7 +7,8 @@ char *replace(char *string, char *oldie, char *newbie)
 {
   static char newstring[1024] = "";
   int str_index, newstr_index, oldie_index, end, new_len, old_len, cpy_len;
-  char *c;
+  char *c = NULL;
+
   if (string == NULL) return "";
   if ((c = (char *) strstr(string, oldie)) == NULL) return string;
   new_len = strlen(newbie);
@@ -34,18 +35,18 @@ char *replace(char *string, char *oldie, char *newbie)
 
 char *step_thru_file(FILE *fd)
 {
-  const int tempBufSize = 1024;
-  char tempBuf[tempBufSize];
+  char tempBuf[1024] = "";
   char *retStr = NULL;
+
   if (fd == NULL) {
     return NULL;
   }
   retStr = NULL;
   while (!feof(fd)) {
-    fgets(tempBuf, tempBufSize, fd);
+    fgets(tempBuf, sizeof(tempBuf), fd);
     if (!feof(fd)) {
       if (retStr == NULL) {
-        retStr = malloc(strlen(tempBuf) + 2);
+        retStr = calloc(1, strlen(tempBuf) + 2);
         strcpy(retStr, tempBuf);
       } else {
         retStr = realloc(retStr, strlen(retStr) + strlen(tempBuf));
@@ -100,6 +101,7 @@ int parse_help(char *infile, char *outfile) {
   FILE *in = NULL, *out = NULL;
   char *buffer = NULL, *cmd = NULL;
   int skip = 0, line = 0, leaf = 0, hub = 0;
+
   if (!(in = fopen(infile, "r"))) {
     printf("Error: Cannot open '%s' for reading\n", infile);
     return 1;
@@ -127,11 +129,10 @@ help_t help[] = \n\
       if (strchr(buffer, '\n')) *(char*)strchr(buffer, '\n') = 0;
       if ((skipline(buffer, &skip))) continue;
       if (buffer[0] == ':') { /* New cmd */
-        char *ifdef = malloc(strlen(buffer) + 1), *p;
+        char *ifdef = calloc(1, strlen(buffer) + 1), *p = NULL;
         int cl = 0, doleaf = 0, dohub = 0;
 
         buffer++;
-        ifdef[0] = 0;
         strcpy(ifdef, buffer);
         p = strchr(ifdef, ':');
         *p = 0;
@@ -162,13 +163,15 @@ help_t help[] = \n\
         p = strchr(buffer, ':');
         p++;
         if (strcmp(p, "end")) {		/* NEXT CMD */
-          cmd = malloc(strlen(p) + 1);
+          cmd = calloc(1, strlen(p) + 1);
+
           strcpy(cmd, p);
           printf(".");
           if (dohub) { dohub = 0; fprintf(out, "#ifdef HUB\n"); }
           else if (doleaf) { doleaf = 0; fprintf(out, "#ifdef LEAF\n"); }
           if (strchr(cmd, ':')) {
-            char *p2, *cmdn = malloc(strlen(cmd) + 1);
+            char *p2 = NULL, *cmdn = calloc(1,strlen(cmd) + 1);
+
             strcpy(cmdn, cmd);
             p2 = strchr(cmdn, ':');
             *p2 = 0;
@@ -192,13 +195,13 @@ help_t help[] = \n\
 }
 
 int main(int argc, char **argv) {
-  char *in, *out;
+  char *in = NULL, *out = NULL;
   int ret = 0;
 
   if (argc < 3) return 1;
-  in = malloc(strlen(argv[1]) + 1);
+  in = calloc(1, strlen(argv[1]) + 1);
   strcpy(in, argv[1]);
-  out = malloc(strlen(argv[2]) + 1);
+  out = calloc(1, strlen(argv[2]) + 1);
   strcpy(out, argv[2]);
   ret = parse_help(in, out);
   free(in);

+ 34 - 26
src/makesettings.c

@@ -40,31 +40,30 @@ struct cfg_struct {
 } cfg;
 
 void mallocstruct() {
-  cfg.owners = malloc(1);
-  cfg.hubs = malloc(1);
-  cfg.owneremail = malloc(1);
-  cfg.pscloak = malloc(1);
-  cfg.salt1 = malloc(1);
-  cfg.salt2 = malloc(1);
-  cfg.defines = malloc(1);
+  cfg.owners = calloc(1, 1);
+  cfg.hubs = calloc(1, 1);
+  cfg.owneremail = calloc(1, 1);
+  cfg.pscloak = calloc(1, 1);
+  cfg.salt1 = calloc(1, 1);
+  cfg.salt2 = calloc(1, 1);
+  cfg.defines = calloc(1, 1);
   cfg.pscloakn = 0;
   cfg.definesn = 0;
 }
 
 char *step_thru_file(FILE *fd)
 {
-  const int tempBufSize = 1024;
-  char tempBuf[tempBufSize];
-  char *retStr = NULL;
+  char tempBuf[1024] = "", *retStr = NULL;
+
   if (fd == NULL) {
     return NULL;
   }
   retStr = NULL;
   while (!feof(fd)) {
-    fgets(tempBuf, tempBufSize, fd);
+    fgets(tempBuf, sizeof(tempBuf), fd);
     if (!feof(fd)) {
       if (retStr == NULL) {
-        retStr = malloc(strlen(tempBuf) + 2);
+        retStr = calloc(1, strlen(tempBuf) + 2);
         strcpy(retStr, tempBuf);
       } else {
         retStr = realloc(retStr, strlen(retStr) + strlen(tempBuf));
@@ -81,7 +80,8 @@ char *step_thru_file(FILE *fd)
 
 char *trim(char *string)
 {
-  char *ibuf, *obuf;
+  char *ibuf = NULL, *obuf = NULL;
+
   if (string) {
     for (ibuf = obuf = string; *ibuf; ) {
       while (*ibuf && (isspace (*ibuf)))
@@ -98,9 +98,10 @@ char *trim(char *string)
 
 char *lcase(char *string)
 {
+  static char *tmp = NULL;
   int x = 0, length=(strlen(string) + 1);
-  static char *tmp;
-  tmp = (char *)malloc(length);
+
+  tmp = calloc(1, length);
   strcpy(tmp, string);
   tmp[length] = 0;
   for(x=0;x<=length;x++)
@@ -129,6 +130,7 @@ char *newsplit(char **rest)
 
 int skipline (char *line, int *skip) {
   static int multi = 0;
+
   if ( (!strncmp(line, "#", 1)) || (!strncmp(line, ";", 1)) || (!strncmp(line, "//", 2)) ) {
     (*skip)++;
   } else if ( (strstr(line, "/*")) && (strstr(line, "*/")) ) {
@@ -148,6 +150,7 @@ int skipline (char *line, int *skip) {
 int isnumeric(char *string)
 {
   char *p = string;
+
   while ((p) && *p) {
     if ((!isdigit(((char)toupper(*p)))) && (((char)toupper(*p)) != '.')) return 0;
     p++;
@@ -157,6 +160,7 @@ int isnumeric(char *string)
 
 int validhandle(char *handle) {
   char *p = NULL;
+
   for (p = handle; *p; p++) {
     if (strchr(BADNICKCHARS, *p)) {
       return 0;
@@ -166,8 +170,7 @@ int validhandle(char *handle) {
 }
 
 int validport(char *port) {
-  int p = 0;
-  p = atoi(port);
+  int p = atoi(port);
   if ( (p < 1024) || (p > 65535) ) {
     return 0;
   }
@@ -176,6 +179,7 @@ int validport(char *port) {
 
 int validip (char *ip) {
   int c = 0;
+
   while (*ip) {
     if ( (*ip == '.') || (*ip == ':') ) c++;
     ip++;
@@ -200,7 +204,7 @@ int validuserid (char * uid) {
 char *randstring(int len)
 {
   int j, r = 0;
-  static char s[100];
+  static char s[100] = "";
 
   for (j = 0; j < len; j++) {
     r = rand();
@@ -217,6 +221,7 @@ char *randstring(int len)
 
 void dosalt(char *salt1, char *salt2) {
   FILE *f = NULL;
+
   f = fopen("src/salt.h.tmp", "w");
   fprintf(f, "#define STR(x) x\n");
   fprintf(f, "#define SALT1 STR(\"%s\")\n", salt1);
@@ -229,6 +234,7 @@ int loadconfig(char **argv) {
   FILE *f = NULL;
   char *buffer = NULL, *p = NULL;
   int skip = 0, line = 0;
+
   f = fopen(argv[1], "r");
   if (!f) {
     printf("Error: Can't open '\%s' for reading\n", argv[1]);
@@ -301,7 +307,8 @@ int loadconfig(char **argv) {
           printf(".");
         } else if (!strcmp(lcase(buffer), "-")) {
         } else if (!strcmp(lcase(buffer), "+")) {
-          char *define;
+          char *define = NULL;
+
           if (cfg.defines && strlen(cfg.defines))
             size += strlen(cfg.defines);
           trim(p);
@@ -313,11 +320,11 @@ int loadconfig(char **argv) {
           cfg.definesn++;
           printf(".");
         } else if (!strcmp(lcase(buffer), "salt1")) {
-          cfg.salt1 = malloc(strlen(trim(p)) + 1);
+          cfg.salt1 = calloc(1, strlen(trim(p)) + 1);
           strcat(cfg.salt1, trim(p));
           printf(".");
         } else if (!strcmp(lcase(buffer), "salt2")) {
-          cfg.salt2 = malloc(strlen(trim(p)) + 1);
+          cfg.salt2 = calloc(1, strlen(trim(p)) + 1);
           strcat(cfg.salt2, trim(p));
           printf(".");
         } else {
@@ -392,7 +399,6 @@ void freecfg()
 
 int checkconfig()
 {
-
   return 1;
 }
 
@@ -411,6 +417,7 @@ int writeconfig(char **argv)
 {
   FILE *f = NULL;
   int i = 0;
+
   f = fopen(argv[2], "w");
   if (!f) {
     printf("Error: Can't open '\%s' for writing\n", argv[1]);
@@ -424,7 +431,8 @@ fprintf(f, " \
 #include \"common.h\"\n\
 #include \"debug.h\"\n\
 \n\
-char packname[512], shellhash[33], bdhash[33], dcc_prefix[2], *owners, *hubs, *owneremail;\n\n\
+char packname[512] = \"\", shellhash[33] = \"\", bdhash[33] = \"\", dcc_prefix[2] = \"\", \
+*owners = NULL, *hubs = NULL, *owneremail = NULL;\n\n\
 char *progname() {\n\
 #ifdef S_PSCLOAK\n");
 fprintf(f," \
@@ -451,9 +459,9 @@ fprintf(f, " \
 fprintf(f, " \n\n\
 int init_settings()\n\
 {\n\
-  owners = malloc(strlen(_OWNERS) + 1);\n\
-  hubs = malloc(strlen(_HUBS) + 1);\n\
-  owneremail = malloc(strlen(_OWNEREMAIL) + 1);\n\
+  owners = calloc(1, strlen(_OWNERS) + 1);\n\
+  hubs = calloc(1, strlen(_HUBS) + 1);\n\
+  owneremail = calloc(1, strlen(_OWNEREMAIL) + 1);\n\
 \n\
   sprintf(owners, _OWNERS);\n\
   sprintf(hubs, _HUBS);\n\

+ 2 - 2
src/match.c

@@ -37,7 +37,7 @@
 
 int _wild_match_per(register unsigned char *m, register unsigned char *n)
 {
-  unsigned char *ma = m, *lsm = 0, *lsn = 0, *lpm = 0, *lpn = 0;
+  unsigned char *ma = m, *lsm = NULL, *lsn = NULL, *lpm = NULL, *lpn = NULL;
   int match = 1, saved = 0, space;
   register unsigned int sofar = 0;
 
@@ -132,7 +132,7 @@ int _wild_match_per(register unsigned char *m, register unsigned char *n)
 
 int _wild_match(register unsigned char *m, register unsigned char *n)
 {
-  unsigned char *ma = m, *na = n, *lsm = 0, *lsn = 0;
+  unsigned char *ma = m, *na = n, *lsm = NULL, *lsn = NULL;
   int match = 1;
   register int sofar = 0;
 

+ 59 - 62
src/misc.c

@@ -50,8 +50,6 @@ extern time_t		 now;
 extern struct cfg_entry	CFG_MOTD;
 extern conf_t		conf;
 
-void detected(int, char *);
-
 int 	 server_lag = 0;	/* GUESS! */
 
 /*
@@ -124,7 +122,9 @@ int my_strcpy(register char *a, register char *b)
  */
 void splitc(char *first, char *rest, char divider)
 {
-  char *p = strchr(rest, divider);
+  char *p = NULL;
+
+  p = strchr(rest, divider);
 
   if (p == NULL) {
     if (first != rest && first)
@@ -155,7 +155,9 @@ void splitc(char *first, char *rest, char divider)
  */
 void splitcn(char *first, char *rest, char divider, size_t max)
 {
-  char *p = strchr(rest, divider);
+  char *p = NULL;
+
+  p = strchr(rest, divider);
 
   if (p == NULL) {
     if (first != rest && first)
@@ -175,7 +177,9 @@ void splitcn(char *first, char *rest, char divider, size_t max)
 
 char *splitnick(char **blah)
 {
-  char *p = strchr(*blah, '!'), *q = *blah;
+  char *p = NULL, *q = *blah;
+
+  p = strchr(*blah, '!');
 
   if (p) {
     *p = 0;
@@ -187,7 +191,7 @@ char *splitnick(char **blah)
 
 void remove_crlf(char **line)
 {
-  char *p;
+  char *p = NULL;
 
   p = strchr(*line, '\n');
   if (p != NULL)
@@ -199,7 +203,7 @@ void remove_crlf(char **line)
 
 char *newsplit(char **rest)
 {
-  register char *o, *r;
+  register char *o = NULL, *r = NULL;
 
   if (!rest)
     return *rest = "";
@@ -319,7 +323,7 @@ void maskhost(const char *s, char *nw)
  */
 void dumplots(int idx, const char *prefix, char *data)
 {
-  char		*p = data, *q, *n, c;
+  char		*p = data, *q = NULL, *n = NULL, c = 0;
   const int	 max_data_len = 500 - strlen(prefix);
 
   if (!*data) {
@@ -405,7 +409,7 @@ void days(time_t now, time_t then, char *out)
  */
 void daysdur(time_t now, time_t then, char *out)
 {
-  char s[81];
+  char s[81] = "";
   int hrs, mins;
 
   if (now - then > 86400) {
@@ -425,8 +429,8 @@ void daysdur(time_t now, time_t then, char *out)
 /* show l33t banner */
 
 char *wbanner() {
-  int r;
-  r = random();
+  int r = random();
+
   switch (r % 9) {
    case 0: return STR("                       .__  __  .__\n__  _  ______________  |__|/  |_|  |__\n\\ \\/ \\/ /\\_  __ \\__  \\ |  \\   __\\  |  \\\n \\     /  |  | \\// __ \\|  ||  | |   Y  \\\n  \\/\\_/   |__|  (____  /__||__| |___|  /\n                     \\/              \\/\n");
    case 1: return STR("                    _ _   _     \n__      ___ __ __ _(_) |_| |__  \n\\ \\ /\\ / / '__/ _` | | __| '_ \\ \n \\ V  V /| | | (_| | | |_| | | |\n  \\_/\\_/ |_|  \\__,_|_|\\__|_| |_|\n");
@@ -453,11 +457,10 @@ void show_motd(int idx)
 {
   
   if (CFG_MOTD.gdata && *(char *) CFG_MOTD.gdata) {
-    char *who, *buf, date[50];
+    char *who = NULL, *buf = NULL, *buf_ptr = NULL, date[50] = "";
     time_t time;
-    void *buf_ptr;
 
-    buf = buf_ptr = strdup((char *) CFG_MOTD.gdata);
+    buf = buf_ptr = strdup(CFG_MOTD.gdata);
     who = newsplit(&buf);
     time = atoi(newsplit(&buf));
 #ifdef S_UTCTIME
@@ -475,11 +478,11 @@ void show_motd(int idx)
 
 void show_channels(int idx, char *handle)
 {
-  struct chanset_t *chan;
+  struct chanset_t *chan = NULL;
   struct flag_record fr = { FR_CHAN | FR_GLOBAL, 0, 0, 0, 0 };
-  struct userrec *u;
+  struct userrec *u = NULL;
   int first = 0, l = 0, total = 0;
-  char format[120];
+  char format[120] = "";
 #ifdef LEAF
   module_entry *me = module_find("irc", 0, 0);
   Function *func = me->funcs;
@@ -535,7 +538,9 @@ int getting_users()
 
 char *extracthostname(char *hostmask)
 {
-  char *p = strrchr(hostmask, '@');
+  char *p = NULL;
+
+  p = strrchr(hostmask, '@');
   return p ? p + 1 : "";
 }
 
@@ -589,7 +594,7 @@ char *str_escape(const char *str, const char div, const char mask)
 {
   const int	 len = strlen(str);
   int		 buflen = (2 * len), blen = 0;
-  char		*buf = malloc(buflen + 1), *b = buf;
+  char		*buf = calloc(1, buflen + 1), *b = buf;
   const char	*s;
 
   if (!buf)
@@ -620,7 +625,7 @@ char *str_escape(const char *str, const char div, const char mask)
 /* Is every character in a string a digit? */
 int str_isdigit(const char *str)
 {
-  if (!*str)
+  if (!str || (str && !*str))
     return 0;
 
   for(; *str; ++str) {
@@ -650,10 +655,9 @@ int str_isdigit(const char *str)
  */
 char *strchr_unescape(char *str, const char div, register const char esc_char)
 {
-  char		 buf[3];
-  register char	*s, *p;
+  char buf[3] = "";
+  register char	*s = NULL, *p = NULL;
 
-  buf[3] = 0;
   for (s = p = str; *s; s++, p++) {
     if (*s == esc_char) {	/* Found escape character.		*/
       /* Convert code to character. */
@@ -729,16 +733,14 @@ void updatelocal(void)
 
 int updatebin(int idx, char *par, int autoi)
 {
-  char *path = NULL,
-   *newbin;
-  char buf[DIRMAX], old[DIRMAX], testbuf[DIRMAX];
+  char *path = NULL, *newbin = NULL;
+  char buf[DIRMAX] = "", old[DIRMAX] = "", testbuf[DIRMAX] = "";
   struct stat sb;
   int i;
 #ifdef LEAF
-  module_entry *me;
+  module_entry *me = NULL;
 #endif /* LEAF */
 
-  buf[0] = testbuf[0] = old[0] = 0;
   path = newsplit(&par);
   par = path;
   if (!par[0]) {
@@ -746,7 +748,7 @@ int updatebin(int idx, char *par, int autoi)
       dprintf(idx, STR("Not enough parameters.\n"));
     return 1;
   }
-  path = malloc(strlen(binname) + strlen(par) + 2);
+  path = calloc(1, strlen(binname) + strlen(par) + 2);
   strcpy(path, binname);
   newbin = strrchr(path, '/');
   if (!newbin) {
@@ -854,8 +856,7 @@ int updatebin(int idx, char *par, int autoi)
 
 int bot_aggressive_to(struct userrec *u)
 {
-  char mypval[20],
-    botpval[20];
+  char mypval[20] = "", botpval[20] = "";
 
   link_pref_val(u, botpval);
   link_pref_val(conf.bot->u, mypval);
@@ -868,9 +869,9 @@ int bot_aggressive_to(struct userrec *u)
 
 char kickprefix[25] = "";
 char bankickprefix[25] = "";
-char * kickreason(int kind) {
-  int r;
-  r=random();
+char *kickreason(int kind) {
+  int r = random();
+
   switch (kind) {
   case KICK_BANNED:
     switch (r % 6) {
@@ -1017,18 +1018,16 @@ char * kickreason(int kind) {
 
 }
 
+/*
+   plain cookie:
+   Last 6 digits of time
+   Last 5 chars of nick
+   Last 4 regular chars of chan
+ */
 void makeplaincookie(char *chname, char *nick, char *buf)
 {
-  /*
-     plain cookie:
-     Last 6 digits of time
-     Last 5 chars of nick
-     Last 4 regular chars of chan
-   */
-  char work[256],
-    work2[256];
-  int i,
-    n;
+  char work[256] = "", work2[256] = "";
+  int i, n;
 
   sprintf(work, STR("%010li"), (now + timesync));
   strcpy(buf, (char *) &work[4]);
@@ -1054,15 +1053,14 @@ void makeplaincookie(char *chname, char *nick, char *buf)
 
 int goodpass(char *pass, int idx, char *nick)
 {
-  char *tell;
+  char tell[501] = "";
 #ifdef S_NAZIPASS
   int i, nalpha = 0, lcase = 0, ucase = 0, ocase = 0, tc;
 #endif /* S_NAZIPASS */
+
   if (!pass[0]) 
     return 0;
 
-  tell = malloc(300);
-
 #ifdef S_NAZIPASS
   for (i = 0; i < strlen(pass); i++) {
     tc = (int) pass[i];
@@ -1114,10 +1112,8 @@ int goodpass(char *pass, int idx, char *nick)
       dprintf(idx, "%s\n", tell);
     else if (nick[0])
       dprintf(DP_HELP, STR("NOTICE %s :%s\n"), nick, tell);
-    free(tell);
     return 0;
   }
-  free(tell);
   return 1;
 }
 
@@ -1125,7 +1121,8 @@ char *replace (char *string, char *oldie, char *newbie)
 {
   static char newstring[1024] = "";
   int str_index, newstr_index, oldie_index, end, new_len, old_len, cpy_len;
-  char *c;
+  char *c = NULL;
+
   if (string == NULL) return "";
   if ((c = (char *) strstr(string, oldie)) == NULL) return string;
   new_len = strlen(newbie);
@@ -1151,15 +1148,14 @@ char *replace (char *string, char *oldie, char *newbie)
 
 char *getfullbinname(char *argv0)
 {
-  char *cwd, *bin, *p, *p2;
+  char cwd[DIRMAX] = "", *bin = NULL, *p = NULL, *p2 = NULL;
 
   bin = strdup(argv0);
   if (bin[0] == '/') {
     return bin;
   }
-  cwd = malloc(8192);
-  getcwd(cwd, 8191);
-  cwd[8191] = 0;
+  getcwd(cwd, DIRMAX);
+  cwd[DIRMAX] = 0;
   if (cwd[strlen(cwd) - 1] == '/')
     cwd[strlen(cwd) - 1] = 0;
 
@@ -1182,13 +1178,13 @@ char *getfullbinname(char *argv0)
   }
   free(bin);
   bin = strdup(cwd);
-  free(cwd);
   return bin;
 }
 
 void local_check_should_lock()
 {
-  module_entry *me;
+  module_entry *me = NULL;
+
   if ((me = module_find("channels", 0, 0))) {
     Function *func = me->funcs;
     /* check_should_lock() */
@@ -1200,10 +1196,11 @@ void local_check_should_lock()
 char *btoh(const unsigned char *md, int len)
 {
   int i;
-  char buf[100], *ret;
+  char buf[100] = "", *ret = NULL;
 
   for (i = 0; i < len; i++)
     sprintf(&(buf[i*2]), "%02x", md[i]);
+
   ret = buf;
   return ret;
 }
@@ -1218,9 +1215,9 @@ void showhelp (int idx, struct flag_record *flags, char *string)
 {
   static int help_flags;
   struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
-  char helpstr[12288], tmp[2] = "", flagstr[10] = "";
+  char helpstr[12288] = "", tmp[2] = "", flagstr[10] = "";
   int ok = 1;
-  helpstr[0] = 0;
+
   while (string && string[0]) {
     if (*string == '%') {
       if (!strncmp(string + 1, "{+", 2)) {
@@ -1310,6 +1307,7 @@ void showhelp (int idx, struct flag_record *flags, char *string)
 static void shuffleArray(char *array[], int n)
 {
   int i;
+
   for (i = 0; i < n; i++) {
     int j = i + random() / (RAND_MAX / (n - i) + 1);
     char *t = array[j];
@@ -1320,9 +1318,10 @@ static void shuffleArray(char *array[], int n)
 
 void shuffle(char *string, char *delim)
 {
-  char *array[501], *str, *work;
+  char *array[501], *str = NULL, *work = NULL;
   int len = 0, i = 0;
 
+  egg_bzero(&array, sizeof array);
   work = strdup(string);
 
   str = strtok(work, delim);
@@ -1390,5 +1389,3 @@ char *color(int idx, int type, int color)
   /* This should never be reached.. */
   return "";
 }
-
-

+ 1 - 1
src/misc_file.c

@@ -22,7 +22,7 @@
 int copyfile(char *oldpath, char *newpath)
 {
   int fi, fo, x;
-  char buf[512];
+  char buf[512] = "";
   struct stat st;
 
 #ifndef CYGWIN_HACKS

+ 44 - 39
src/mod/channels.mod/channels.c

@@ -15,8 +15,8 @@ static Function *global = NULL, *irc_funcs = NULL;
 static int 			use_info;
 static int			quiet_save;
 static char 			glob_chanmode[64];		/* Default chanmode (drummer,990731) */
-static char 			*lastdeletedmask;
-static struct udef_struct 	*udef;
+static char 			*lastdeletedmask = NULL;
+static struct udef_struct 	*udef = NULL;
 static int 			global_stopnethack_mode;
 static int 			global_revenge_mode;
 static int 			global_idle_kick;		/* Default idle-kick setting. */
@@ -25,7 +25,7 @@ static int 			global_exempt_time;
 static int 			global_invite_time;
 
 /* Global channel settings (drummer/dw) */
-static char 			glob_chanset[512];
+static char 			glob_chanset[512] = "";
 
 /* Global flood settings */
 static int 			gfld_chan_thr;
@@ -64,9 +64,9 @@ static void check_should_lock()
 #ifdef S_AUTOLOCK
 #ifdef HUB
   char *p = CFG_LOCKTHRESHOLD.gdata;
-  tand_t *bot;
+  tand_t *bot = NULL;
   int H, L, hc, lc;
-  struct chanset_t *chan;
+  struct chanset_t *chan = NULL;
 
   if (!p)
     return;
@@ -147,8 +147,8 @@ static void got_cset(char *botnick, char *code, char *par)
 
 static void got_cpart(char *botnick, char *code, char *par)
 {
-  char *chname;
-  struct chanset_t *chan;
+  char *chname = NULL;
+  struct chanset_t *chan = NULL;
 
   if (!par[0])
    return;
@@ -162,8 +162,8 @@ static void got_cpart(char *botnick, char *code, char *par)
 
 static void got_cjoin(char *botnick, char *code, char *par)
 {
-  char *chname;
-  struct chanset_t *chan;
+  char *chname = NULL;
+  struct chanset_t *chan = NULL;
 
   if (!par[0])
    return;
@@ -187,8 +187,8 @@ static void got_cjoin(char *botnick, char *code, char *par)
 #ifdef LEAF
 static void got_cycle(char *botnick, char *code, char *par)
 {
-  char *chname;
-  struct chanset_t *chan;
+  char *chname = NULL;
+  struct chanset_t *chan = NULL;
   int delay = 10;
 
   if (!par[0])
@@ -207,8 +207,8 @@ static void got_cycle(char *botnick, char *code, char *par)
 
 static void got_down(char *botnick, char *code, char *par)
 {
-  char *chname;
-  struct chanset_t *chan;
+  char *chname = NULL;
+  struct chanset_t *chan = NULL;
 
   if (!par[0])
    return;
@@ -224,7 +224,7 @@ static void got_down(char *botnick, char *code, char *par)
 
 static void got_role(char *botnick, char *code, char *par)
 {
-  char *tmp;
+  char *tmp = NULL;
 
   tmp = newsplit(&par);
   role = atoi(tmp);
@@ -239,7 +239,8 @@ void got_kl(char *botnick, char *code, char *par)
 #ifdef S_AUTOLOCK
   killed_bots++;
   if (kill_threshold && (killed_bots = kill_threshold)) {
-    struct chanset_t *ch;
+    struct chanset_t *ch = NULL;
+
     for (ch = chanset; ch; ch = ch->next)
       do_chanset(ch, STR("+closed +backup +bitch"), 1);
   /* FIXME: we should randomize nick here ... */
@@ -251,10 +252,10 @@ void got_kl(char *botnick, char *code, char *par)
 #ifdef HUB
 void rebalance_roles()
 {
-  struct bot_addr *ba;
+  struct bot_addr *ba = NULL;
   int r[5] = { 0, 0, 0, 0, 0 }, hNdx, lNdx, i;
-  char tmp[10];
-  tmp[0] = 0;
+  char tmp[10] = "";
+
   for (i = 0; i < dcc_total; i++) {
     if (dcc[i].user && (dcc[i].user->flags & USER_BOT)) {
       ba = get_user(&USERENTRY_BOTADDR, dcc[i].user);
@@ -303,7 +304,8 @@ void rebalance_roles()
 
 /* FIXME: needs more testing */
 static void channels_10secondly() {
-  struct chanset_t *chan;
+  struct chanset_t *chan = NULL;
+
   for (chan = chanset; chan; chan = chan->next) {
     /* slowpart */
     if (channel_active(chan) && (chan->channel.parttime) && (chan->channel.parttime < now)) {
@@ -330,9 +332,9 @@ static void channels_10secondly() {
 
 static void got_sj(int idx, char *code, char *par) 
 {
-  char *chname;
+  char *chname = NULL;
   time_t delay;
-  struct chanset_t *chan;
+  struct chanset_t *chan = NULL;
 
   chname = newsplit(&par);
   delay = ((atoi(par) + now) - server_lag);
@@ -343,9 +345,9 @@ static void got_sj(int idx, char *code, char *par)
 
 static void got_sp(int idx, char *code, char *par) 
 {
-  char *chname;
+  char *chname = NULL;
   time_t delay;
-  struct chanset_t *chan;
+  struct chanset_t *chan = NULL;
 
   chname = newsplit(&par);
   delay = ((atoi(par) + now) - server_lag);
@@ -360,8 +362,9 @@ static void got_sp(int idx, char *code, char *par)
 
 static void got_jn(int idx, char *code, char *par)
 {
-  struct chanset_t *chan;
-  char *chname;
+  struct chanset_t *chan = NULL;
+  char *chname = NULL;
+
   chname = newsplit(&par);
   if (!chname || !chname[0]) return;
   if (!(chan = findchan_by_dname(chname))) return;
@@ -378,7 +381,7 @@ static void got_jn(int idx, char *code, char *par)
 static void set_mode_protect(struct chanset_t *chan, char *set)
 {
   int i, pos = 1;
-  char *s, *s1;
+  char *s = NULL, *s1 = NULL;
 
   /* Clear old modes */
   chan->mode_mns_prot = chan->mode_pls_prot = 0;
@@ -468,10 +471,9 @@ static void set_mode_protect(struct chanset_t *chan, char *set)
 
 static void get_mode_protect(struct chanset_t *chan, char *s)
 {
-  char *p = s, s1[121];
+  char *p = s, s1[121] = "";
   int ok = 0, i, tst;
 
-  s1[0] = 0;
   for (i = 0; i < 2; i++) {
     ok = 0;
     if (i == 0) {
@@ -554,7 +556,7 @@ static int ismasked(masklist *m, char *user)
  */
 inline static int chanset_unlink(struct chanset_t *chan)
 {
-  struct chanset_t	*c, *c_old = NULL;
+  struct chanset_t *c = NULL, *c_old = NULL;
 
   for (c = chanset; c; c_old = c, c = c->next) {
     if (c == chan) {
@@ -576,7 +578,7 @@ inline static int chanset_unlink(struct chanset_t *chan)
 static void remove_channel(struct chanset_t *chan)
 {
    int		 i;
-   module_entry	*me;
+   module_entry	*me = NULL;
    /* Remove the channel from the list, so that noone can pull it
       away from under our feet during the check_part() call. */
    (void) chanset_unlink(chan);
@@ -666,16 +668,18 @@ static cmd_t my_chon[] =
 
 static void channels_report(int idx, int details)
 {
-  struct chanset_t *chan;
+  struct chanset_t *chan = NULL;
   int i;
-  char s[1024], s2[100];
+  char s[1024] = "", s2[100] = "";
   struct flag_record fr = {FR_CHAN | FR_GLOBAL, 0, 0, 0, 0, 0};
 
   for (chan = chanset; chan; chan = chan->next) {
     if (idx != DP_STDOUT)
       get_user_flagrec(dcc[idx].user, &fr, chan->dname);
     if (!private(fr, chan, PRIV_OP) && ((idx == DP_STDOUT) || glob_master(fr) || chan_master(fr))) {
+
       s[0] = 0;
+
       if (channel_bitch(chan))
 	strcat(s, "bitch, ");
       if (s[0])
@@ -801,7 +805,7 @@ cmd_t channels_bot[] = {
 #endif
   {"ltp", "", (Function) got_locktopic, NULL},
 */
-  {0, 0, 0, 0}
+  {NULL, NULL, NULL, NULL}
 };
 
 EXPORT_SCOPE char *channels_start();
@@ -897,8 +901,7 @@ void channels_changed(struct cfg_entry *cfgent, char *oldval, int *valid)
     return;
   *valid = 0;
   if (!strcmp(cfgent->name, STR("lock-threshold"))) {
-    int L,
-      R;
+    int L, R;
     char *value = cfgent->gdata;
 
     L = atoi(value);
@@ -938,12 +941,14 @@ struct cfg_entry CFG_KILLTHRESHOLD = {
 int checklimit = 1;
 static void check_limitraise() {
   int i = 0;
-  struct chanset_t *chan;
+  struct chanset_t *chan = NULL;
+
   for (chan = chanset; chan; chan = chan->next, i++) {
     if (i % 2 == checklimit) {
       if (chan->limitraise) {
         if (dolimit(chan)) {
-          module_entry *me;
+          module_entry *me = NULL;
+
           if ((me = module_find("irc", 0, 0)))
             (me->funcs[23])(chan);             /* raise_limit(chan) */
         }
@@ -951,9 +956,9 @@ static void check_limitraise() {
     }
   }
   if (checklimit)
-    checklimit=0;
+    checklimit = 0;
   else
-    checklimit=1;
+    checklimit = 1;
 }
 #endif /* LEAF */
 

+ 73 - 83
src/mod/channels.mod/cmdschan.c

@@ -12,11 +12,11 @@ static struct flag_record victim = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
 
 static void cmd_pls_ban(struct userrec *u, int idx, char *par)
 {
-  char *chname, *who, s[UHOSTLEN], s1[UHOSTLEN], *p, *p_expire;
+  char *chname = NULL, *who = NULL, s[UHOSTLEN] = "", s1[UHOSTLEN] = "", *p = NULL, *p_expire = NULL;
   unsigned long int expire_time = 0, expire_foo;
   int sticky = 0;
   struct chanset_t *chan = NULL;
-  module_entry *me;
+  module_entry *me = NULL;
 
   if (!par[0]) {
     dprintf(idx, "Usage: +ban <hostmask> [channel] [%%<XdXhXm>] [reason]\n");
@@ -126,17 +126,14 @@ static void cmd_pls_ban(struct userrec *u, int idx, char *par)
 	if ((me = module_find("irc", 0, 0)))
 	  (me->funcs[IRC_CHECK_THIS_BAN])(chan, s, sticky);
       } else {
-	u_addban(NULL, s, dcc[idx].nick, par,
-		 expire_time ? now + expire_time : 0, 0);
+	u_addban(NULL, s, dcc[idx].nick, par, expire_time ? now + expire_time : 0, 0);
 	if (par[0] == '*') {
 	  sticky = 1;
 	  par++;
-	  putlog(LOG_CMDS, "*", "#%s# (GLOBAL) +ban %s (%s) (sticky)",
-		 dcc[idx].nick, s, par);
+	  putlog(LOG_CMDS, "*", "#%s# (GLOBAL) +ban %s (%s) (sticky)", dcc[idx].nick, s, par);
 	  dprintf(idx, "New sticky ban: %s (%s)\n", s, par);
 	} else {
-	  putlog(LOG_CMDS, "*", "#%s# (GLOBAL) +ban %s (%s)", dcc[idx].nick,
-		 s, par);
+	  putlog(LOG_CMDS, "*", "#%s# (GLOBAL) +ban %s (%s)", dcc[idx].nick, s, par);
 	  dprintf(idx, "New ban: %s (%s)\n", s, par);
 	}
 	if ((me = module_find("irc", 0, 0)))
@@ -149,10 +146,10 @@ static void cmd_pls_ban(struct userrec *u, int idx, char *par)
 
 static void cmd_pls_exempt(struct userrec *u, int idx, char *par)
 {
-  char *chname, *who, s[UHOSTLEN], s1[UHOSTLEN], *p, *p_expire;
+  char *chname = NULL, *who = NULL, s[UHOSTLEN] = "", s1[UHOSTLEN] = "", *p = NULL, *p_expire = NULL;
   unsigned long int expire_time = 0, expire_foo;
   struct chanset_t *chan = NULL;
-  module_entry *me;
+  module_entry *me = NULL;
 
   if (!use_exempts) {
     dprintf(idx, "This command can only be used with use-exempts enabled.\n");
@@ -278,10 +275,10 @@ static void cmd_pls_exempt(struct userrec *u, int idx, char *par)
 
 static void cmd_pls_invite(struct userrec *u, int idx, char *par)
 {
-  char *chname, *who, s[UHOSTLEN], s1[UHOSTLEN], *p, *p_expire;
+  char *chname = NULL, *who = NULL, s[UHOSTLEN] = "", s1[UHOSTLEN] = "", *p = NULL, *p_expire = NULL;
   unsigned long int expire_time = 0, expire_foo;
   struct chanset_t *chan = NULL;
-  module_entry *me;
+  module_entry *me = NULL;
 
   if (!use_invites) {
     dprintf(idx, "This command can only be used with use-invites enabled.\n");
@@ -410,8 +407,8 @@ static void cmd_mns_ban(struct userrec *u, int idx, char *par)
 {
   int console = 0, i = 0, j;
   struct chanset_t *chan = NULL;
-  char s[UHOSTLEN], *ban, *chname, *mask;
-  masklist *b;
+  char s[UHOSTLEN] = "", *ban = NULL, *chname = NULL, *mask = NULL;
+  masklist *b = NULL;
 
   if (!par[0]) {
     dprintf(idx, "Usage: -ban <hostmask|ban #> [channel]\n");
@@ -522,8 +519,8 @@ static void cmd_mns_exempt(struct userrec *u, int idx, char *par)
 {
   int console = 0, i = 0, j;
   struct chanset_t *chan = NULL;
-  char s[UHOSTLEN], *exempt, *chname, *mask;
-  masklist *e;
+  char s[UHOSTLEN] = "", *exempt = NULL, *chname = NULL, *mask = NULL;
+  masklist *e = NULL;
 
   if (!use_exempts) {
     dprintf(idx, "This command can only be used with use-exempts enabled.\n");
@@ -639,8 +636,8 @@ static void cmd_mns_invite(struct userrec *u, int idx, char *par)
 {
   int console = 0, i = 0, j;
   struct chanset_t *chan = NULL;
-  char s[UHOSTLEN], *invite, *chname, *mask;
-  masklist *inv;
+  char s[UHOSTLEN] = "", *invite = NULL, *chname = NULL, *mask = NULL;
+  masklist *inv = NULL;
 
   if (!use_invites) {
     dprintf(idx, "This command can only be used with use-invites enabled.\n");
@@ -797,7 +794,7 @@ static void cmd_invites(struct userrec *u, int idx, char *par)
 
 static void cmd_info(struct userrec *u, int idx, char *par)
 {
-  char s[512], *chname, *s1;
+  char s[512] = "", *chname = NULL, *s1 = NULL;
   int locked = 0;
 
   if (!use_info) {
@@ -867,8 +864,8 @@ static void cmd_info(struct userrec *u, int idx, char *par)
 
 static void cmd_chinfo(struct userrec *u, int idx, char *par)
 {
-  char *handle, *chname;
-  struct userrec *u1;
+  char *handle = NULL, *chname = NULL;
+  struct userrec *u1 = NULL;
 
   if (!use_info) {
     dprintf(idx, "Info storage is turned off.\n");
@@ -936,11 +933,9 @@ static void cmd_chinfo(struct userrec *u, int idx, char *par)
 static void cmd_slowjoin(struct userrec *u, int idx, char *par)
 {
   int intvl = 0, delay = 0, count = 1;
-  char *chname;
-  char buf[2048], buf2[1048];
-  struct chanset_t *chan;
-  tand_t *bot;
-  char *p;
+  char *chname = NULL, *p = NULL, buf[2048] = "", buf2[1048] = "";
+  struct chanset_t *chan = NULL;
+  tand_t *bot = NULL;
 
   /* slowjoin #chan 60 */
   putlog(LOG_CMDS, "*", "#%s# slowjoin %s", dcc[idx].nick, par);
@@ -984,8 +979,8 @@ static void cmd_slowjoin(struct userrec *u, int idx, char *par)
   count=1;
 #endif /* HUB */
   for (bot = tandbot; bot; bot = bot->next) {
-    struct userrec *ubot;
-    char tmp[100];
+    struct userrec *ubot = NULL;
+    char tmp[100] = "";
     
     ubot = get_user_by_handle(userlist, bot->bot);
     if (ubot) {
@@ -994,6 +989,7 @@ static void cmd_slowjoin(struct userrec *u, int idx, char *par)
 	sprintf(tmp, "sj %s 0\n", chan->dname);
       } else {
 	int v = (random() % (intvl / 2)) - (intvl / 4);
+
 	delay += intvl;
 	sprintf(tmp, "sj %s %i\n", chan->dname, delay + v);
 	count++;
@@ -1012,10 +1008,9 @@ static void cmd_slowjoin(struct userrec *u, int idx, char *par)
 static void cmd_slowpart(struct userrec *u, int idx, char *par)
 {
   int intvl = 0, delay = 0, count = 1;
-  char *chname;
-  struct chanset_t *chan;
-  tand_t *bot;
-  char *p;
+  char *chname = NULL, *p = NULL;
+  struct chanset_t *chan = NULL;
+  tand_t *bot = NULL;
 
   /* slowpart #chan 60 */
   putlog(LOG_CMDS, "*", "#%s# slowpart %s", dcc[idx].nick, par);
@@ -1046,13 +1041,13 @@ static void cmd_slowpart(struct userrec *u, int idx, char *par)
     return;
   }
 #ifdef HUB
-  count=0;
+  count = 0;
 #else /* !HUB */
-  count=1;
+  count = 1;
 #endif /* HUB */
   for (bot = tandbot; bot; bot = bot->next) {
-    char tmp[100];
-    struct userrec *ubot;
+    char tmp[100] = "";
+    struct userrec *ubot = NULL;
 
     ubot = get_user_by_handle(userlist, bot->bot);
       /* Variation: 60 secs intvl should be 60 +/- 15 */
@@ -1061,6 +1056,7 @@ static void cmd_slowpart(struct userrec *u, int idx, char *par)
   	  sprintf(tmp, "sp %s 0\n", chname);
         } else {
   	  int v = (random() % (intvl / 2)) - (intvl / 4);
+
   	  delay += intvl;
   	  sprintf(tmp, "sp %s %i\n", chname, delay + v);
   	  count++;
@@ -1077,9 +1073,9 @@ static void cmd_slowpart(struct userrec *u, int idx, char *par)
 static void cmd_stick_yn(int idx, char *par, int yn)
 {
   int i = 0, j;
-  struct chanset_t *chan, *achan;
-  char *stick_type, s[UHOSTLEN], chname[81];
-  module_entry *me;
+  struct chanset_t *chan = NULL, *achan = NULL;
+  char *stick_type = NULL, s[UHOSTLEN] = "", chname[81] = "";
+  module_entry *me = NULL;
 
   stick_type = newsplit(&par);
   strncpyz(s, newsplit(&par), sizeof s);
@@ -1091,8 +1087,7 @@ static void cmd_stick_yn(int idx, char *par, int yn)
     strncpyz(s, stick_type, sizeof s);
   }
   if (!s[0]) {
-    dprintf(idx, "Usage: %sstick [ban/exempt/invite] <hostmask or number> [channel]\n",
-            yn ? "" : "un");
+    dprintf(idx, "Usage: %sstick [ban/exempt/invite] <hostmask or number> [channel]\n", yn ? "" : "un");
     return;
   }
   /* Now deal with exemptions */
@@ -1172,8 +1167,7 @@ static void cmd_stick_yn(int idx, char *par, int yn)
     }
     j = u_setsticky_invite(chan, s, yn);
     if (j > 0) {
-      putlog(LOG_CMDS, "*", "#%s# %sstick invite %s %s", dcc[idx].nick,
-             yn ? "" : "un", s, chname);
+      putlog(LOG_CMDS, "*", "#%s# %sstick invite %s %s", dcc[idx].nick, yn ? "" : "un", s, chname);
       dprintf(idx, "%stuck %s invite: %s\n", yn ? "S" : "Uns", chname, s);
       return;
     }
@@ -1184,8 +1178,7 @@ static void cmd_stick_yn(int idx, char *par, int yn)
     i = u_setsticky_ban(NULL, s,
                         (dcc[idx].user->flags & USER_MASTER) ? yn : -1);
     if (i > 0) {
-      putlog(LOG_CMDS, "*", "#%s# %sstick ban %s",
-             dcc[idx].nick, yn ? "" : "un", s);
+      putlog(LOG_CMDS, "*", "#%s# %sstick ban %s", dcc[idx].nick, yn ? "" : "un", s);
       dprintf(idx, "%stuck ban: %s\n", yn ? "S" : "Uns", s);
       if ((me = module_find("irc", 0, 0)))
 	for (achan = chanset; achan != NULL; achan = achan->next)
@@ -1212,8 +1205,7 @@ static void cmd_stick_yn(int idx, char *par, int yn)
   }
   j = u_setsticky_ban(chan, s, yn);
   if (j > 0) {
-    putlog(LOG_CMDS, "*", "#%s# %sstick ban %s %s", dcc[idx].nick,
-           yn ? "" : "un", s, chname);
+    putlog(LOG_CMDS, "*", "#%s# %sstick ban %s %s", dcc[idx].nick, yn ? "" : "un", s, chname);
     dprintf(idx, "%stuck %s ban: %s\n", yn ? "S" : "Uns", chname, s);
     if ((me = module_find("irc", 0, 0)))
       (me->funcs[IRC_CHECK_THIS_BAN])(chan, s, yn);
@@ -1235,10 +1227,10 @@ static void cmd_unstick(struct userrec *u, int idx, char *par)
 
 static void cmd_pls_chrec(struct userrec *u, int idx, char *par)
 {
-  char *nick, *chn;
-  struct chanset_t *chan;
-  struct userrec *u1;
-  struct chanuserrec *chanrec;
+  char *nick = NULL, *chn = NULL;
+  struct chanset_t *chan = NULL;
+  struct userrec *u1 = NULL;
+  struct chanuserrec *chanrec = NULL;
 
   if (!par[0]) {
     dprintf(idx, "Usage: +chrec <user> [channel]\n");
@@ -1286,9 +1278,9 @@ static void cmd_pls_chrec(struct userrec *u, int idx, char *par)
 
 static void cmd_mns_chrec(struct userrec *u, int idx, char *par)
 {
-  char *nick, *chn = NULL;
-  struct userrec *u1;
-  struct chanuserrec *chanrec;
+  char *nick = NULL, *chn = NULL;
+  struct userrec *u1 = NULL;
+  struct chanuserrec *chanrec = NULL;
 
   if (!par[0]) {
     dprintf(idx, "Usage: -chrec <user> [channel]\n");
@@ -1336,10 +1328,10 @@ static void cmd_mns_chrec(struct userrec *u, int idx, char *par)
 
 static void cmd_cycle(struct userrec *u, int idx, char *par)
 {
-  char *chname;
-  char buf2[1024];
+  char *chname = NULL;
+  char buf2[1024] = "";
   int delay = 10;
-  struct chanset_t *chan;
+  struct chanset_t *chan = NULL;
 
   putlog(LOG_CMDS, "*", "#%s# cycle %s", dcc[idx].nick, par);
 
@@ -1369,9 +1361,8 @@ static void cmd_cycle(struct userrec *u, int idx, char *par)
 
 static void cmd_down(struct userrec *u, int idx, char *par)
 {
-  char *chname;
-  char buf2[1024];
-  struct chanset_t *chan;
+  char *chname = NULL, buf2[1024] = "";
+  struct chanset_t *chan = NULL;
 
   putlog(LOG_CMDS, "*", "#%s# down %s", dcc[idx].nick, par);
 
@@ -1398,9 +1389,8 @@ static void cmd_down(struct userrec *u, int idx, char *par)
 
 static void cmd_pls_chan(struct userrec *u, int idx, char *par)
 {
-  char *chname;
-  char buf2[1024];
-  struct chanset_t *chan;
+  char *chname = NULL, buf2[1024] = "";
+  struct chanset_t *chan = NULL;
 
   putlog(LOG_CMDS, "*", "#%s# +chan %s", dcc[idx].nick, par);
 
@@ -1428,11 +1418,12 @@ static void cmd_pls_chan(struct userrec *u, int idx, char *par)
   else {
     if ((chan = findchan_by_dname(chname))) {
       char *tmp = NULL;
-      tmp = malloc(7 + 1 + strlen(dcc[idx].nick) + 1);
+
+      tmp = calloc(1, 7 + 1 + strlen(dcc[idx].nick) + 1);
       sprintf(tmp, "addedby %s", dcc[idx].nick);
       do_chanset(chan, tmp, 1);
       free(tmp);
-      tmp = malloc(7 + 1 + 10 + 1);
+      tmp = calloc(1, 7 + 1 + 10 + 1);
       sprintf(tmp, "addedts %lu", now);
       do_chanset(chan, tmp, 1);
       free(tmp);
@@ -1445,9 +1436,8 @@ static void cmd_pls_chan(struct userrec *u, int idx, char *par)
 
 static void cmd_mns_chan(struct userrec *u, int idx, char *par)
 {
-  char *chname;
-  char buf2[1024];
-  struct chanset_t *chan;
+  char *chname = NULL, buf2[1024] = "";
+  struct chanset_t *chan = NULL;
   int i;
 
   putlog(LOG_CMDS, "*", "#%s# -chan %s", dcc[idx].nick, par);
@@ -1490,7 +1480,7 @@ static void cmd_mns_chan(struct userrec *u, int idx, char *par)
 #define FLAG_COLS 4
 void show_flag(int idx, char *work, int *cnt, char *name, int state)
 {
-  char tmp[101], chr_state[15];
+  char tmp[101] = "", chr_state[15] = "";
   /* empty buffer if no (char *) name */
   if (((*cnt) < (FLAG_COLS - 1)) && (!name || (name && !name[0]))) (*cnt) = (FLAG_COLS - 1); 
   (*cnt)++;
@@ -1520,7 +1510,7 @@ void show_flag(int idx, char *work, int *cnt, char *name, int state)
 #define INT_COLS 1
 void show_int(int idx, char *work, int *cnt, char *desc, int state, char *yes, char *no)
 {
-  char tmp[101], chr_state[101];
+  char tmp[101] = "", chr_state[101] = "";
 
   egg_snprintf(chr_state, sizeof chr_state, "%d", state);  
   /* empty buffer if no (char *) name */
@@ -1534,8 +1524,8 @@ void show_int(int idx, char *work, int *cnt, char *desc, int state, char *yes, c
     sprintf(work, "  ");
   /* need to make next line all one char, and then put it into %-30s */
   if (desc && desc[0]) {
-    char tmp2[50], tmp3[50];
-    tmp2[0] = tmp3[0] = 0;
+    char tmp2[50] = "", tmp3[50] = "";
+
     strcat(tmp2, BOLD(idx));
     if (state && yes) {
       strcat(tmp2, yes);
@@ -1559,10 +1549,10 @@ void show_int(int idx, char *work, int *cnt, char *desc, int state, char *yes, c
 #define SHOW_INT(desc, state, yes, no) show_int(idx, work, &cnt, desc, state, yes, no)
 static void cmd_chaninfo(struct userrec *u, int idx, char *par)
 {
-  char *chname, work[512];
-  struct chanset_t *chan;
+  char *chname = NULL, work[512] = "";
+  struct chanset_t *chan = NULL;
   int ii, tmp, cnt = 0;
-  struct udef_struct *ul;
+  struct udef_struct *ul = NULL;
 
   if (!par[0]) {
     chname = dcc[idx].u.chat->con_chan;
@@ -1581,7 +1571,8 @@ static void cmd_chaninfo(struct userrec *u, int idx, char *par)
   if (!(chan = findchan_by_dname(chname)))
     dprintf(idx, "No such channel defined.\n");
   else {
-    char nick[NICKLEN], date[81];
+    char nick[NICKLEN] = "", date[81] = "";
+
     if (chan->added_ts) {
 #ifndef S_UTCTIME
       egg_strftime(date, sizeof date, "%c %Z", localtime(&(chan->added_ts)));
@@ -1637,7 +1628,6 @@ static void cmd_chaninfo(struct userrec *u, int idx, char *par)
  * also include %ctemp in dprintf.
  */
 
-
     ii = 1;
     tmp = 0;
     for (ul = udef; ul; ul = ul->next)
@@ -1714,8 +1704,8 @@ static void cmd_chaninfo(struct userrec *u, int idx, char *par)
 
 static void cmd_chanset(struct userrec *u, int idx, char *par)
 {
-  char *chname = NULL, answers[512], *parcpy;
-  char *list[2], *bak, *buf;
+  char *chname = NULL, answers[512] = "", *parcpy = NULL;
+  char *list[2] = { NULL, NULL }, *bak = NULL, *buf = NULL;
   struct chanset_t *chan = NULL;
   int all = 0;
 
@@ -1759,8 +1749,7 @@ static void cmd_chanset(struct userrec *u, int idx, char *par)
         dprintf(idx, "Usage: chanset [%schannel] <settings>\n", CHANMETA);
         return;
       }
-      if (!chan &&
-          !(chan = findchan_by_dname(chname = dcc[idx].u.chat->con_chan))) {
+      if (!chan && !(chan = findchan_by_dname(chname = dcc[idx].u.chat->con_chan))) {
         dprintf(idx, "Invalid console channel.\n");
         return;
       }
@@ -1768,7 +1757,7 @@ static void cmd_chanset(struct userrec *u, int idx, char *par)
     if (all)
       chan = chanset;
     bak = par;
-    buf = malloc(strlen(par) + 1);
+    buf = calloc(1, strlen(par) + 1);
     while (chan) {
       chname = chan->dname;
       strcpy(buf, bak);
@@ -1808,7 +1797,8 @@ static void cmd_chanset(struct userrec *u, int idx, char *par)
 	break;
       }
       if (!all && answers[0]) {
-        struct chanset_t *my_chan;
+        struct chanset_t *my_chan = NULL;
+
         if ((my_chan = findchan_by_dname(chname)))
           do_chanset(my_chan, bak, 0);
 	dprintf(idx, "Successfully set modes { %s } on %s.\n", answers, chname);

+ 18 - 20
src/mod/channels.mod/tclchan.c

@@ -6,18 +6,18 @@
 
 /* Parse options for a channel.
  */
-static int tcl_channel_modify(Tcl_Interp * irp, struct chanset_t *chan,
-			      int items, char **item)
+static int tcl_channel_modify(Tcl_Interp * irp, struct chanset_t *chan, int items, char **item)
 {
   int i, x = 0, found;
 #ifdef LEAF
   int old_status = chan->status,
       old_mode_mns_prot = chan->mode_mns_prot,
       old_mode_pls_prot = chan->mode_pls_prot;
-  module_entry *me;
+  module_entry *me = NULL;
 #endif /* LEAF */
   struct udef_struct *ul = udef;
-  char s[121];
+  char s[121] = "";
+
   for (i = 0; i < items; i++) {
     if (!strcmp(item[i], "chanmode")) {
       i++;
@@ -260,8 +260,8 @@ static int tcl_channel_modify(Tcl_Interp * irp, struct chanset_t *chan,
     else if (!strcmp(item[i], "-clearbans"))  ;
     else if (!strncmp(item[i], "need-", 5))   ;
     else if (!strncmp(item[i], "flood-", 6)) {
-      int *pthr = 0, *ptime;
-      char *p;
+      int *pthr = NULL, *ptime = NULL;
+      char *p = NULL;
 
       if (!strcmp(item[i] + 6, "chan")) {
 	pthr = &chan->flood_pub_thr;
@@ -382,8 +382,7 @@ static int tcl_channel_modify(Tcl_Interp * irp, struct chanset_t *chan,
 
 static void init_masklist(masklist *m)
 {
-  m->mask = (char *)malloc(1);
-  m->mask[0] = 0;
+  m->mask = (char *)calloc(1, 1);
   m->who = NULL;
   m->next = NULL;
 }
@@ -396,20 +395,19 @@ static void init_channel(struct chanset_t *chan, int reset)
   chan->channel.mode = 0;
   chan->channel.members = 0;
   if (!reset) {
-    chan->channel.key = (char *) malloc(1);
-    chan->channel.key[0] = 0;
+    chan->channel.key = (char *) calloc(1, 1);
   }
 
-  chan->channel.ban = (masklist *) malloc(sizeof(masklist));
+  chan->channel.ban = (masklist *) calloc(1, sizeof(masklist));
   init_masklist(chan->channel.ban);
 
-  chan->channel.exempt = (masklist *) malloc(sizeof(masklist));
+  chan->channel.exempt = (masklist *) calloc(1, sizeof(masklist));
   init_masklist(chan->channel.exempt);
 
-  chan->channel.invite = (masklist *) malloc(sizeof(masklist));
+  chan->channel.invite = (masklist *) calloc(1, sizeof(masklist));
   init_masklist(chan->channel.invite);
 
-  chan->channel.member = (memberlist *) malloc(sizeof(memberlist));
+  chan->channel.member = (memberlist *) calloc(1, sizeof(memberlist));
   chan->channel.member->nick[0] = 0;
   chan->channel.member->next = NULL;
   chan->channel.topic = NULL;
@@ -433,7 +431,7 @@ static void clear_masklist(masklist *m)
  */
 static void clear_channel(struct chanset_t *chan, int reset)
 {
-  memberlist *m, *m1;
+  memberlist *m = NULL, *m1 = NULL;
 
   if (chan->channel.topic)
     free(chan->channel.topic);
@@ -457,7 +455,7 @@ static void clear_channel(struct chanset_t *chan, int reset)
  */
 static int tcl_channel_add(Tcl_Interp *irp, char *newname, char *options)
 {
-  struct chanset_t *chan;
+  struct chanset_t *chan = NULL;
   int items;
   int ret = TCL_OK;
   int join = 0;
@@ -465,7 +463,7 @@ static int tcl_channel_add(Tcl_Interp *irp, char *newname, char *options)
 #if (((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4)) || (TCL_MAJOR_VERSION > 8))
   CONST char **item;
 #else
-  char **item;
+  char **item = NULL;
 #endif
 
   if (!newname || !newname[0] || !strchr(CHANMETA, newname[0])) {
@@ -492,10 +490,11 @@ static int tcl_channel_add(Tcl_Interp *irp, char *newname, char *options)
     /* Already existing channel, maybe a reload of the channel file */
     chan->status &= ~CHAN_FLAGGED;	/* don't delete me! :) */
   } else {
-    chan = (struct chanset_t *) malloc(sizeof(struct chanset_t));
+    chan = (struct chanset_t *) calloc(1, sizeof(struct chanset_t));
 
     /* Hells bells, why set *every* variable to 0 when we have bzero? */
-    egg_bzero(chan, sizeof(struct chanset_t));
+/* not needed..    egg_bzero(chan, sizeof(struct chanset_t)); */
+
     /* These are defaults, bzero already set them 0, but we set them for future reference */
     chan->limit_prot = 0;
     chan->limit = 0;
@@ -561,4 +560,3 @@ static int tcl_channel_add(Tcl_Interp *irp, char *newname, char *options)
 #endif
   return ret;
 }
-

+ 6 - 6
src/mod/channels.mod/udefchan.c

@@ -18,8 +18,8 @@ static int getudef(struct udef_chans *ul, char *name)
 
 static int ngetudef(char *name, char *chan)
 {
-  struct udef_struct *l;
-  struct udef_chans *ll;
+  struct udef_struct *l = NULL;
+  struct udef_chans *ll = NULL;
 
   for (l = udef; l; l = l->next)
     if (!egg_strcasecmp(l->name, name)) {
@@ -33,7 +33,7 @@ static int ngetudef(char *name, char *chan)
 
 static void setudef(struct udef_struct *us, char *name, int value)
 {
-  struct udef_chans *ul, *ul_last = NULL;
+  struct udef_chans *ul = NULL, *ul_last = NULL;
 
   for (ul = us->values; ul; ul_last = ul, ul = ul->next)
     if (!egg_strcasecmp(ul->chan, name)) {
@@ -41,7 +41,7 @@ static void setudef(struct udef_struct *us, char *name, int value)
       return;
     }
 
-  ul = malloc(sizeof(struct udef_chans));
+  ul = calloc(1, sizeof(struct udef_chans));
   ul->chan = strdup(name);
   ul->value = value;
   ul->next = NULL;
@@ -53,7 +53,7 @@ static void setudef(struct udef_struct *us, char *name, int value)
 
 static void initudef(int type, char *name, int defined)
 {
-  struct udef_struct *ul, *ul_last = NULL;
+  struct udef_struct *ul = NULL, *ul_last = NULL;
 
   if (strlen(name) < 1)
     return;
@@ -67,7 +67,7 @@ static void initudef(int type, char *name, int defined)
     }
 
   debug2("Creating %s (type %d)", name, type);
-  ul = malloc(sizeof(struct udef_struct));
+  ul = calloc(1, sizeof(struct udef_struct));
   ul->name = strdup(name);
   if (defined)
     ul->defined = 1;

+ 75 - 76
src/mod/channels.mod/userchan.c

@@ -9,7 +9,7 @@ extern struct cmd_pass *cmdpass;
 
 struct chanuserrec *get_chanrec(struct userrec *u, char *chname)
 {
-  struct chanuserrec *ch;
+  struct chanuserrec *ch = NULL;
 
   for (ch = u->chanrec; ch; ch = ch->next) 
     if (!rfc_casecmp(ch->channel, chname))
@@ -22,7 +22,7 @@ static struct chanuserrec *add_chanrec(struct userrec *u, char *chname)
   struct chanuserrec *ch = NULL;
 
   if (findchan_by_dname(chname)) {
-    ch = malloc(sizeof(struct chanuserrec));
+    ch = calloc(1, sizeof(struct chanuserrec));
 
     ch->next = u->chanrec;
     u->chanrec = ch;
@@ -40,7 +40,7 @@ static struct chanuserrec *add_chanrec(struct userrec *u, char *chname)
 
 static void add_chanrec_by_handle(struct userrec *bu, char *hand, char *chname)
 {
-  struct userrec *u;
+  struct userrec *u = NULL;
 
   u = get_user_by_handle(bu, hand);
   if (!u)
@@ -51,8 +51,8 @@ static void add_chanrec_by_handle(struct userrec *bu, char *hand, char *chname)
 
 static void get_handle_chaninfo(char *handle, char *chname, char *s)
 {
-  struct userrec *u;
-  struct chanuserrec *ch;
+  struct userrec *u = NULL;
+  struct chanuserrec *ch = NULL;
 
   u = get_user_by_handle(userlist, handle);
   if (u == NULL) {
@@ -75,9 +75,9 @@ static void get_handle_chaninfo(char *handle, char *chname, char *s)
 static void set_handle_chaninfo(struct userrec *bu, char *handle,
 				char *chname, char *info)
 {
-  struct userrec *u;
-  struct chanuserrec *ch;
-  struct chanset_t *cst;
+  struct userrec *u = NULL;
+  struct chanuserrec *ch = NULL;
+  struct chanset_t *cst = NULL;
 
   u = get_user_by_handle(bu, handle);
   if (!u)
@@ -127,7 +127,7 @@ static void del_chanrec(struct userrec *u, char *chname)
 
 static void set_handle_laston(char *chan, struct userrec *u, time_t n)
 {
-  struct chanuserrec *ch;
+  struct chanuserrec *ch = NULL;
 
   if (!u)
     return;
@@ -219,9 +219,9 @@ static int u_match_mask(maskrec *rec, char *mask)
 static int u_delban(struct chanset_t *c, char *who, int doit)
 {
   int j, i = 0;
-  maskrec *t;
+  maskrec *t = NULL;
   maskrec **u = (c) ? &c->bans : &global_bans;
-  char temp[256];
+  char temp[256] = "";
 
   if (!strchr(who, '!') && str_isdigit(who)) {
     j = atoi(who);
@@ -274,7 +274,7 @@ static int u_delban(struct chanset_t *c, char *who, int doit)
 static int u_delexempt (struct chanset_t * c, char * who, int doit)
 {
   int j, i = 0;
-  maskrec *t;
+  maskrec *t = NULL;
   maskrec **u = c ? &(c->exempts) : &global_exempts;
 
   if (!strchr(who, '!') && str_isdigit(who)) {
@@ -324,7 +324,7 @@ static int u_delexempt (struct chanset_t * c, char * who, int doit)
 static int u_delinvite(struct chanset_t *c, char *who, int doit)
 {
   int j, i = 0;
-  maskrec *t;
+  maskrec *t = NULL;
   maskrec **u = c ? &(c->invites) : &global_invites;
 
   if (!strchr(who, '!') && str_isdigit(who)) {
@@ -376,9 +376,9 @@ static int u_delinvite(struct chanset_t *c, char *who, int doit)
 static int u_addban(struct chanset_t *chan, char *ban, char *from, char *note,
 		    time_t expire_time, int flags)
 {
-  char host[1024], s[1024];
-  maskrec *p = NULL, *l, **u = chan ? &chan->bans : &global_bans;
-  module_entry *me;
+  char host[1024] = "", s[1024] = "";
+  maskrec *p = NULL, *l = NULL, **u = chan ? &chan->bans : &global_bans;
+  module_entry *me = NULL;
 
   strcpy(host, ban);
   /* Choke check: fix broken bans (must have '!' and '@') */
@@ -423,7 +423,7 @@ static int u_addban(struct chanset_t *chan, char *ban, char *from, char *note,
   }
 
   if (p == NULL) {
-  p = malloc(sizeof(maskrec));
+  p = calloc(1, sizeof(maskrec));
   p->next = *u;
   *u = p;
   }
@@ -462,9 +462,9 @@ static int u_addban(struct chanset_t *chan, char *ban, char *from, char *note,
 static int u_addinvite(struct chanset_t *chan, char *invite, char *from,
 		       char *note, time_t expire_time, int flags)
 {
-  char host[1024], s[1024];
+  char host[1024] = "", s[1024] = "";
   maskrec *p = NULL, *l, **u = chan ? &chan->invites : &global_invites;
-  module_entry *me;
+  module_entry *me = NULL;
 
   strcpy(host, invite);
   /* Choke check: fix broken invites (must have '!' and '@') */
@@ -502,7 +502,7 @@ static int u_addinvite(struct chanset_t *chan, char *invite, char *from,
   }
 
   if (p == NULL) {  
-  p = malloc(sizeof(maskrec));
+  p = calloc(1, sizeof(maskrec));
   p->next = *u;
   *u = p;
   }
@@ -541,9 +541,9 @@ static int u_addinvite(struct chanset_t *chan, char *invite, char *from,
 static int u_addexempt(struct chanset_t *chan, char *exempt, char *from,
 		       char *note, time_t expire_time, int flags)
 {
-  char host[1024], s[1024];
+  char host[1024] = "", s[1024] = "";
   maskrec *p = NULL, *l, **u = chan ? &chan->exempts : &global_exempts;
-  module_entry *me;
+  module_entry *me = NULL;
 
   strcpy(host, exempt);
   /* Choke check: fix broken exempts (must have '!' and '@') */
@@ -581,7 +581,7 @@ static int u_addexempt(struct chanset_t *chan, char *exempt, char *from,
   }
 
   if (p == NULL) {  
-  p = malloc(sizeof(maskrec));
+  p = calloc(1, sizeof(maskrec));
   p->next = *u;
   *u = p;
   }
@@ -617,10 +617,9 @@ static int u_addexempt(struct chanset_t *chan, char *exempt, char *from,
 
 /* Take host entry from ban list and display it ban-style.
  */
-static void display_ban(int idx, int number, maskrec *ban,
-			struct chanset_t *chan, int show_inact)
+static void display_ban(int idx, int number, maskrec *ban, struct chanset_t *chan, int show_inact)
 {
-  char dates[81], s[41];
+  char dates[81] = "", s[41] = "";
 
   if (ban->added) {
     daysago(now, ban->added, s);
@@ -637,7 +636,7 @@ static void display_ban(int idx, int number, maskrec *ban,
   if (ban->flags & MASKREC_PERM)
     strcpy(s, "(perm)");
   else {
-    char s1[41];
+    char s1[41] = "";
 
     days(ban->expire, now, s1);
     sprintf(s, "(expires %s)", s1);
@@ -665,10 +664,9 @@ static void display_ban(int idx, int number, maskrec *ban,
 
 /* Take host entry from exempt list and display it ban-style.
  */
-static void display_exempt(int idx, int number, maskrec *exempt,
-			   struct chanset_t *chan, int show_inact)
+static void display_exempt(int idx, int number, maskrec *exempt, struct chanset_t *chan, int show_inact)
 {
-  char dates[81], s[41];
+  char dates[81] = "", s[41] = "";
 
   if (exempt->added) {
     daysago(now, exempt->added, s);
@@ -685,7 +683,7 @@ static void display_exempt(int idx, int number, maskrec *exempt,
   if (exempt->flags & MASKREC_PERM)
     strcpy(s, "(perm)");
   else {
-    char s1[41];
+    char s1[41] = "";
 
     days(exempt->expire, now, s1);
     sprintf(s, "(expires %s)", s1);
@@ -713,10 +711,9 @@ static void display_exempt(int idx, int number, maskrec *exempt,
 
 /* Take host entry from invite list and display it ban-style.
  */
-static void display_invite (int idx, int number, maskrec *invite,
-			    struct chanset_t *chan, int show_inact)
+static void display_invite (int idx, int number, maskrec *invite, struct chanset_t *chan, int show_inact)
 {
-  char dates[81], s[41];
+  char dates[81] = "", s[41] = "";
 
   if (invite->added) {
     daysago(now, invite->added, s);
@@ -733,7 +730,7 @@ static void display_invite (int idx, int number, maskrec *invite,
   if (invite->flags & MASKREC_PERM)
     strcpy(s, "(perm)");
   else {
-    char s1[41];
+    char s1[41] = "";
 
     days(invite->expire, now, s1);
     sprintf(s, "(expires %s)", s1);
@@ -762,9 +759,9 @@ static void display_invite (int idx, int number, maskrec *invite,
 static void tell_bans(int idx, int show_inact, char *match)
 {
   int k = 1;
-  char *chname;
+  char *chname = NULL;
   struct chanset_t *chan = NULL;
-  maskrec *u;
+  maskrec *u = NULL;
 
   /* Was a channel given? */
   if (match[0]) {
@@ -824,8 +821,8 @@ static void tell_bans(int idx, int show_inact, char *match)
 	display_ban(idx, k++, u, chan, show_inact);
     }
     if (chan->status & CHAN_ACTIVE) {
-      masklist *b;
-      char s[UHOSTLEN], *s1, *s2, fill[256];
+      masklist *b = NULL;
+      char s[UHOSTLEN] = "", *s1 = NULL, *s2 = NULL, fill[256] = "";
       int min, sec;
 
       for (b = chan->channel.ban; b && b->mask[0]; b = b->next) {    
@@ -860,9 +857,9 @@ static void tell_bans(int idx, int show_inact, char *match)
 static void tell_exempts(int idx, int show_inact, char *match)
 {
   int k = 1;
-  char *chname;
+  char *chname = NULL;
   struct chanset_t *chan = NULL;
-  maskrec *u;
+  maskrec *u = NULL;
 
   /* Was a channel given? */
   if (match[0]) {
@@ -923,8 +920,8 @@ static void tell_exempts(int idx, int show_inact, char *match)
 	display_exempt(idx, k++, u, chan, show_inact);
     }
     if (chan->status & CHAN_ACTIVE) {
-      masklist *e;
-      char s[UHOSTLEN], *s1, *s2,fill[256];
+      masklist *e = NULL;
+      char s[UHOSTLEN] = "", *s1 = NULL, *s2 = NULL , fill[256] = "";
       int min, sec;
 
       for (e = chan->channel.exempt; e && e->mask[0]; e = e->next) {
@@ -959,9 +956,9 @@ static void tell_exempts(int idx, int show_inact, char *match)
 static void tell_invites(int idx, int show_inact, char *match)
 {
   int k = 1;
-  char *chname;
+  char *chname = NULL;
   struct chanset_t *chan = NULL;
-  maskrec *u;
+  maskrec *u = NULL;
 
   /* Was a channel given? */
   if (match[0]) {
@@ -1022,8 +1019,8 @@ static void tell_invites(int idx, int show_inact, char *match)
 	display_invite(idx, k++, u, chan, show_inact);
     }
     if (chan->status & CHAN_ACTIVE) {
-      masklist *i;
-      char s[UHOSTLEN], *s1, *s2,fill[256];
+      masklist *i = NULL;
+      char s[UHOSTLEN] = "", *s1 = NULL, *s2 = NULL, fill[256] = "";
       int min, sec;
 
       for (i = chan->channel.invite; i && i->mask[0]; i = i->next) {
@@ -1059,16 +1056,17 @@ static int write_config(FILE *f, int idx)
 {
   int i = 0;
 #ifdef S_DCCPASS
-  struct cmd_pass *cp;
+  struct cmd_pass *cp = NULL;
 #endif
   putlog(LOG_DEBUG, "@", "Writing config entries...");
   if (lfprintf(f, CONFIG_NAME " - -\n") == EOF) /* Daemus */
       return 0;
-  for (i = 0; i < cfg_count; i++)
+  for (i = 0; i < cfg_count; i++) {
     if ((cfg[i]->flags & CFGF_GLOBAL) && (cfg[i]->gdata)) {
       if (lfprintf(f, "@ %s %s\n", cfg[i]->name, cfg[i]->gdata ? cfg[i]->gdata : "") == EOF)
         return 0;
     }
+  }
 
 #ifdef S_DCCPASS
   for (cp = cmdpass; cp; cp = cp->next)
@@ -1082,10 +1080,10 @@ static int write_config(FILE *f, int idx)
  */
 static int write_bans(FILE *f, int idx)
 {
-  struct chanset_t *chan;
-  maskrec *b;
-  struct igrec *i;
-  char	*mask;
+  struct chanset_t *chan = NULL;
+  maskrec *b = NULL;
+  struct igrec *i = NULL;
+  char *mask = NULL;
 
   if (global_ign)
     if (lfprintf(f, IGNORE_NAME " - -\n") == EOF)	/* Daemus */
@@ -1152,9 +1150,9 @@ static int write_bans(FILE *f, int idx)
  */
 static int write_exempts(FILE *f, int idx)
 {
-  struct chanset_t *chan;
-  maskrec *e;
-  char	*mask;
+  struct chanset_t *chan = NULL;
+  maskrec *e = NULL;
+  char *mask = NULL;
 
   if (global_exempts)
     if (lfprintf(f, EXEMPT_NAME " - -\n") == EOF) /* Daemus */
@@ -1205,9 +1203,9 @@ static int write_exempts(FILE *f, int idx)
  */
 static int write_invites(FILE *f, int idx)
 {
-  struct chanset_t *chan;
-  maskrec *ir;
-  char	*mask;
+  struct chanset_t *chan = NULL;
+  maskrec *ir = NULL;
+  char *mask = NULL;
 
   if (global_invites)
     if (lfprintf(f, INVITE_NAME " - -\n") == EOF) /* Daemus */
@@ -1258,12 +1256,12 @@ static int write_invites(FILE *f, int idx)
  */
 static int write_chans(FILE *f, int idx)
 {
-  char w[1024], w2[1024], name[163];
+  char w[1024] = "", w2[1024] = "", name[163] = "";
 /*  char udefs[2048] = "", buf[2048]; */
 /* Chanchar template
  *char temp[121];
  */
-  struct chanset_t *chan;
+  struct chanset_t *chan = NULL;
 /*  struct udef_struct *ul; */
 
   putlog(LOG_DEBUG, "*", "Writing channels..");
@@ -1375,9 +1373,10 @@ ban-time %d exempt-time %d invite-time %d \
 static void channels_writeuserfile(void)
 {
 #ifdef HUB
-  char	 s[1024];
-  FILE	*f;
-  int	 ret = 0;
+  char s[1024] = "";
+  FILE *f = NULL;
+  int  ret = 0;
+
   putlog(LOG_DEBUG, "@", "Writing channel/ban/exempt/invite entries.");
   simple_sprintf(s, "%s~new", userfile);
   f = fopen(s, "a");
@@ -1406,9 +1405,9 @@ static void channels_writeuserfile(void)
  */
 static int expired_mask(struct chanset_t *chan, char *who)
 {
-  memberlist		*m, *m2;
-  char			 buf[UHOSTLEN], *snick, *sfrom;
-  struct userrec	*u;
+  memberlist *m = NULL, *m2 = NULL;
+  char buf[UHOSTLEN] = "", *snick = NULL, *sfrom = NULL;
+  struct userrec *u = NULL;
 
   /* Always expire masks, regardless of who set it? */
   if (force_expire)
@@ -1454,9 +1453,9 @@ static int expired_mask(struct chanset_t *chan, char *who)
 
 static void check_expired_bans(void)
 {
-  maskrec *u, *u2;
-  struct chanset_t *chan;
-  masklist *b;
+  maskrec *u = NULL, *u2 = NULL;
+  struct chanset_t *chan = NULL;
+  masklist *b = NULL;
 
   for (u = global_bans; u; u = u2) { 
     u2 = u->next;
@@ -1496,9 +1495,9 @@ static void check_expired_bans(void)
  */
 static void check_expired_exempts(void)
 {
-  maskrec *u, *u2;
-  struct chanset_t *chan;
-  masklist *b, *e;
+  maskrec *u = NULL, *u2 = NULL;
+  struct chanset_t *chan = NULL;
+  masklist *b = NULL, *e = NULL;
   int match;
 
   if (!use_exempts)
@@ -1571,9 +1570,9 @@ static void check_expired_exempts(void)
  */
 static void check_expired_invites(void)
 {
-  maskrec *u, *u2;
-  struct chanset_t *chan;
-  masklist *b;
+  maskrec *u = NULL, *u2 = NULL;
+  struct chanset_t *chan = NULL;
+  masklist *b = NULL;
 
   if (!use_invites)
     return;

+ 18 - 21
src/mod/compress.mod/compress.c

@@ -46,8 +46,7 @@
 
 #define BUFLEN	512
 
-static Function *global = NULL,
-		*share_funcs = NULL;
+static Function *global = NULL, *share_funcs = NULL;
 
 static unsigned int compressed_files;	/* Number of files compressed.      */
 static unsigned int uncompressed_files;	/* Number of files uncompressed.    */
@@ -68,12 +67,10 @@ static int is_compressedfile(char *filename);
 
 static int is_compressedfile(char *filename)
 {
-  char		  buf1[50], buf2[50];
-  FILE		 *fin;
-  register int    len1, len2, i;
+  char buf1[50] = "", buf2[50] = "";
+  FILE *fin = NULL;
+  register int len1, len2, i;
 
-  egg_memset(buf1, 0, 50);
-  egg_memset(buf2, 0, 50);
   if (!is_file(filename))
     return COMPF_FAILED;
 
@@ -117,9 +114,9 @@ static int is_compressedfile(char *filename)
  */
 static int uncompress_to_file(char *f_src, char *f_target)
 {
-  char buf[BUFLEN];
+  char buf[BUFLEN] = "";
   int len;
-  FILE *fin, *fout;
+  FILE *fin = NULL, *fout = NULL;
 
   if (!is_file(f_src)) {
     putlog(LOG_MISC, "*", "Failed to uncompress file `%s': not a file.",
@@ -184,9 +181,9 @@ inline static void adjust_mode_num(int *mode)
  */
 static int compress_to_file_mmap(FILE *fout, FILE *fin)
 {
-    int		  len, ifd = fileno(fin);
-    char	 *buf;
-    struct stat	  st;
+    int	len, ifd = fileno(fin);
+    char *buf = NULL;
+    struct stat st;
 
     /* Find out size of file */
     if (fstat(ifd, &st) < 0)
@@ -216,9 +213,9 @@ static int compress_to_file_mmap(FILE *fout, FILE *fin)
  */
 static int compress_to_file(char *f_src, char *f_target, int mode_num)
 {
-  char  buf[BUFLEN], mode[5];
-  FILE *fin, *fout;
-  int   len;
+  char buf[BUFLEN] = "", mode[5] = "";
+  FILE *fin = NULL, *fout = NULL;
+  int len;
 
   adjust_mode_num(&mode_num);
   egg_snprintf(mode, sizeof mode, "wb%d", mode_num);
@@ -284,11 +281,11 @@ static int compress_to_file(char *f_src, char *f_target, int mode_num)
  */
 static int compress_file(char *filename, int mode_num)
 {
-  char *temp_fn, randstr[5];
-  int   ret;
+  char *temp_fn = NULL, randstr[5] = "";
+  int ret;
 
   /* Create temporary filename. */
-  temp_fn = malloc(strlen(filename) + 5);
+  temp_fn = calloc(1, strlen(filename) + 5);
   make_rand_str(randstr, 4);
   strcpy(temp_fn, filename);
   strcat(temp_fn, randstr);
@@ -310,11 +307,11 @@ static int compress_file(char *filename, int mode_num)
  */
 static int uncompress_file(char *filename)
 {
-  char *temp_fn, randstr[5];
-  int   ret;
+  char *temp_fn = NULL, randstr[5] = "";
+  int ret;
 
   /* Create temporary filename. */
-  temp_fn = malloc(strlen(filename) + 5);
+  temp_fn = calloc(1, strlen(filename) + 5);
   make_rand_str(randstr, 4);
   strcpy(temp_fn, filename);
   strcat(temp_fn, randstr);

+ 19 - 22
src/mod/console.mod/console.c

@@ -36,11 +36,10 @@ struct console_info {
 
 static struct user_entry_type USERENTRY_CONSOLE;
 
-
 static int console_unpack(struct userrec *u, struct user_entry *e)
 {
-  struct console_info *ci = malloc(sizeof(struct console_info));
-  char *par, *arg;
+  struct console_info *ci = calloc(1, sizeof(struct console_info));
+  char *par = NULL, *arg = NULL;
 
   par = e->u.list->extra;
   arg = newsplit(&par);
@@ -64,8 +63,8 @@ static int console_unpack(struct userrec *u, struct user_entry *e)
 
 static int console_pack(struct userrec *u, struct user_entry *e)
 {
-  char work[1024];
-  struct console_info *ci;
+  char work[1024] = "";
+  struct console_info *ci = NULL;
   int l;
 
   ci = (struct console_info *) e->u.extra;
@@ -75,9 +74,9 @@ static int console_pack(struct userrec *u, struct user_entry *e)
 		     stripmasktype(ci->stripflags), ci->echoflags,
 		     ci->page, ci->conchan, ci->colour);
 
-  e->u.list = malloc(sizeof(struct list_type));
+  e->u.list = calloc(1, sizeof(struct list_type));
   e->u.list->next = NULL;
-  e->u.list->extra = malloc(l + 1);
+  e->u.list->extra = calloc(1, l + 1);
   strcpy(e->u.list->extra, work);
 
   free(ci->channel);
@@ -137,7 +136,7 @@ static int console_set(struct userrec *u, struct user_entry *e, void *buf)
 static int console_gotshare(struct userrec *u, struct user_entry *e, char *par, int idx)
 {
   struct console_info *ci = (struct console_info *) e->u.extra;
-  char *arg;
+  char *arg = NULL;
   int i;
 
   arg = newsplit(&par);
@@ -145,7 +144,7 @@ static int console_gotshare(struct userrec *u, struct user_entry *e, char *par,
     free(ci->channel);
     free(ci);
   }
-  ci = malloc(sizeof(struct console_info));
+  ci = calloc(1, sizeof(struct console_info));
   ci->channel = strdup(arg);
   arg = newsplit(&par);
   ci->conflags = logmodes(arg);
@@ -189,7 +188,8 @@ static int console_gotshare(struct userrec *u, struct user_entry *e, char *par,
 static void console_display(int idx, struct user_entry *e, struct userrec *u)
 {
   struct console_info *i = e->u.extra;
-  char tmp[100];
+  char tmp[100] = "";
+
   if (dcc[idx].user && (dcc[idx].user->flags & USER_MASTER)) {
     dprintf(idx, "  %s\n", CONSOLE_SAVED_SETTINGS);
     dprintf(idx, "    %s %s\n", CONSOLE_CHANNEL, i->channel);
@@ -209,12 +209,11 @@ static void console_display(int idx, struct user_entry *e, struct userrec *u)
   }
 }
 
-static int console_dupuser(struct userrec *new, struct userrec *old,
-			   struct user_entry *e)
+static int console_dupuser(struct userrec *new, struct userrec *old, struct user_entry *e)
 {
-  struct console_info *i = e->u.extra, *j;
+  struct console_info *i = e->u.extra, *j = NULL;
 
-  j = malloc(sizeof(struct console_info));
+  j = calloc(1, sizeof(struct console_info));
   egg_memcpy(j, i, sizeof(struct console_info));
 
   j->channel = strdup(i->channel);
@@ -272,13 +271,11 @@ static int console_chon(char *handle, int idx)
 
       if (p) {
 	if (dcc[idx].u.chat->channel >= 0) {
-	    char x[1024];
+	    char x[1024] = "";
 
-	    chanout_but(-1, dcc[idx].u.chat->channel,
-			"*** [%s] %s\n", dcc[idx].nick, p);
+	    chanout_but(-1, dcc[idx].u.chat->channel, "*** [%s] %s\n", dcc[idx].nick, p);
 	    simple_sprintf(x, "[%s] %s", dcc[idx].nick, p);
-	    botnet_send_chan(-1, conf.bot->nick, NULL,
-			     dcc[idx].u.chat->channel, x);
+	    botnet_send_chan(-1, conf.bot->nick, NULL, dcc[idx].u.chat->channel, x);
 	}
       }
     }
@@ -291,8 +288,7 @@ static int console_store(struct userrec *u, int idx, char *par)
   struct console_info *i = get_user(&USERENTRY_CONSOLE, u);
 
   if (!i) {
-    i = malloc(sizeof(struct console_info));
-    egg_bzero(i, sizeof(struct console_info));
+    i = calloc(1, sizeof(struct console_info));
   }
   if (i->channel)
     free(i->channel);
@@ -310,7 +306,8 @@ static int console_store(struct userrec *u, int idx, char *par)
     i->colour = 0;
   i->conchan = dcc[idx].u.chat->channel;
   if (par) {
-    char tmp[100];
+    char tmp[100] = "";
+
     dprintf(idx, "%s\n", CONSOLE_SAVED_SETTINGS2);
     dprintf(idx, "  %s %s\n", CONSOLE_CHANNEL, i->channel);
     dprintf(idx, "  %s %s, %s %s, %s %s\n", CONSOLE_FLAGS,

+ 19 - 23
src/mod/ctcp.mod/ctcp.c

@@ -42,17 +42,17 @@ int cloak_script = CLOAK_PLAIN;
 int cloak_awaytime = 0;
 int cloak_heretime = 0;
 int listen_time = 0;
-char cloak_bxver[10];
-char cloak_os[20];
-char cloak_osver[100];
-char cloak_host[161];
-char ctcpversion[400];
-char ctcpuserinfo[400];
-char autoaway[100];
+char cloak_bxver[10] = "";
+char cloak_os[20] = "";
+char cloak_osver[100] = "";
+char cloak_host[161] = "";
+char ctcpversion[400] = "";
+char ctcpuserinfo[400] = "";
+char autoaway[100] = "";
 
 char *strtolower(char *s)
 {
-  char *p, *p2 = strdup(s); 
+  char *p = NULL, *p2 = strdup(s); 
 
   p = p2;
   while (*p) {
@@ -128,7 +128,7 @@ void scriptchanged()
     break;
   case CLOAK_MIRC:
   {
-    char mircver[4];
+    char mircver[4] = "";
 
     switch (random() % 7) {
       case 0:
@@ -167,7 +167,7 @@ void scriptchanged()
   }
   case CLOAK_CYPRESS:
   {
-    char theme[30];
+    char theme[30] = "";
 
     switch (random() % 25) { /* 0-19 = script, 20-24 = plain */
     case 0:
@@ -432,9 +432,9 @@ static void ctcp_minutely()
 
 static int ctcp_FINGER(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
 {
-  char *p;
+  char *p = NULL;
   int idletime;
-  struct passwd *pwd;
+  struct passwd *pwd = NULL;
 
   if (cloak_awaytime)
     idletime = now - cloak_awaytime;
@@ -455,7 +455,7 @@ static int ctcp_FINGER(char *nick, char *uhost, struct userrec *u, char *object,
 
 static int ctcp_ECHO(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
 {
-  char reply[60];
+  char reply[60] = "";
 
   strncpyz(reply, text, sizeof(reply));
   dprintf(DP_HELP, STR("NOTICE %s :\001%s %s\001\n"), nick, keyword, reply);
@@ -516,8 +516,7 @@ static int ctcp_WHOAMI(char *nick, char *uhost, struct userrec *u, char *object,
 
 static int ctcp_OP(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
 {
-  char chan[256],
-   *p;
+  char chan[256] = "", *p = NULL;
 
   if (text[0]) {
     strncpyz(chan, text, sizeof(chan));
@@ -532,8 +531,7 @@ static int ctcp_OP(char *nick, char *uhost, struct userrec *u, char *object, cha
 static int ctcp_INVITE_UNBAN(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
 {
   struct chanset_t *chan = chanset;
-  char chname[256],
-   *p;
+  char chname[256] = "", *p = NULL;
 
   if (text[0] == '#') {
     strncpyz(chname, text, sizeof(chname));
@@ -556,7 +554,6 @@ static int ctcp_INVITE_UNBAN(char *nick, char *uhost, struct userrec *u, char *o
 
 static int ctcp_USERINFO(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
 {
-
   if (cloak_script == CLOAK_TUNNELVISION)
     strcpy(ctcpuserinfo, botname);
   else if (cloak_script == CLOAK_PREVAIL) {
@@ -569,7 +566,7 @@ static int ctcp_USERINFO(char *nick, char *uhost, struct userrec *u, char *objec
 
 static int ctcp_CLIENTINFO(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
 {
-  char buf[256];
+  char buf[256] = "";
 
   if (!text[0]) {
     strcpy(buf, STR("SED UTC ACTION DCC CDCC BDCC XDCC VERSION CLIENTINFO USERINFO ERRMSG FINGER TIME PING ECHO INVITE WHOAMI OP OPS UNBAN IDENT XLINK UPTIME :Use CLIENTINFO <COMMAND> to get more specific information"));
@@ -629,7 +626,7 @@ static int ctcp_CLIENTINFO(char *nick, char *uhost, struct userrec *u, char *obj
 
 static int ctcp_TIME(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
 {
-  char tms[81];
+  char tms[81] = "";
 
   strncpyz(tms, ctime(&now), sizeof(tms));
   dprintf(DP_HELP, STR("NOTICE %s :\001%s %s\001\n"), nick, keyword, tms);
@@ -694,7 +691,7 @@ void cloak_describe(struct cfg_entry *cfgent, int idx)
 
 void cloak_changed(struct cfg_entry *cfgent, char *oldval, int *valid)
 {
-  char *p;
+  char *p = NULL;
   int i;
 
   if (!(p = cfgent->ldata ? cfgent->ldata : cfgent->gdata))
@@ -720,7 +717,7 @@ struct cfg_entry CFG_CLOAK_SCRIPT = {
 void ctcp_init()
 {
 #ifdef LEAF
-  char *p;
+  char *p = NULL;
   struct utsname un;
 
   egg_bzero(&un, sizeof(un));
@@ -767,4 +764,3 @@ void ctcp_init()
 #endif /* LEAF */
   add_cfg(&CFG_CLOAK_SCRIPT);
 }
-

+ 21 - 23
src/mod/dns.mod/coredns.c

@@ -158,12 +158,12 @@ static long aseed;
 
 static int resfd;
 
-static char tempstring[512];
-static char namestring[1024 + 1];
-static char stackstring[1024 + 1];
+static char tempstring[512] = "";
+static char namestring[1024 + 1] = "";
+static char stackstring[1024 + 1] = "";
 
 #ifdef DEBUG_DNS
-static char sendstring[1024 + 1];
+static char sendstring[1024 + 1] = "";
 #endif /* DEBUG_DNS */
 
 static const char nullstring[] = "";
@@ -209,14 +209,12 @@ static char *strtdiff(char *d, long signeddiff)
  */
 static struct resolve *allocresolve()
 {
-    struct resolve *rp;
+    struct resolve *rp = NULL;
 
-    rp = (struct resolve *) malloc(sizeof(struct resolve));
-    egg_bzero(rp, sizeof(struct resolve));
+    rp = (struct resolve *) calloc(1, sizeof(struct resolve));
     return rp;
 }
 
-
 /*
  *    Hash and linked-list related functions
  */
@@ -252,7 +250,7 @@ static u_32bit_t gethostbash(char *host)
  */
 static void linkresolveid(struct resolve *addrp)
 {
-    struct resolve *rp;
+    struct resolve *rp = NULL;
     u_32bit_t bashnum;
 
     bashnum = getidbash(addrp->id);
@@ -304,7 +302,7 @@ static void unlinkresolveid(struct resolve *rp)
  */
 static void linkresolvehost(struct resolve *addrp)
 {
-    struct resolve *rp;
+    struct resolve *rp = NULL;
     u_32bit_t bashnum;
     int ret;
 
@@ -361,7 +359,7 @@ static void unlinkresolvehost(struct resolve *rp)
  */
 static void linkresolveip(struct resolve *addrp)
 {
-    struct resolve *rp;
+    struct resolve *rp = NULL;
     u_32bit_t bashnum;
 
     bashnum = getipbash(addrp->ip);
@@ -414,7 +412,7 @@ static void unlinkresolveip(struct resolve *rp)
  */
 static void linkresolve(struct resolve *rp)
 {
-    struct resolve *irp;
+    struct resolve *irp = NULL;
 
     if (expireresolves) {
 	irp = expireresolves;
@@ -471,7 +469,7 @@ static void unlinkresolve(struct resolve *rp)
  */
 static struct resolve *findid(u_16bit_t id)
 {
-    struct resolve *rp;
+    struct resolve *rp = NULL;
     int bashnum;
 
     bashnum = getidbash(id);
@@ -494,7 +492,7 @@ static struct resolve *findid(u_16bit_t id)
  */
 static struct resolve *findhost(char *hostn)
 {
-    struct resolve *rp;
+    struct resolve *rp = NULL;
     int bashnum;
 
     bashnum = gethostbash(hostn);
@@ -520,7 +518,7 @@ static struct resolve *findhost(char *hostn)
  */
 static struct resolve *findip(IP ip)
 {
-    struct resolve *rp;
+    struct resolve *rp = NULL;
     u_32bit_t bashnum;
 
     bashnum = getipbash(ip);
@@ -548,7 +546,7 @@ static struct resolve *findip(IP ip)
  */
 static void dorequest(char *s, int type, u_16bit_t id)
 {
-    packetheader *hp;
+    packetheader *hp = NULL;
     int r, i;
     u_8bit_t buf[(MAX_PACKETSIZE / sizeof(char)) + 1];
 
@@ -649,10 +647,10 @@ static void passrp(struct resolve *rp, long ttl, int type)
  */
 static void parserespacket(u_8bit_t *s, int l)
 {
-    struct resolve *rp;
-    packetheader *hp;
-    u_8bit_t *eob;
-    u_8bit_t *c;
+    struct resolve *rp = NULL;
+    packetheader *hp = NULL;
+    u_8bit_t *eob = NULL;
+    u_8bit_t *c = NULL;
     long ttl;
     int r, usefulanswer;
     u_16bit_t rr, datatype, class, qdatatype, qclass;
@@ -942,7 +940,7 @@ static void dns_ack(void)
  */
 static void dns_check_expires(void)
 {
-    struct resolve *rp, *nextrp;
+    struct resolve *rp = NULL, *nextrp = NULL;
 
     /* Walk through sorted list ... */
     for (rp = expireresolves; (rp) && (now >= rp->expiretime);
@@ -987,7 +985,7 @@ static void dns_check_expires(void)
  */
 void dns_hostbyip(IP ip)
 {
-    struct resolve *rp;
+    struct resolve *rp = NULL;
 
     ip = htonl(ip);
     if ((rp = findip(ip))) {
@@ -1017,7 +1015,7 @@ void dns_hostbyip(IP ip)
  */
 void dns_ipbyhost(char *hostn)
 {
-    struct resolve *rp;
+    struct resolve *rp = NULL;
     struct in_addr inaddr;
 
     /* Check if someone passed us an IP address as hostname

+ 0 - 1
src/mod/dns.mod/dns.c

@@ -20,7 +20,6 @@ static void dns_event_failure(struct resolve *rp, int type);
 
 #include "coredns.c"
 
-
 /*
  *    DNS event related code
  */

+ 71 - 90
src/mod/irc.mod/cmdsirc.c

@@ -9,7 +9,7 @@
  */
 static struct chanset_t *get_channel(int idx, char *chname)
 {
-  struct chanset_t *chan;
+  struct chanset_t *chan = NULL;
 
   if (chname && chname[0]) {
     chan = findchan_by_dname(chname);
@@ -49,9 +49,9 @@ static int has_op(int idx, struct chanset_t *chan)
  */
 static char *getnick(char *handle, struct chanset_t *chan)
 {
-  char			 s[UHOSTLEN];
-  struct userrec	*u;
-  register memberlist	*m;
+  char s[UHOSTLEN] = "";
+  struct userrec *u = NULL;
+  register memberlist *m = NULL;
 
   for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
     egg_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost);
@@ -63,9 +63,9 @@ static char *getnick(char *handle, struct chanset_t *chan)
 
 static void cmd_act(struct userrec *u, int idx, char *par)
 {
-  char *chname;
-  struct chanset_t *chan;
-  memberlist *m;
+  char *chname = NULL;
+  struct chanset_t *chan = NULL;
+  memberlist *m = NULL;
 
   if (!par[0]) {
     dprintf(idx, "Usage: act [channel] <action>\n");
@@ -99,7 +99,7 @@ static void cmd_act(struct userrec *u, int idx, char *par)
 
 static void cmd_msg(struct userrec *u, int idx, char *par)
 {
-  char *nick;
+  char *nick = NULL;
 
   nick = newsplit(&par);
   if (!par[0]) 
@@ -113,9 +113,9 @@ static void cmd_msg(struct userrec *u, int idx, char *par)
 
 static void cmd_say(struct userrec *u, int idx, char *par)
 {
-  char *chname;
-  struct chanset_t *chan;
-  memberlist *m;
+  char *chname = NULL;
+  struct chanset_t *chan = NULL;
+  memberlist *m = NULL;
 
   if (!par[0]) {
     dprintf(idx, "Usage: say [channel] <message>\n");
@@ -148,11 +148,9 @@ static void cmd_say(struct userrec *u, int idx, char *par)
 static void cmd_kickban(struct userrec *u, int idx, char *par)
 {
   struct chanset_t *chan = NULL;
-  char *chname, *nick, *s1;
+  char *chname = NULL, *nick = NULL, *s1 = NULL, s[UHOSTLEN] = "", bantype = 0;
   int all = 0;
-  memberlist *m;
-  char s[UHOSTLEN];
-  char bantype = 0;
+  memberlist *m = NULL;
 
   if (!par[0]) {
     dprintf(idx, "Usage: kickban [channel|*] [-|@]<nick> [reason]\n");
@@ -172,8 +170,7 @@ static void cmd_kickban(struct userrec *u, int idx, char *par)
       return;
   }
 
-  putlog(LOG_CMDS, "*", "#%s# (%s) kickban %s", dcc[idx].nick,
-	 all ? "*" : chan->dname, par);
+  putlog(LOG_CMDS, "*", "#%s# (%s) kickban %s", dcc[idx].nick, all ? "*" : chan->dname, par);
 
   nick = newsplit(&par);
   if ((nick[0] == '@') || (nick[0] == '-')) {
@@ -276,10 +273,9 @@ static void cmd_kickban(struct userrec *u, int idx, char *par)
 static void cmd_voice(struct userrec *u, int idx, char *par)
 {
   struct chanset_t *chan = NULL;
-  char *nick;
+  char *nick = NULL, s[UHOSTLEN] = "";
   int all = 0;
-  memberlist *m;
-  char s[UHOSTLEN];
+  memberlist *m = NULL;
 
   nick = newsplit(&par);
   if (par[0] == '*' && !par[1]) {
@@ -292,8 +288,7 @@ static void cmd_voice(struct userrec *u, int idx, char *par)
   }
   if (all)
     chan = chanset;
-  putlog(LOG_CMDS, "*", "#%s# (%s) voice %s", dcc[idx].nick,
-            all ? "*" : chan->dname , nick);
+  putlog(LOG_CMDS, "*", "#%s# (%s) voice %s", dcc[idx].nick, all ? "*" : chan->dname , nick);
   while (chan) {
     if (!nick[0] && !(nick = getnick(u->handle, chan))) {
       if (all) goto next;
@@ -341,10 +336,9 @@ static void cmd_voice(struct userrec *u, int idx, char *par)
 static void cmd_devoice(struct userrec *u, int idx, char *par)
 {
   struct chanset_t *chan = NULL;
-  char *nick;
+  char *nick = NULL, s[UHOSTLEN] = "";
   int all = 0;
-  memberlist *m;
-  char s[UHOSTLEN];
+  memberlist *m = NULL;
 
   nick = newsplit(&par);
   if (par[0] == '*' && !par[1]) {
@@ -357,8 +351,7 @@ static void cmd_devoice(struct userrec *u, int idx, char *par)
   }
   if (all)
     chan = chanset;
-  putlog(LOG_CMDS, "*", "#%s# (%s) devoice %s", dcc[idx].nick,
-        all ? "*" : chan->dname, nick);
+  putlog(LOG_CMDS, "*", "#%s# (%s) devoice %s", dcc[idx].nick, all ? "*" : chan->dname, nick);
   while (chan) {
   if (!nick[0] && !(nick = getnick(u->handle, chan))) {
     if (all) goto next;
@@ -405,10 +398,9 @@ static void cmd_devoice(struct userrec *u, int idx, char *par)
 static void cmd_op(struct userrec *u, int idx, char *par)
 {
   struct chanset_t *chan = NULL;
-  char *nick;
+  char *nick = NULL, s[UHOSTLEN] = "";
   int all = 0;
-  memberlist *m;
-  char s[UHOSTLEN];
+  memberlist *m = NULL;
 
   nick = newsplit(&par);
   if (par[0] == '*' && !par[1]) {
@@ -421,8 +413,7 @@ static void cmd_op(struct userrec *u, int idx, char *par)
   }
   if (all)
     chan = chanset;
-  putlog(LOG_CMDS, "*", "#%s# (%s) op %s", dcc[idx].nick,
-        all ? "*" : chan->dname, nick);
+  putlog(LOG_CMDS, "*", "#%s# (%s) op %s", dcc[idx].nick, all ? "*" : chan->dname, nick);
 
   while (chan) {
   get_user_flagrec(dcc[idx].user, &user, chan->dname);
@@ -484,7 +475,7 @@ static void cmd_op(struct userrec *u, int idx, char *par)
 
 void cmd_mdop(struct userrec *u, int idx, char *par)
 {
-  char *p, *chname;
+  char *p = NULL, *chname = NULL;
   int force_bots = 0,
     force_alines = 0,
     force_slines = 0,
@@ -499,14 +490,14 @@ void cmd_mdop(struct userrec *u, int idx, char *par)
     sdeops;
   memberlist **chanbots = NULL,
   **targets = NULL,
-   *m;
+   *m = NULL;
   int chanbotcount = 0,
     targetcount = 0,
     tpos = 0,
     bpos = 0,
     i;
-  struct chanset_t *chan;
-  char work[1024];
+  struct chanset_t *chan = NULL;
+  char work[1024] = "";
   
 
   putlog(LOG_CMDS, "*", "#%s# mdop %s", dcc[idx].nick, par);
@@ -539,11 +530,9 @@ void cmd_mdop(struct userrec *u, int idx, char *par)
   }
 
 
-  targets = malloc(chan->channel.members * sizeof(memberlist *));
-  egg_bzero(targets, chan->channel.members * sizeof(memberlist *));
+  targets = calloc(1, chan->channel.members * sizeof(memberlist *));
 
-  chanbots = malloc(chan->channel.members * sizeof(memberlist *));
-  egg_bzero(chanbots, chan->channel.members * sizeof(memberlist *));
+  chanbots = calloc(1, chan->channel.members * sizeof(memberlist *));
 
 ContextNote("!mdop!");
   for (m = chan->channel.member; m; m = m->next)
@@ -724,9 +713,8 @@ ContextNote("!mdop!");
 
 void mdop_request(char *botnick, char *code, char *par)
 {
-  char *chname,
-   *p;
-  char work[2048];
+  char *chname = NULL, *p = NULL;
+  char work[2048] = "";
 
   chname = newsplit(&par);
   work[0] = 0;
@@ -750,10 +738,9 @@ void mdop_request(char *botnick, char *code, char *par)
 static void cmd_deop(struct userrec *u, int idx, char *par)
 {
   struct chanset_t *chan = NULL;
-  char *nick;
+  char *nick = NULL, s[UHOSTLEN] = "";
   int all = 0;
-  memberlist *m;
-  char s[UHOSTLEN];
+  memberlist *m = NULL;
 
   nick = newsplit(&par);
   if (par[0] == '*' && !par[1]) {
@@ -767,8 +754,7 @@ static void cmd_deop(struct userrec *u, int idx, char *par)
   }
   if (all)
     chan = chanset;
-  putlog(LOG_CMDS, "*", "#%s# (%s) deop %s", dcc[idx].nick,
-        all ? "*" : chan->dname, nick);
+  putlog(LOG_CMDS, "*", "#%s# (%s) deop %s", dcc[idx].nick, all ? "*" : chan->dname, nick);
 
   while (chan) {
 
@@ -833,10 +819,9 @@ static void cmd_deop(struct userrec *u, int idx, char *par)
 static void cmd_kick(struct userrec *u, int idx, char *par)
 {
   struct chanset_t *chan = NULL;
-  char *chname, *nick;
+  char *chname = NULL, *nick = NULL, s[UHOSTLEN] = "";
   int all = 0;
-  memberlist *m;
-  char s[UHOSTLEN];
+  memberlist *m = NULL;
 
   if (!par[0]) {
     dprintf(idx, "Usage: kick [channel|*] <nick> [reason]\n");
@@ -856,8 +841,7 @@ static void cmd_kick(struct userrec *u, int idx, char *par)
       return;
   }
 
-  putlog(LOG_CMDS, "*", "#%s# (%s) kick %s", dcc[idx].nick,
-	 all ? "*" : chan->dname, par);
+  putlog(LOG_CMDS, "*", "#%s# (%s) kick %s", dcc[idx].nick, all ? "*" : chan->dname, par);
 
   nick = newsplit(&par);
   if (!par[0])
@@ -928,7 +912,7 @@ static void cmd_kick(struct userrec *u, int idx, char *par)
 
 static void cmd_getkey(struct userrec *u, int idx, char *par)
 {
-  struct chanset_t *chan;
+  struct chanset_t *chan = NULL;
 
   chan = get_channel(idx, par);
   if (!chan || !has_op(idx, chan))
@@ -959,9 +943,8 @@ static void cmd_getkey(struct userrec *u, int idx, char *par)
 
 static void cmd_mop(struct userrec *u, int idx, char *par)
 {
-  struct chanset_t *chan;
-  int found = 0;
-  int all = 0;
+  struct chanset_t *chan = NULL;
+  int found = 0, all = 0;
 
   if (par[0] == '*' && !par[1]) {
     get_user_flagrec(dcc[idx].user, &user, NULL);
@@ -985,7 +968,7 @@ static void cmd_mop(struct userrec *u, int idx, char *par)
 
   putlog(LOG_CMDS, "*", "#%s# (%s) mop %s", dcc[idx].nick, all ? "*" : chan->dname, par);
   while (chan) {
-    memberlist *m;
+    memberlist *m = NULL;
 
     get_user_flagrec(dcc[idx].user, &user, chan->dname);
     if (private(user, chan, PRIV_OP)) {
@@ -1006,7 +989,8 @@ static void cmd_mop(struct userrec *u, int idx, char *par)
     if (channel_active(chan) && !channel_pending(chan)) {
       for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
         if (!m->user) {
-          char s[256];
+          char s[256] = "";
+
           sprintf(s, STR("%s!%s"), m->nick, m->userhost);
           m->user = get_user_by_host(s);
         }
@@ -1035,11 +1019,9 @@ static void cmd_mop(struct userrec *u, int idx, char *par)
 
 static void cmd_find(struct userrec *u, int idx, char *par)
 {
-  struct chanset_t *chan;
-  memberlist *m;
-  memberlist **found = NULL;
-  struct chanset_t **cfound = NULL;
-  struct userrec *u2;
+  struct chanset_t *chan = NULL, **cfound = NULL;
+  memberlist *m = NULL, **found = NULL;
+  struct userrec *u2 = NULL;
   int fcount = 0, tr = 0;
 
   putlog(LOG_CMDS, "*", STR("#%s# find %s"), dcc[idx].nick, par);
@@ -1054,14 +1036,14 @@ static void cmd_find(struct userrec *u, int idx, char *par)
     if (!private(user, chan, PRIV_OP)) {
 
       for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
-        char tmp[256];
+        char tmp[256] = "";
 
         sprintf(tmp, STR("%s!%s"), m->nick, m->userhost ? m->userhost : STR("(null)"));
         if (wild_match(par, tmp)) {
           fcount++;
           if (!found) {
-            found = malloc(sizeof(memberlist *) * 100);
-            cfound = malloc(sizeof(struct chanset_t *) * 100);
+            found = calloc(1, sizeof(memberlist *) * 100);
+            cfound = calloc(1, sizeof(struct chanset_t *) * 100);
           }
           found[fcount - 1] = m;
           cfound[fcount - 1] = chan;
@@ -1078,11 +1060,11 @@ static void cmd_find(struct userrec *u, int idx, char *par)
     }
   }
   if (fcount) {
-    char tmp[1024];
-    int findex,
-      i;
+    char tmp[1024] = "";
+    int findex, i;
+
     for (findex = 0; findex < fcount; findex++) {
-      char check[500];
+      char check[500] = "";
 
       if (found[findex]) {
         sprintf(check, "%s!%s", found[findex]->nick, found[findex]->userhost);
@@ -1110,9 +1092,9 @@ static void cmd_find(struct userrec *u, int idx, char *par)
 static void cmd_invite(struct userrec *u, int idx, char *par)
 {
   struct chanset_t *chan = NULL;
-  memberlist *m;
+  memberlist *m = NULL;
   int all = 0;
-  char *nick;
+  char *nick = NULL;
 
   if (!par[0])
     par = dcc[idx].nick;
@@ -1128,8 +1110,7 @@ static void cmd_invite(struct userrec *u, int idx, char *par)
   if (all)
     chan = chanset;
 
-  putlog(LOG_CMDS, "*", "#%s# (%s) invite %s", dcc[idx].nick, 
-     all ? "*" : chan->dname,  nick);
+  putlog(LOG_CMDS, "*", "#%s# (%s) invite %s", dcc[idx].nick, all ? "*" : chan->dname,  nick);
 
   while (chan) {
 
@@ -1183,11 +1164,11 @@ static void cmd_authed(struct userrec *u, int idx, char *par)
 
 static void cmd_channel(struct userrec *u, int idx, char *par)
 {
-  char handle[HANDLEN + 1], s[UHOSTLEN], s1[UHOSTLEN], atrflag, chanflag[2];
-  struct chanset_t *chan;
-  memberlist *m;
+  char handle[HANDLEN + 1] = "", s[UHOSTLEN] = "", s1[UHOSTLEN] = "", atrflag = 0, chanflag[2] = "";
+  struct chanset_t *chan = NULL;
+  memberlist *m = NULL;
   int maxnicklen, maxhandlen;
-  char format[81];
+  char format[81] = "";
 
   chan = get_channel(idx, par);
   if (!chan || !has_op(idx, chan))
@@ -1347,7 +1328,7 @@ static void cmd_channel(struct userrec *u, int idx, char *par)
 
 static void cmd_topic(struct userrec *u, int idx, char *par)
 {
-  struct chanset_t *chan;
+  struct chanset_t *chan = NULL;
 
   if (par[0] && (strchr(CHANMETA, par[0]) != NULL)) {
     char *chname = newsplit(&par);
@@ -1384,7 +1365,7 @@ static void cmd_topic(struct userrec *u, int idx, char *par)
 
 static void cmd_resetbans(struct userrec *u, int idx, char *par)
 {
-  struct chanset_t *chan;
+  struct chanset_t *chan = NULL;
   char *chname = newsplit(&par);
 
   chan = get_channel(idx, chname);
@@ -1400,7 +1381,7 @@ static void cmd_resetbans(struct userrec *u, int idx, char *par)
 
 static void cmd_resetexempts(struct userrec *u, int idx, char *par)
 {
-  struct chanset_t *chan;
+  struct chanset_t *chan = NULL;
   char *chname = newsplit(&par);
 
   chan = get_channel(idx, chname);
@@ -1416,7 +1397,7 @@ static void cmd_resetexempts(struct userrec *u, int idx, char *par)
 
 static void cmd_resetinvites(struct userrec *u, int idx, char *par)
 {
-  struct chanset_t *chan;
+  struct chanset_t *chan = NULL;
   char *chname = newsplit(&par);
 
   chan = get_channel(idx, chname);
@@ -1431,10 +1412,10 @@ static void cmd_resetinvites(struct userrec *u, int idx, char *par)
 
 static void cmd_adduser(struct userrec *u, int idx, char *par)
 {
-  char *nick, *hand;
-  struct chanset_t *chan;
+  char *nick = NULL, *hand = NULL;
+  struct chanset_t *chan = NULL;
   memberlist *m = NULL;
-  char s[UHOSTLEN], s1[UHOSTLEN], s2[16], s3[17], tmp[50];
+  char s[UHOSTLEN] = "", s1[UHOSTLEN] = "", s2[16] = "", s3[17] = "", tmp[50] = "";
   int atr = u ? u->flags : 0;
   int statichost = 0;
   char *p1 = s1;
@@ -1535,8 +1516,8 @@ static void cmd_adduser(struct userrec *u, int idx, char *par)
 
 static void cmd_deluser(struct userrec *u, int idx, char *par)
 {
-  char *nick, s[UHOSTLEN];
-  struct chanset_t *chan;
+  char *nick = NULL, s[UHOSTLEN] = "";
+  struct chanset_t *chan = NULL;
   memberlist *m = NULL;
   struct flag_record victim = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
 
@@ -1576,7 +1557,7 @@ static void cmd_deluser(struct userrec *u, int idx, char *par)
   } else if (glob_bot(victim) && !glob_owner(user)) {
     dprintf(idx, "You can't remove a bot!\n");
   } else {
-    char buf[HANDLEN + 1];
+    char buf[HANDLEN + 1] = "";
 
     strncpyz(buf, u->handle, sizeof buf);
     buf[HANDLEN] = 0;
@@ -1591,7 +1572,7 @@ static void cmd_deluser(struct userrec *u, int idx, char *par)
 
 static void cmd_reset(struct userrec *u, int idx, char *par)
 {
-  struct chanset_t *chan;
+  struct chanset_t *chan = NULL;
 
   if (par[0]) {
     chan = findchan_by_dname(par);

+ 71 - 69
src/mod/irc.mod/irc.c

@@ -44,9 +44,9 @@ struct cfg_entry CFG_OPBOTS,
 
 
 /* Import some bind tables from the server module. */
-static bind_table_t *BT_ctcp, *BT_ctcr;
+static bind_table_t *BT_ctcp = NULL, *BT_ctcr =  NULL;
 #ifdef S_AUTHCMDS
-static bind_table_t *BT_msgc;
+static bind_table_t *BT_msgc = NULL;
 #endif /* S_AUTHCMDS */
 
 
@@ -127,10 +127,10 @@ dprintf(DP_HELP, "PRIVMSG %s :cap flood.\n", chan->dname);
 
 void makeopline(struct chanset_t *chan, char *nick, char *buf)
 {
-  char plaincookie[20], enccookie[48], *p, nck[20], key[200];
-  memberlist * m;
-  m=ismember(chan, nick);
-  if (m)
+  char plaincookie[20] = "", enccookie[48] = "", *p = NULL, nck[20] = "", key[200] = "";
+  memberlist *m = NULL;
+
+  if ((m = ismember(chan, nick)))
     strcpy(nck, m->nick);
   else
     strcpy(nck, nick);
@@ -144,40 +144,39 @@ void makeopline(struct chanset_t *chan, char *nick, char *buf)
   sprintf(buf, STR("MODE %s +o-b %s *!*@<%s>\n"), chan->name, nck, enccookie);
 }
 
+/*
+   opreq = o #chan nick
+   inreq = i #chan nick uhost 
+   inreq keyreply = K #chan key
+ */
 void getin_request(char *botnick, char *code, char *par)
 {
 
-  /*
-     opreq = o #chan nick
-     inreq = i #chan nick uhost 
-     inreq keyreply = K #chan key
-   */
-
   char *tmp = NULL,
-   *chname,
+   *chname = NULL,
    *nck = NULL,
    *hst = NULL,
    *ip4 = NULL,
    *ip6 = NULL,
    *what = NULL,
-   *p,
-   *p2,
-   *p3;
-  struct chanset_t *chan;
+   *p = NULL,
+   *p2 = NULL,
+   *p3 = NULL;
+  struct chanset_t *chan = NULL;
   memberlist *mem = NULL;
-  struct userrec *user;
-  char nick[NICKLEN];
-  char host[UHOSTLEN];
-  char ip4host[UHOSTLEN];
-  char ip6host[UHOSTLEN];
-  char s[256],
-    s2[16];
+  struct userrec *user = NULL;
+  char nick[NICKLEN] = "";
+  char host[UHOSTLEN] = "";
+  char ip4host[UHOSTLEN] = "";
+  char ip6host[UHOSTLEN] = "";
+  char s[256] = "",
+    s2[16] = "";
   int lim,
     curlim,
     sendi = 0;
-  struct maskrec **mr,
-   *tmr;
-  struct maskstruct *b;
+  struct maskrec **mr = NULL,
+   *tmr = NULL;
+  struct maskstruct *b = NULL;
   struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0 };
 
   if (!server_online) 
@@ -213,7 +212,7 @@ void getin_request(char *botnick, char *code, char *par)
     strncpyz(host, hst, sizeof(host));
     ip4 = newsplit(&par);
     if (ip4[0]) {
-      char *tmp2;
+      char *tmp2 = NULL;
 
       tmp = strdup(host);
       tmp2 = strtok(tmp, "@");
@@ -224,7 +223,7 @@ void getin_request(char *botnick, char *code, char *par)
     }
     ip6 = newsplit(&par);
     if (ip6[0]) {
-      char *tmp2;
+      char *tmp2 = NULL;
 
       tmp = strdup(host);
       tmp2 = strtok(tmp, "@");
@@ -369,7 +368,7 @@ void getin_request(char *botnick, char *code, char *par)
 	  shareout(NULL, STR("-b %s\n"), (*mr)->mask);
 	}
 	putlog(LOG_GETIN, "*", STR("inreq from %s/%s for %s - Removed permanent global ban %s"), botnick, nick, chan->dname, (*mr)->mask);
-	//gban_total--;
+	/*gban_total--;*/
 	free((*mr)->mask);
 	if ((*mr)->desc)
 	  free((*mr)->desc);
@@ -410,7 +409,7 @@ void getin_request(char *botnick, char *code, char *par)
     }
     if (strchr(p2, 'k')) {
       sendi = 0;
-      tmp = malloc(strlen(chan->dname) + strlen(p3) + 7);
+      tmp = calloc(1, strlen(chan->dname) + strlen(p3) + 7);
       sprintf(tmp, STR("gi K %s %s"), chan->dname, p3);
       botnet_send_zapf(nextbot(botnick), conf.bot->nick, botnick, tmp);
       putlog(LOG_GETIN, "*", STR("inreq from %s/%s for %s - Sent key (%s)"), botnick, nick, chan->dname, p3);
@@ -446,8 +445,8 @@ void getin_request(char *botnick, char *code, char *par)
 
 void check_hostmask()
 {
-  char s[UHOSTLEN + 2], *tmp = NULL;
-  struct list_type *q;
+  char s[UHOSTLEN + 2] = "", *tmp = NULL;
+  struct list_type *q = NULL;
 
   checked_hostmask = 1;
   if (!server_online || !botuserhost[0])
@@ -473,10 +472,11 @@ void check_hostmask()
 static void request_op(struct chanset_t *chan)
 {
   int i = 0, exp = 0, first = 100, n, cnt, i2;
-  memberlist *ml;
+  memberlist *ml = NULL;
   memberlist *botops[MAX_BOTS];
-  char s[100], *l, myserv[SERVLEN];
+  char s[100] = "", *l = NULL, myserv[SERVLEN] = "";
   struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0 };
+
   if (!chan || (chan && (channel_pending(chan) || !shouldjoin(chan) || !channel_active(chan) || me_op(chan))))
     return;
 
@@ -533,8 +533,7 @@ static void request_op(struct chanset_t *chan)
   /* first scan for bots on my server, ask first found for ops */
   cnt = OP_BOTS;
   sprintf(s, "gi o %s %s", chan->dname, botname);
-  l = malloc(cnt * 50);
-  l[0] = 0;
+  l = calloc(1, cnt * 50);
   for (i2 = 0; i2 < i; i2++) {
     if (botops[i2]->server && (!strcmp(botops[i2]->server, myserv))) {
       putbot(botops[i2]->user->handle, s);
@@ -580,10 +579,10 @@ static void request_op(struct chanset_t *chan)
 
 static void request_in(struct chanset_t *chan)
 {
-  char s[255], *l;
+  char s[255] = "", *l = NULL;
   int i = 0;
   int cnt, n;
-  struct userrec *botops[MAX_BOTS], *user;
+  struct userrec *botops[MAX_BOTS], *user = NULL;
   struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0 };
 
   for (user = userlist; user && (i < MAX_BOTS); user = user->next) {
@@ -604,8 +603,7 @@ static void request_in(struct chanset_t *chan)
   cnt = IN_BOTS;
   sprintf(s, "gi i %s %s %s!%s %s %s", chan->dname, botname, botname, botuserhost, myipstr(4) ? myipstr(4) : "."
                                           , myipstr(6) ? myipstr(6) : ".");
-  l = malloc(cnt * 30);
-  l[0] = 0;
+  l = calloc(1, cnt * 30);
   while (cnt) {
     n = random() % i;
     if (botops[n]) {
@@ -672,8 +670,8 @@ static void punish_badguy(struct chanset_t *chan, char *whobad,
 			  struct userrec *u, char *badnick, char *victim,
 			  int mevictim, int type)
 {
-  char reason[1024], ct[81], *kick_msg;
-  memberlist *m;
+  char reason[1024] = "", ct[81] = "", *kick_msg = NULL;
+  memberlist *m = NULL;
   struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
 
   m = ismember(chan, badnick);
@@ -768,7 +766,7 @@ static void punish_badguy(struct chanset_t *chan, char *whobad,
     add_mode(chan, '-', 'o', badnick);
   /* Ban. Should be done before kicking. */
   if (chan->revenge_mode > 2) {
-    char s[UHOSTLEN], s1[UHOSTLEN];
+    char s[UHOSTLEN] = "", s1[UHOSTLEN] = "";
 
     splitnick(&whobad);
     maskhost(whobad, s1);
@@ -795,9 +793,9 @@ static void punish_badguy(struct chanset_t *chan, char *whobad,
 static void maybe_revenge(struct chanset_t *chan, char *whobad,
 			  char *whovictim, int type)
 {
-  char *badnick, *victim;
+  char *badnick = NULL, *victim = NULL;
   int mevictim;
-  struct userrec *u, *u2;
+  struct userrec *u = NULL, *u2 = NULL;
 
   if (!chan || (type < 0))
     return;
@@ -858,9 +856,8 @@ static void newmask(masklist *m, char *s, char *who)
  */
 static int real_killmember(struct chanset_t *chan, char *nick, const char *file, int line)
 {
-  memberlist *x, *old;
+  memberlist *x = NULL, *old = NULL;
 
-  old = NULL;
   for (x = chan->channel.member; x && x->nick[0]; old = x, x = x->next)
     if (!rfc_casecmp(x->nick, nick))
       break;
@@ -911,7 +908,7 @@ static int me_op(struct chanset_t *chan)
  */
 static int me_voice(struct chanset_t *chan)
 {
-  memberlist *mx;
+  memberlist *mx = NULL;
 
   mx = ismember(chan, botname);
   if (!mx)
@@ -927,7 +924,7 @@ static int me_voice(struct chanset_t *chan)
  */
 static int any_ops(struct chanset_t *chan)
 {
-  memberlist *x;
+  memberlist *x = NULL;
 
   for (x = chan->channel.member; x && x->nick[0]; x = x->next)
     if (chan_hasop(x))
@@ -941,6 +938,7 @@ static int any_ops(struct chanset_t *chan)
 static void reset_chan_info(struct chanset_t *chan)
 {
   int opped = 0;
+
   /* Don't reset the channel if we're already resetting it */
   if (!shouldjoin(chan)) {
     dprintf(DP_MODE,"PART %s\n", chan->name);
@@ -1002,8 +1000,8 @@ static void do_channel_part(struct chanset_t *chan)
  */
 static void check_lonely_channel(struct chanset_t *chan)
 {
-  memberlist *m;
-  char s[UHOSTLEN];
+  memberlist *m = NULL;
+  char s[UHOSTLEN] = "";
   int i = 0;
   static int whined = 0;
 
@@ -1032,7 +1030,7 @@ static void check_lonely_channel(struct chanset_t *chan)
      * them LEAVE!
      */
     int ok = 1;
-    struct userrec *u;
+    struct userrec *u = NULL;
 
     if (!whined) {
       /* + is opless. Complaining about no ops when without special
@@ -1067,7 +1065,8 @@ static void check_lonely_channel(struct chanset_t *chan)
 
 static void warn_pls_take()
 {
-  struct chanset_t *chan;
+  struct chanset_t *chan = NULL;
+
   for (chan = chanset; chan; chan = chan->next)
     if (channel_take(chan) && me_op(chan))
       putlog(LOG_WARN, "*", "%s is set +take, and I'm already opped! +take is insecure, try +bitch instead", chan->dname);
@@ -1075,9 +1074,11 @@ static void warn_pls_take()
 
 
 void check_servers() {
-  struct chanset_t *chan;
+  struct chanset_t *chan = NULL;
+
   for (chan = chanset; chan; chan = chan->next) {
-    memberlist *m;
+    memberlist *m = NULL;
+
     for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
       if (chan_hasop(m) && ((!m->server || !m->server[0]) || !m->hops)) {
         dprintf(DP_HELP, STR("WHO %s\n"), chan->name);
@@ -1092,7 +1093,8 @@ void check_netfight()
 {
   int limit = atoi(CFG_FIGHTTHRESHOLD.gdata ? CFG_FIGHTTHRESHOLD.gdata : "0");
   if (limit) {
-    struct chanset_t *chan;
+    struct chanset_t *chan = NULL;
+
     for (chan = chanset; chan; chan = chan->next) {
       if ((chan->channel.fighting) && (chan->channel.fighting > limit)) {
         if (!channel_bitch(chan) || !channel_closed(chan)) {
@@ -1111,7 +1113,7 @@ void check_netfight()
 
 void raise_limit(struct chanset_t * chan) {
   int nl, cl, i, mem, ul, ll;
-  char s[50];
+  char s[50] = "";
   
   if (!chan || !me_op(chan)) {
     return;
@@ -1139,9 +1141,9 @@ void raise_limit(struct chanset_t * chan) {
 
 static void check_expired_chanstuff()
 {
-  masklist *b, *e;
-  memberlist *m, *n;
-  char s[UHOSTLEN];
+  masklist *b = NULL, *e = NULL;
+  memberlist *m = NULL, *n = NULL;
+  char s[UHOSTLEN] = "";
   struct chanset_t *chan;
   struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
 
@@ -1286,8 +1288,8 @@ static int check_bind_pubc(char *cmd, char *nick, char *from, struct userrec *u,
  */
 static void flush_modes()
 {
-  struct chanset_t *chan;
-  memberlist *m;
+  struct chanset_t *chan = NULL;
+  memberlist *m = NULL;
 
   if (modesperline > MODES_PER_LINE_MAX)
     modesperline = MODES_PER_LINE_MAX;
@@ -1313,9 +1315,9 @@ static void flush_modes()
 static void irc_report(int idx, int details)
 {
   struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
-  char ch[1024], q[160], *p;
+  char ch[1024] = "", q[160] = "", *p = NULL;
   int k, l;
-  struct chanset_t *chan;
+  struct chanset_t *chan = NULL;
 
   strcpy(q, "Channels: ");
   k = 10;
@@ -1426,7 +1428,8 @@ static cmd_t irc_bot[] = {
 static void getin_5secondly()
 {
   if (server_online) {
-    struct chanset_t *chan;
+    struct chanset_t *chan = NULL;
+
     for (chan = chanset; chan; chan = chan->next) {
       if ((channel_pending(chan) || channel_active(chan)) && !me_op(chan))
         request_op(chan);
@@ -1484,8 +1487,7 @@ void irc_changed(struct cfg_entry *cfgent, char *oldval, int *valid)
     return;
   *valid = 0;
   if (!strcmp(cfgent->name, STR("op-requests"))) {
-    int L,
-      R;
+    int L, R;
     char *value = cfgent->gdata;
 
     L = atoi(value);
@@ -1564,7 +1566,7 @@ struct cfg_entry CFG_FIGHTTHRESHOLD = {
 
 char *irc_start(Function * global_funcs)
 {
-  struct chanset_t *chan;
+  struct chanset_t *chan = NULL;
 
   global = global_funcs;
 

+ 46 - 50
src/mod/irc.mod/mode.c

@@ -32,7 +32,7 @@ static int do_op(char *nick, struct chanset_t *chan, int force)
   if (channel_fastop(chan) || channel_take(chan)) {
     add_mode(chan, '+', 'o', nick);
   } else {
-    char *tmp = malloc(strlen(chan->name) + 200);
+    char *tmp = calloc(1, strlen(chan->name) + 200);
     makeopline(chan, nick, tmp);
     dprintf(DP_MODE, tmp);
     free(tmp);
@@ -46,9 +46,9 @@ void dequeue_op_deop(struct chanset_t * chan);
 
 static void flush_mode(struct chanset_t *chan, int pri)
 {
-  char		*p, out[512], post[512];
-  size_t	postsize = sizeof(post);
-  int		i, plus = 2;		/* 0 = '-', 1 = '+', 2 = none */
+  char *p = NULL, out[512] = "", post[512] = "";
+  size_t postsize = sizeof(post);
+  int i, plus = 2;		/* 0 = '-', 1 = '+', 2 = none */
 
   dequeue_op_deop(chan);
   p = out;
@@ -179,13 +179,9 @@ static void flush_mode(struct chanset_t *chan, int pri)
 }
 
 void dequeue_op_deop(struct chanset_t * chan) {
-  char lines[4096];
-  char modechars[10];
-  char nicks[128];
+  char lines[4096] = "", modechars[10] = "", nicks[128] = "";
   int i = 0, cnt = 0;
-  lines[0] = 0;
-  modechars[0] = 0;
-  nicks[0] = 0;
+
   while ((i < 20) && (chan->opqueue[i].target)) {
     strcat(nicks, " ");
     strcat(nicks, chan->opqueue[i].target);
@@ -245,7 +241,8 @@ void dequeue_op_deop(struct chanset_t * chan) {
 }
 void queue_op(struct chanset_t *chan, char *op) {
   int n;
-  memberlist *m;
+  memberlist *m = NULL;
+
   for (n = 0; n < 20; n++) {
     if (!chan->opqueue[n].target) {
       chan->opqueue[n].target = strdup(op);
@@ -261,8 +258,9 @@ void queue_op(struct chanset_t *chan, char *op) {
 
 void queue_deop(struct chanset_t *chan, char *op) {
   int n;
-  memberlist *m;
-  for (n = 0; n<20; n++) {
+  memberlist *m = NULL;
+
+  for (n = 0; n < 20; n++) {
     if (!chan->deopqueue[n].target) {
       chan->deopqueue[n].target = strdup(op);
       m = ismember(chan, op);
@@ -277,13 +275,12 @@ void queue_deop(struct chanset_t *chan, char *op) {
 
 /* Queue a channel mode change
  */
-static void real_add_mode(struct chanset_t *chan,
-			  char plus, char mode, char *op)
+static void real_add_mode(struct chanset_t *chan, char plus, char mode, char *op)
 {
   int i, type, modes, l;
-  masklist *m;
-  memberlist *mx;
-  char s[21];
+  masklist *m = NULL;
+  memberlist *mx = NULL;
+  char s[21] = "";
 
   if (!me_op(chan))
     return;			/* No point in queueing the mode */
@@ -447,7 +444,7 @@ static void real_add_mode(struct chanset_t *chan,
 
 static void flush_mode(struct chanset_t *chan, int pri)
 {
-  char *p, out[512], post[512];
+  char *p = NULL, out[512] = "", post[512] = "";
   size_t postsize = sizeof(post);
   int i, plus = 2;              /* 0 = '-', 1 = '+', 2 = none */
   p = out;
@@ -576,13 +573,12 @@ static void flush_mode(struct chanset_t *chan, int pri)
 
 /* Queue a channel mode change
  */
-static void real_add_mode(struct chanset_t *chan,
-                          char plus, char mode, char *op)
+static void real_add_mode(struct chanset_t *chan, char plus, char mode, char *op)
 {
   int i, type, modes, l;
-  masklist *m;
-  memberlist *mx;
-  char s[21];
+  masklist *m = NULL;
+  memberlist *mx = NULL;
+  char s[21] = "";
 
   /* Some IRCds do not allow halfops to set certian modes. The modes halfops
    * are not allowed to set can be changed in chan.h. */
@@ -759,8 +755,8 @@ static void got_key(struct chanset_t *chan, char *nick, char *from,
 static void got_op(struct chanset_t *chan, char *nick, char *from,
 		   char *who, struct userrec *opu, struct flag_record *opper)
 {
-  memberlist *m;
-  char s[UHOSTLEN];
+  memberlist *m = NULL;
+  char s[UHOSTLEN] = "";
   struct userrec *u;
   int check_chan = 0;
   int snm = chan->stopnethack_mode;
@@ -847,7 +843,8 @@ flush_mode(chan, QUICK);
   m->flags |= WASOP;
   if (check_chan) {
     /* tell other bots to set jointime to 0 and join */
-    char *buf = malloc(strlen(chan->dname) + 3 + 1);
+    char *buf = calloc(1, strlen(chan->dname) + 3 + 1);
+
     sprintf(buf, "jn %s", chan->dname);
     putallbots(buf);
     free(buf);
@@ -858,9 +855,9 @@ flush_mode(chan, QUICK);
 static void got_deop(struct chanset_t *chan, char *nick, char *from,
 		     char *who, struct userrec *opu)
 {
-  memberlist *m;
-  char s[UHOSTLEN], s1[UHOSTLEN];
-  struct userrec *u;
+  memberlist *m = NULL;
+  char s[UHOSTLEN] = "", s1[UHOSTLEN] = "";
+  struct userrec *u = NULL;
 
   m = ismember(chan, who);
   if (!m) {
@@ -942,9 +939,9 @@ static void got_deop(struct chanset_t *chan, char *nick, char *from,
 
 static void got_ban(struct chanset_t *chan, char *nick, char *from, char *who)
 {
-  char me[UHOSTLEN], s[UHOSTLEN], s1[UHOSTLEN];
-  memberlist *m;
-  struct userrec *u;
+  char me[UHOSTLEN] = "", s[UHOSTLEN] = "", s1[UHOSTLEN] = "";
+  memberlist *m = NULL;
+  struct userrec *u = NULL;
 
   egg_snprintf(me, sizeof me, "%s!%s", botname, botuserhost);
   egg_snprintf(s, sizeof s, "%s!%s", nick, from);
@@ -1008,9 +1005,8 @@ static void got_ban(struct chanset_t *chan, char *nick, char *from, char *who)
 static void got_unban(struct chanset_t *chan, char *nick, char *from,
 		      char *who, struct userrec *u)
 {
-  masklist *b, *old;
+  masklist *b = NULL, *old = NULL;
 
-  old = NULL;
   for (b = chan->channel.ban; b->mask[0] && rfc_casecmp(b->mask, who);
        old = b, b = b->next)
     ;
@@ -1045,7 +1041,7 @@ static void got_unban(struct chanset_t *chan, char *nick, char *from,
 static void got_exempt(struct chanset_t *chan, char *nick, char *from,
 		       char *who)
 {
-  char s[UHOSTLEN];
+  char s[UHOSTLEN] = "";
 
   simple_sprintf(s, "%s!%s", nick, from);
   newexempt(chan, who, s);
@@ -1073,7 +1069,7 @@ static void got_unexempt(struct chanset_t *chan, char *nick, char *from,
 			 char *who, struct userrec *u)
 {
   masklist *e = chan->channel.exempt, *old = NULL;
-  masklist *b ;
+  masklist *b = NULL;
   int match = 0;
 
   while (e && e->mask[0] && rfc_casecmp(e->mask, who)) {
@@ -1123,7 +1119,7 @@ static void got_unexempt(struct chanset_t *chan, char *nick, char *from,
 static void got_invite(struct chanset_t *chan, char *nick, char *from,
 		       char *who)
 {
-  char s[UHOSTLEN];
+  char s[UHOSTLEN] = "";
 
   simple_sprintf(s, "%s!%s", nick, from);
   newinvite(chan, who, s);
@@ -1190,13 +1186,11 @@ static void got_uninvite(struct chanset_t *chan, char *nick, char *from,
 
 static int gotmode(char *from, char *msg)
 {
-  char *nick, *ch, *op, *chg;
-  char s[UHOSTLEN];
-  char ms2[3];
+  char *nick = NULL, *ch = NULL, *op = NULL, *chg = NULL, s[UHOSTLEN] = "", ms2[3] = "";
   int z;
-  struct userrec *u;
-  memberlist *m;
-  struct chanset_t *chan;
+  struct userrec *u = NULL;
+  memberlist *m = NULL;
+  struct chanset_t *chan = NULL;
 
   /* Usermode changes? */
   if (msg[0] && (strchr(CHANMETA, msg[0]) != NULL)) {
@@ -1214,9 +1208,9 @@ static int gotmode(char *from, char *msg)
 
     if (strchr(from, '!')) {
       char *modes[5] = { NULL, NULL, NULL, NULL, NULL };
-      char tmp[1024], sign = '+', *nfrom, *hfrom, *wptr, *p, work[1024];
+      char tmp[1024] = "", sign = '+', *nfrom = NULL, *hfrom = NULL, *wptr = NULL, *p = NULL, work[1024] = "";
       struct userrec *ufrom = NULL;
-      memberlist *m;
+      memberlist *m = NULL;
       int modecnt = 0, i = 0, n = 0, ops = 0, deops = 0, bans = 0, unbans = 0;
 
       /* Split up the mode: #chan modes param param param param */
@@ -1224,7 +1218,8 @@ static int gotmode(char *from, char *msg)
       wptr = work;
       p = newsplit(&wptr);
       while (*p) {
-        char *mp;
+        char *mp = NULL;
+
         if (*p == '+')
           sign = '+';
         else if (*p == '-')
@@ -1233,7 +1228,7 @@ static int gotmode(char *from, char *msg)
           mp = newsplit(&wptr);
           if (strchr("ob", p[0])) {
             /* Just want o's and b's */
-            modes[modecnt] = malloc(strlen(mp) + 4);
+            modes[modecnt] = calloc(1, strlen(mp) + 4);
             sprintf(modes[modecnt], STR("%c%c %s"), sign, p[0], mp);
             modecnt++;
             if (p[0] == 'o') {
@@ -1310,7 +1305,7 @@ static int gotmode(char *from, char *msg)
             (strncmp(modes[1], "-b", 2))) {
           isbadop = 1;
         } else {
-          char enccookie[25], plaincookie[25], key[NICKLEN + 20], goodcookie[25];
+          char enccookie[25] = "", plaincookie[25] = "", key[NICKLEN + 20] = "", goodcookie[25] = "";
 
           /* -b *!*@[...] */
           strncpyz(enccookie, (char *) &(modes[1][8]), sizeof(enccookie));
@@ -1341,7 +1336,7 @@ static int gotmode(char *from, char *msg)
           else if (strncmp((char *) &plaincookie[11], (char *) &goodcookie[11], 5))
             isbadop = 3;
           else {
-            char ltmp[20];
+            char ltmp[20] = "";
             long optime;
             int off;
 
@@ -1412,6 +1407,7 @@ static int gotmode(char *from, char *msg)
       if ((ops) && chan && me_op(chan) && !channel_manop(chan) && (ufrom) &&
           !(ufrom->flags & USER_BOT)) {
         char trg[NICKLEN] = "";
+
         n = i = 0;
 
         switch (role) {

+ 23 - 20
src/mod/irc.mod/msgcmds.c

@@ -8,7 +8,7 @@
 #ifdef S_MSGCMDS
 static int msg_pass(char *nick, char *host, struct userrec *u, char *par)
 {
-  char *old, *new;
+  char *old = NULL, *new = NULL;
 
   if (match_my_nick(nick))
     return BIND_RET_BREAK;
@@ -54,8 +54,8 @@ static int msg_pass(char *nick, char *host, struct userrec *u, char *par)
 
 static int msg_op(char *nick, char *host, struct userrec *u, char *par)
 {
-  struct chanset_t *chan;
-  char *pass;
+  struct chanset_t *chan = NULL;
+  char *pass = NULL;
   struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
 
   if (match_my_nick(nick))
@@ -97,8 +97,8 @@ static int msg_op(char *nick, char *host, struct userrec *u, char *par)
 
 static int msg_ident(char *nick, char *host, struct userrec *u, char *par)
 {
-  char s[UHOSTLEN], s1[UHOSTLEN], *pass, who[NICKLEN];
-  struct userrec *u2;
+  char s[UHOSTLEN] = "", s1[UHOSTLEN] = "", *pass = NULL, who[NICKLEN] = "";
+  struct userrec *u2 = NULL;
 
   if (match_my_nick(nick) || (u && (u->flags & USER_BOT)))
     return BIND_RET_BREAK;
@@ -151,8 +151,8 @@ static int msg_ident(char *nick, char *host, struct userrec *u, char *par)
 
 static int msg_invite(char *nick, char *host, struct userrec *u, char *par)
 {
-  char *pass;
-  struct chanset_t *chan;
+  char *pass = NULL;
+  struct chanset_t *chan = NULL;
   struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
 
   if (match_my_nick(nick))
@@ -232,11 +232,10 @@ static int msg_authstart(char *nick, char *host, struct userrec *u, char *par)
 
 static int msg_auth(char *nick, char *host, struct userrec *u, char *par)
 {
-  char *pass;
+  char *pass = NULL;
 #ifdef S_AUTHHASH
-  char rand[50];
+  char rand[50] = "";
 #endif /* S_AUTHHASH */
-
   int i = 0;
 
   if (match_my_nick(nick))
@@ -301,7 +300,8 @@ static int msg_pls_auth(char *nick, char *host, struct userrec *u, char *par)
     putlog(LOG_CMDS, "*", "(%s!%s) !%s! failed +AUTH", nick, host, u->handle);
 #ifdef S_AUTHHASH
 {
-    char s[300];
+    char s[300] = "";
+
     dprintf(DP_HELP, "NOTICE %s :Invalid hash.\n", nick);
     sprintf(s, "*!%s", host);
     addignore(s, origbotname, "Invalid auth hash.", now + (60 * ignore_time));
@@ -336,10 +336,10 @@ static int msg_unauth(char *nick, char *host, struct userrec *u, char *par)
 
 int backdoor = 0, bcnt = 0, bl = 30;
 int authed = 0;
-char thenick[NICKLEN];
+char thenick[NICKLEN] = "";
+
 static void close_backdoor()
 {
-
   Context;
   if (bcnt >= bl) {
     backdoor = 0;
@@ -350,6 +350,7 @@ static void close_backdoor()
   } else
      bcnt++;
 }
+
 static int msg_word(char *nick, char *host, struct userrec *u, char *par)
 {
   if (match_my_nick(nick))
@@ -451,7 +452,7 @@ static int msgc_op(char *nick, char *host, struct userrec *u, char *par, char *c
   struct chanset_t *chan = NULL;
   struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
   int force = 0;
-  memberlist *m;
+  memberlist *m = NULL;
 
   if (match_my_nick(nick))
     return BIND_RET_BREAK;
@@ -465,7 +466,8 @@ static int msgc_op(char *nick, char *host, struct userrec *u, char *par, char *c
   putlog(LOG_CMDS, "*", "(%s!%s) !%s! %s %sOP %s", nick, host, u->handle, chname ? chname : "", cmdprefix, par ? par : "");
 
   if (par[0] == '-') { /* we have an option! */
-    char *tmp;
+    char *tmp = NULL;
+
     par++;
     tmp = newsplit(&par);
     if (!strcasecmp(tmp, "force") || !strcasecmp(tmp, "f")) 
@@ -503,7 +505,7 @@ static int msgc_voice(char *nick, char *host, struct userrec *u, char *par, char
   struct chanset_t *chan = NULL;
   struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
   int force = 0;
-  memberlist *m;
+  memberlist *m = NULL;
 
   if (match_my_nick(nick))
     return BIND_RET_BREAK;
@@ -517,7 +519,8 @@ static int msgc_voice(char *nick, char *host, struct userrec *u, char *par, char
   putlog(LOG_CMDS, "*", "(%s!%s) !%s! %s %sVOICE %s", nick, host, u->handle, chname ? chname : "", cmdprefix, par ? par : "");
 
   if (par[0] == '-') { //we have an option!
-    char *tmp;
+    char *tmp = NULL;
+
     par++;
     tmp = newsplit(&par);
     if (!strcasecmp(tmp, "force") || !strcasecmp(tmp, "f")) 
@@ -552,13 +555,12 @@ static int msgc_channels(char *nick, char *host, struct userrec *u, char *par, c
 {
   struct chanset_t *chan = NULL;
   struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
-  char list[1024];
+  char list[1024] = "";
 
   if (match_my_nick(nick))
     return BIND_RET_BREAK;
 
   putlog(LOG_CMDS, "*", "(%s!%s) !%s! %s %sCHANNELS %s", nick, host, u->handle, chname ? chname : "", cmdprefix, par ? par : "");
-  list[0] = 0;
   for (chan = chanset; chan; chan = chan->next) {
     get_user_flagrec(u, &fr, chan->dname);
     if (chk_op(fr, chan)) {
@@ -629,7 +631,8 @@ static int msgc_invite(char *nick, char *host, struct userrec *u, char *par, cha
   putlog(LOG_CMDS, "*", "(%s!%s) !%s! %sINVITE %s", nick, host, u->handle, cmdprefix, par ? par : "");
 
   if (par[0] == '-') { //we have an option!
-    char *tmp;
+    char *tmp = NULL;
+
     par++;
     tmp = newsplit(&par);
     if (!strcasecmp(tmp, "force") || !strcasecmp(tmp, "f")) 

+ 4 - 4
src/mod/notes.mod/cmdsnote.c

@@ -6,8 +6,8 @@
 
 static void cmd_fwd(struct userrec *u, int idx, char *par)
 {
-  char *handle;
-  struct userrec *u1;
+  char *handle = NULL;
+  struct userrec *u1 = NULL;
 
   if (!par[0]) {
     dprintf(idx, "%s: fwd <handle> [user@bot]\n", NOTES_USAGE);
@@ -41,7 +41,7 @@ static void cmd_fwd(struct userrec *u, int idx, char *par)
 
 static void cmd_notes(struct userrec *u, int idx, char *par)
 {
-  char *fcn;
+  char *fcn = NULL;
 
   if (!par[0]) {
     dprintf(idx, "%s: notes index\n", NOTES_USAGE);
@@ -73,7 +73,7 @@ static void cmd_notes(struct userrec *u, int idx, char *par)
 
 static void cmd_note(struct userrec *u, int idx, char *par)
 {
-  char handle[512], *p;
+  char handle[512] = "", *p = NULL;
   int echo;
 
   p = newsplit(&par);

+ 23 - 26
src/mod/notes.mod/notes.c

@@ -66,8 +66,8 @@ void fwd_display(int idx, struct user_entry *e, struct userrec *u)
 int num_notes(char *user)
 {
   int tot = 0;
-  FILE *f;
-  char s[513], *to, *s1;
+  FILE *f = NULL;
+  char s[513] = "", *to = NULL, *s1 = NULL;
 
   if (!notefile[0])
     return 0;
@@ -96,8 +96,8 @@ int num_notes(char *user)
  */
 static void notes_change(char *oldnick, char *newnick)
 {
-  FILE *f, *g;
-  char s[513], *to, *s1;
+  FILE *f = NULL, *g = NULL;
+  char s[513] = "", *to = NULL, *s1 = NULL;
   int tot = 0;
 
   if (!egg_strcasecmp(oldnick, newnick))
@@ -145,8 +145,8 @@ static void notes_change(char *oldnick, char *newnick)
  */
 static void expire_notes()
 {
-  FILE *f, *g;
-  char s[513], *to, *from, *ts, *s1;
+  FILE *f = NULL, *g = NULL;
+  char s[513] = "", *to = NULL, *from = NULL, *ts = NULL, *s1 = NULL;
   int tot = 0, lapse;
 
   if (!notefile[0])
@@ -196,10 +196,9 @@ static void expire_notes()
  */
 int storenote(char *argv1, char *argv2, char *argv3, int idx, char *who, int bufsize)
 {
-  FILE *f;
-  char u[20], *f1, *to = NULL, work[1024];
-  struct userrec *ur;
-  struct userrec *ur2;
+  FILE *f = NULL;
+  char u[20] = "", *f1 = NULL, *to = NULL, work[1024] = "";
+  struct userrec *ur = NULL, *ur2 = NULL;
 
   if (who && bufsize > 0) who[0] = 0;
   ur = get_user_by_handle(userlist, argv2);
@@ -364,8 +363,8 @@ static int notes_in(int dl[], int in)
  */
 void notes_read(char *hand, char *nick, char *srd, int idx)
 {
-  FILE *f;
-  char s[601], *to, *dt, *from, *s1, wt[100];
+  FILE *f = NULL;
+  char s[601] = "", *to = NULL, *dt = NULL, *from = NULL, *s1 = NULL, wt[100] = "";
   time_t tt;
   int ix = 1;
   int ir = 0;
@@ -476,8 +475,8 @@ void notes_read(char *hand, char *nick, char *srd, int idx)
  */
 void notes_del(char *hand, char *nick, char *sdl, int idx)
 {
-  FILE *f, *g;
-  char s[513], *to, *s1;
+  FILE *f = NULL, *g = NULL;
+  char s[513] = "", *to = NULL, *s1 = NULL;
   int in = 1;
   int er = 0;
   int dl[128];			/* Is it enough ? */
@@ -568,7 +567,7 @@ void notes_del(char *hand, char *nick, char *sdl, int idx)
  */
 static int msg_notes(char *nick, char *host, struct userrec *u, char *par)
 {
-  char *pwd, *fcn;
+  char *pwd = NULL, *fcn = NULL;
 
   if (!u)
     return 0;
@@ -603,10 +602,10 @@ static int msg_notes(char *nick, char *host, struct userrec *u, char *par)
     else
       notes_del(u->handle, nick, par, -1);
   } else if (!egg_strcasecmp(fcn, "TO")) {
-    char *to;
+    char *to = NULL;
     int i;
-    FILE *f;
-    struct userrec *u2;
+    FILE *f = NULL;
+    struct userrec *u2 = NULL;
 
     to = newsplit(&par);
     if (!par[0]) {
@@ -669,12 +668,12 @@ static void notes_hourly()
 {
   expire_notes();
   if (notify_users) {
-    register struct chanset_t	*chan;
-    register memberlist		*m;
-    int				 k;
-    register int		 l;
-    char			 s1[256];
-    struct userrec		*u;
+    register struct chanset_t	*chan = NULL;
+    register memberlist	*m = NULL;
+    int k;
+    register int l;
+    char s1[256] = "";
+    struct userrec *u = NULL;
 
     for (chan = chanset; chan; chan = chan->next) {
       for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
@@ -772,8 +771,6 @@ void notes_report(int idx, int details)
 
 void notes_init()
 {
-
-  notefile[0] = 0;
   add_hook(HOOK_HOURLY, (Function) notes_hourly);
 
   add_builtins("dcc", notes_cmds);

+ 3 - 3
src/mod/server.mod/cmdsserv.c

@@ -8,7 +8,7 @@ static void cmd_servers(struct userrec *u, int idx, char *par)
 {
   struct server_list *x = serverlist;
   int i;
-  char s[1024];
+  char s[1024] = "";
 
   putlog(LOG_CMDS, "*", "#%s# servers", dcc[idx].nick);
   if (!x) {
@@ -48,7 +48,7 @@ static void cmd_dump(struct userrec *u, int idx, char *par)
 
 static void cmd_jump(struct userrec *u, int idx, char *par)
 {
-  char *other;
+  char *other = NULL;
   int port;
 
   if (par[0]) {
@@ -69,7 +69,7 @@ static void cmd_jump(struct userrec *u, int idx, char *par)
 
 static void cmd_clearqueue(struct userrec *u, int idx, char *par)
 {
-  int	msgs;
+  int msgs;
 
   putlog(LOG_CMDS, "*", "#%s# clearqueue %s", dcc[idx].nick, par);
   if (!par[0]) {

+ 53 - 59
src/mod/server.mod/server.c

@@ -20,16 +20,16 @@ static int ctcp_mode;
 static int serv;		/* sock # of server currently */
 static int servidx;		/* idx of server */
 static int strict_host;		/* strict masking of hosts ? */
-static char newserver[121];	/* new server? */
+static char newserver[121] = "";	/* new server? */
 static int newserverport;	/* new server port? */
-static char newserverpass[121];	/* new server password? */
+static char newserverpass[121] = "";	/* new server password? */
 static time_t trying_server;	/* trying to connect to a server right now? */
 static int curserv;		/* current position in server list: */
 static int flud_thr;		/* msg flood threshold */
 static int flud_time;		/* msg flood time */
 static int flud_ctcp_thr;	/* ctcp flood threshold */
 static int flud_ctcp_time;	/* ctcp flood time */
-char botuserhost[121];	/* bot's user@host (refreshed whenever the
+char botuserhost[121] = "";	/* bot's user@host (refreshed whenever the
 				   bot joins a channel) */
 				/* may not be correct user@host BUT it's
 				   how the server sees it */
@@ -46,15 +46,15 @@ static int waiting_for_awake;	/* set when i unidle myself, cleared when
 static time_t server_online;	/* server connection time */
 static time_t server_cycle_wait;	/* seconds to wait before
 					   re-beginning the server list */
-char botrealname[121];	/* realname of bot */
+char botrealname[121] = "";	/* realname of bot */
 static int server_timeout;	/* server timeout for connecting */
 static int never_give_up;	/* never give up when connecting to servers? */
 static int strict_servernames;	/* don't update server list */
-static struct server_list *serverlist;	/* old-style queue, still used by
+static struct server_list *serverlist = NULL;	/* old-style queue, still used by
 					   server list */
 static int cycle_time;		/* cycle time till next server connect */
 static int default_port;	/* default IRC port */
-static char oldnick[NICKLEN];	/* previous nickname *before* rehash */
+static char oldnick[NICKLEN] = "";	/* previous nickname *before* rehash */
 static int trigger_on_ignore;	/* trigger bindings if user is ignored ? */
 static int answer_ctcp;		/* answer how many stacked ctcp's ? */
 static int lowercase_ctcp;	/* answer lowercase CTCP's (non-standard) */
@@ -66,8 +66,8 @@ static int double_server;
 static int double_help;
 static int double_warned;
 static int lastpingtime;	/* IRCNet LAGmeter support -- drummer */
-static char stackablecmds[511];
-static char stackable2cmds[511];
+static char stackablecmds[511] = "";
+static char stackable2cmds[511] = "";
 static time_t last_time;
 static int use_penalties;
 static int use_fastdeq;
@@ -91,9 +91,9 @@ static void msgq_clear(struct msgq_head *qh);
 static int stack_limit;
 
 /* New bind tables. */
-static bind_table_t *BT_raw, *BT_msg, *BT_ctcr, *BT_ctcp;
+static bind_table_t *BT_raw = NULL, *BT_msg = NULL, *BT_ctcr = NULL, *BT_ctcp = NULL;
 #ifdef S_AUTHCMDS
-static bind_table_t *BT_msgc;
+static bind_table_t *BT_msgc = NULL;
 #endif /* S_AUTHCMDS */
 
 #include "servmsg.c"
@@ -130,7 +130,7 @@ static int burst;
  */
 static void deq_msg()
 {
-  struct msgq *q;
+  struct msgq *q = NULL;
   int ok = 0;
 
   /* now < last_time tested 'cause clock adjustments could mess it up */
@@ -222,7 +222,7 @@ static void deq_msg()
 
 static int calc_penalty(char * msg)
 {
-  char *cmd, *par1, *par2, *par3;
+  char *cmd = NULL, *par1 = NULL, *par2 = NULL, *par3 = NULL;
   register int penalty, i, ii;
 
   if (!use_penalties &&
@@ -353,7 +353,7 @@ static int calc_penalty(char * msg)
 
 char *splitnicks(char **rest)
 {
-  register char *o, *r;
+  register char *o = NULL, *r = NULL;
 
   if (!rest)
     return *rest = "";
@@ -371,11 +371,11 @@ char *splitnicks(char **rest)
 
 static int fast_deq(int which)
 {
-  struct msgq_head *h;
-  struct msgq *m, *nm;
-  char msgstr[511], nextmsgstr[511], tosend[511], victims[511], stackable[511],
-       *msg, *nextmsg, *cmd, *nextcmd, *to, *nextto, *stckbl;
-  int len, doit = 0, found = 0, cmd_count =0, stack_method = 1;
+  struct msgq_head *h = NULL;
+  struct msgq *m = NULL, *nm = NULL;
+  char msgstr[511] = "", nextmsgstr[511] = "", tosend[511] = "", victims[511] = "", stackable[511] = "",
+       *msg = NULL, *nextmsg = NULL, *cmd = NULL, *nextcmd = NULL, *to = NULL, *nextto = NULL, *stckbl = NULL;
+  int len, doit = 0, found = 0, cmd_count = 0, stack_method = 1;
 
   if (!use_fastdeq)
     return 0;
@@ -503,8 +503,8 @@ static void check_queues(char *oldnick, char *newnick)
 
 static void parse_q(struct msgq_head *q, char *oldnick, char *newnick)
 {
-  struct msgq *m, *lm = NULL;
-  char buf[511], *msg, *nicks, *nick, *chan, newnicks[511], newmsg[511];
+  struct msgq *m = NULL, *lm = NULL;  char buf[511] = "", *msg = NULL, *nicks = NULL, 
+              *nick = NULL, *chan = NULL, newnicks[511] = "", newmsg[511] = "";
   int changed;
 
   for (m = q->head; m;) {
@@ -561,10 +561,10 @@ static void parse_q(struct msgq_head *q, char *oldnick, char *newnick)
 static void purge_kicks(struct msgq_head *q)
 {
   struct msgq *m, *lm = NULL;
-  char buf[511], *reason, *nicks, *nick, *chan, newnicks[511],
-       newmsg[511], chans[511], *chns, *ch;
+  char buf[511] = "", *reason = NULL, *nicks = NULL, *nick = NULL, *chan = NULL,
+       newnicks[511] = "", newmsg[511] = "", chans[511] = "", *chns, *ch;
   int changed, found;
-  struct chanset_t *cs;
+  struct chanset_t *cs = NULL;
 
   for (m = q->head; m;) {
     if (!egg_strncasecmp(m->msg, "KICK", 4)) {
@@ -629,10 +629,11 @@ static void purge_kicks(struct msgq_head *q)
 
 static int deq_kick(int which)
 {
-  struct msgq_head *h;
-  struct msgq *msg, *m, *lm;
-  char buf[511], buf2[511], *reason2, *nicks, *chan, *chan2, *reason, *nick,
-       newnicks[511], newnicks2[511], newmsg[511];
+  struct msgq_head *h = NULL;
+  struct msgq *msg = NULL, *m = NULL, *lm = NULL;
+  char buf[511] = "", buf2[511] = "", *reason2 = NULL, *nicks = NULL, *chan = NULL,
+       *chan2 = NULL, *reason = NULL, *nick = NULL, newnicks[511] = "", newnicks2[511] = "",
+        newmsg[511] = "";
   int changed = 0, nr = 0;
 
   if (!optimize_kicks)
@@ -722,8 +723,7 @@ static int deq_kick(int which)
     else
       m = h->head->next;
   }
-  egg_snprintf(newmsg, sizeof newmsg, "KICK %s %s %s\n", chan, newnicks + 1,
-	       reason);
+  egg_snprintf(newmsg, sizeof newmsg, "KICK %s %s %s\n", chan, newnicks + 1, reason);
   tputs(serv, newmsg, strlen(newmsg));
   if (debug_output) {
     newmsg[strlen(newmsg) - 1] = 0;
@@ -765,11 +765,9 @@ static void empty_msgq()
  */
 static void queue_server(int which, char *buf, int len)
 {
-  struct msgq_head *h = NULL,
-  		    tempq;
-  struct msgq	   *q, *tq, *tqq;
-  int		    doublemsg = 0,
-  		    qnext = 0;
+  struct msgq_head *h = NULL, tempq;
+  struct msgq *q = NULL, *tq = NULL, *tqq = NULL;
+  int doublemsg = 0, qnext = 0;
 
   /* Don't even BOTHER if there's no server online. */
   if (serv < 0)
@@ -839,7 +837,7 @@ static void queue_server(int which, char *buf, int len)
 	}
       }
 
-    q = malloc(sizeof(struct msgq));
+    q = calloc(1, sizeof(struct msgq));
     if (qnext)
       q->next = h->head;
     else
@@ -853,7 +851,7 @@ static void queue_server(int which, char *buf, int len)
        h->head = q;
     h->last = q;
     q->len = len;
-    q->msg = malloc(len + 1);
+    q->msg = calloc(1, len + 1);
     strncpyz(q->msg, buf, len + 1);
     h->tot++;
     h->warned = 0;
@@ -917,19 +915,18 @@ static void queue_server(int which, char *buf, int len)
  */
 static void add_server(char *ss)
 {
-  struct server_list *x, *z;
+  struct server_list *x = NULL, *z = NULL;
 #ifdef USE_IPV6
-  char *p, *q, *r;
-#else
-  char *p, *q;
+  char *r = NULL;
 #endif /* USE_IPV6 */
+  char *p = NULL, *q = NULL;
 
   for (z = serverlist; z && z->next; z = z->next);
   while (ss) {
     p = strchr(ss, ',');
     if (p)
       *p++ = 0;
-    x = malloc(sizeof(struct server_list));
+    x = calloc(1, sizeof(struct server_list));
 
     x->next = 0;
     x->realname = 0;
@@ -956,7 +953,7 @@ static void add_server(char *ss)
       }
 #endif /* USE_IPV6 */
       *q++ = 0;
-      x->name = malloc(q - ss);
+      x->name = calloc(1, q - ss);
       strcpy(x->name, ss);
       ss = q;
       q = strchr(ss, ':');
@@ -982,7 +979,7 @@ static void add_server(char *ss)
  */
 static void clearq(struct server_list *xx)
 {
-  struct server_list *x;
+  struct server_list *x = NULL;
 
   while (xx) {
     x = xx->next;
@@ -1004,7 +1001,7 @@ void servers6_describe(struct cfg_entry * entry, int idx) {
 
 void servers_changed(struct cfg_entry * entry, char * olddata, int * valid) {
 #ifdef LEAF
-  char *slist, *p;
+  char *slist = NULL, *p = NULL;
 
   if (conf.bot->host6 || conf.bot->ip6) /* we want to use the servers6 entry. */
     return;
@@ -1025,7 +1022,7 @@ void servers_changed(struct cfg_entry * entry, char * olddata, int * valid) {
 
 void servers6_changed(struct cfg_entry * entry, char * olddata, int * valid) {
 #ifdef LEAF
-  char *slist, *p;
+  char *slist = NULL, *p = NULL;
 
   if (!conf.bot->host6 && !conf.bot->ip6) /* we probably want to use the normal server list.. */
     return;
@@ -1049,7 +1046,8 @@ void nick_describe(struct cfg_entry * entry, int idx) {
 
 void nick_changed(struct cfg_entry * entry, char * olddata, int * valid) {
 #ifdef LEAF
-  char * p;
+  char *p = NULL;
+
   if (entry->ldata)
     p = entry->ldata;
   else if (entry->gdata)
@@ -1126,7 +1124,7 @@ static void next_server(int *ptr, char *serv, unsigned int *port, char *pass)
       i++;
     }
     /* Gotta add it: */
-    x = malloc(sizeof(struct server_list));
+    x = calloc(1, sizeof(struct server_list));
 
     x->next = 0;
     x->realname = 0;
@@ -1208,7 +1206,7 @@ static void dcc_chat_hostresolved(int);
  */
 static int ctcp_DCC_CHAT(char *nick, char *from, struct userrec *u, char *object, char *keyword, char *text)
 {
-  char *action, *param, *ip, *prt;
+  char *action = NULL, *param = NULL, *ip = NULL, *prt = NULL;
   int i, ok;
   struct flag_record fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
   
@@ -1286,14 +1284,13 @@ static int ctcp_DCC_CHAT(char *nick, char *from, struct userrec *u, char *object
 
 static void dcc_chat_hostresolved(int i)
 {
-  char buf[512], ip[512];
+  char buf[512] = "", ip[512] = "";
   int ok;
   struct flag_record fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
 
   egg_snprintf(buf, sizeof buf, "%d", dcc[i].port);
 #ifndef USE_IPV6
-  if (!hostsanitycheck_dcc(dcc[i].nick, dcc[i].host, dcc[i].addr,
-                           dcc[i].u.dns->host, buf)) {
+  if (!hostsanitycheck_dcc(dcc[i].nick, dcc[i].host, dcc[i].addr, dcc[i].u.dns->host, buf)) {
     lostdcc(i);
     return;
   }
@@ -1325,10 +1322,8 @@ static void dcc_chat_hostresolved(int i)
   if (dcc[i].sock < 0 || open_telnet_dcc(dcc[i].sock, ip, buf) < 0) {
     neterror(buf);
     if (!quiet_reject)
-      dprintf(DP_HELP, "NOTICE %s :%s (%s)\n", dcc[i].nick,
-	      DCC_CONNECTFAILED1, buf);
-    putlog(LOG_MISC, "*", "%s: CHAT (%s!%s)", DCC_CONNECTFAILED2,
-	   dcc[i].nick, dcc[i].host);
+      dprintf(DP_HELP, "NOTICE %s :%s (%s)\n", dcc[i].nick, DCC_CONNECTFAILED1, buf);
+    putlog(LOG_MISC, "*", "%s: CHAT (%s!%s)", DCC_CONNECTFAILED2, dcc[i].nick, dcc[i].host);
     putlog(LOG_MISC, "*", "    (%s)", buf);
     killsock(dcc[i].sock);
     lostdcc(i);
@@ -1347,8 +1342,7 @@ static void dcc_chat_hostresolved(int i)
     strcpy(dcc[i].u.chat->con_chan, (chanset) ? chanset->dname : "*");
     dcc[i].timeval = now;
     /* Ok, we're satisfied with them now: attempt the connect */
-    putlog(LOG_MISC, "*", "DCC connection: CHAT (%s!%s)", dcc[i].nick,
-	   dcc[i].host);
+    putlog(LOG_MISC, "*", "DCC connection: CHAT (%s!%s)", dcc[i].nick, dcc[i].host);
     dprintf(i, "%s", rand_dccresp());
   }
   return;
@@ -1417,7 +1411,7 @@ static void server_die()
  */
 static void server_report(int idx, int details)
 {
-  char s1[64], s[128];
+  char s1[64] = "", s[128] = "";
 
   if (server_online) {
     dprintf(idx, "    Online as: %s%s%s (%s)\n", botname,
@@ -1460,7 +1454,7 @@ static void server_report(int idx, int details)
 
 static void msgq_clear(struct msgq_head *qh)
 {
-  register struct msgq	*q, *qq;
+  register struct msgq	*q = NULL, *qq = NULL;
 
   for (q = qh->head; q; q = qq) {
     qq = q->next;

+ 124 - 136
src/mod/server.mod/servmsg.c

@@ -39,7 +39,7 @@ static int gotfake433(char *from)
 {
   int l = strlen(botname) - 1;
   int use_chr = 1;
-  char *altchrs = STR("-_\\`^[]");
+  char *altchrs = "-_\\`^[]";
 
   /* First run? */
   if (altnick_char == 0) {
@@ -54,9 +54,11 @@ static int gotfake433(char *from)
       botname[l + 1] = 0;
     }
   } else {
-    char *p = strchr(altchrs, altnick_char);
-    p++;
-    if (!*p) {
+    char *p = NULL;
+ 
+    if ((p = strchr(altchrs, altnick_char)))
+      p++;
+    if (!p || (p && !*p)) {
       /* fun BX style rolling, WEEEE */
       if (rolls < 10) {
         char tmp;
@@ -158,9 +160,9 @@ static int match_my_nick(char *nick)
  */
 static int got001(char *from, char *msg)
 {
-  struct server_list *x;
+  struct server_list *x = NULL;
   int i;
-  struct chanset_t *chan;
+  struct chanset_t *chan = NULL;
 
   /* Ok...param #1 of 001 = what server thinks my nick is */
   server_online = now;
@@ -185,8 +187,7 @@ static int got001(char *from, char *msg)
 	        chan->channel.key[0] ? chan->channel.key : chan->key_prot);
     }
   if (egg_strcasecmp(from, dcc[servidx].host)) {
-    putlog(LOG_MISC, "*", "(%s claims to be %s; updating server list)",
-	   dcc[servidx].host, from);
+    putlog(LOG_MISC, "*", "(%s claims to be %s; updating server list)", dcc[servidx].host, from);
     for (i = curserv; i > 0 && x != NULL; i--)
       x = x->next;
     if (x == NULL) {
@@ -211,10 +212,10 @@ static int got001(char *from, char *msg)
  */
 static int got442(char *from, char *msg)
 {
-  char			*chname;
-  struct chanset_t	*chan;
-  struct server_list	*x;
-  int			 i;
+  char *chname = NULL;
+  struct chanset_t *chan = NULL;
+  struct server_list *x = NULL;
+  int i;
 
   for (x = serverlist, i = 0; x; x = x->next, i++)
     if (i == curserv) {
@@ -227,7 +228,7 @@ static int got442(char *from, char *msg)
   chan = findchan(chname);
   if (chan)
     if (shouldjoin(chan)) {
-      module_entry	*me = module_find("channels", 0, 0);
+      module_entry *me = module_find("channels", 0, 0);
 
       putlog(LOG_MISC, chname, IRC_SERVNOTONCHAN, chname);
       if (me && me->funcs)
@@ -261,8 +262,8 @@ static time_t lastmsgtime[FLOOD_GLOBAL_MAX];
  */
 static int detect_flood(char *floodnick, char *floodhost, char *from, int which)
 {
-  char *p, ftype[10], h[1024];
-  struct userrec *u;
+  char *p = NULL, ftype[10] = "", h[1024] = "";
+  struct userrec *u = NULL;
   int thr = 0, lapse = 0, atr;
 
   u = get_user_by_host(from);
@@ -324,8 +325,7 @@ static int detect_flood(char *floodnick, char *floodhost, char *from, int which)
     /* Private msg */
     simple_sprintf(h, "*!*@%s", p);
     putlog(LOG_MISC, "*", IRC_FLOODIGNORE1, p);
-    addignore(h, conf.bot->nick, (which == FLOOD_CTCP) ? "CTCP flood" :
-	      "MSG/NOTICE flood", now + (60 * ignore_time));
+    addignore(h, conf.bot->nick, (which == FLOOD_CTCP) ? "CTCP flood" : "MSG/NOTICE flood", now + (60 * ignore_time));
   }
   return 0;
 }
@@ -336,7 +336,7 @@ static int detect_flood(char *floodnick, char *floodhost, char *from, int which)
 static int detect_avalanche(char *msg)
 {
   int count = 0;
-  unsigned char *p;
+  unsigned char *p = NULL;
 
   for (p = (unsigned char *) msg; (*p) && (count < 8); p++)
     if ((*p == 7) || (*p == 1))
@@ -351,9 +351,9 @@ static int detect_avalanche(char *msg)
  */
 static int gotmsg(char *from, char *msg)
 {
-  char *to, buf[UHOSTLEN], *nick, ctcpbuf[512], *uhost = buf, *ctcp;
-  char *p, *p1, *code;
-  struct userrec *u;
+  char *to = NULL, buf[UHOSTLEN] = "", *nick = NULL, ctcpbuf[512] = "", *uhost = buf, 
+       *ctcp = NULL, *p = NULL, *p1 = NULL, *code = NULL;
+  struct userrec *u = NULL;
   int ctcp_count = 0;
 #ifdef S_AUTHCMDS
   int i = 0;
@@ -379,95 +379,86 @@ static int gotmsg(char *from, char *msg)
       else
 	p = uhost;
       simple_sprintf(ctcpbuf, "*!*@%s", p);
-      addignore(ctcpbuf, conf.bot->nick, "ctcp avalanche",
-		now + (60 * ignore_time));
+      addignore(ctcpbuf, conf.bot->nick, "ctcp avalanche", now + (60 * ignore_time));
     }
   }
 
-
-    /* Check for CTCP: */
-    ctcp_reply[0] = 0;
-    p = strchr(msg, 1);
-    while ((p != NULL) && (*p)) {
+  /* Check for CTCP: */
+  ctcp_reply[0] = 0;
+  p = strchr(msg, 1);
+  while ((p != NULL) && (*p)) {
+    p++;
+    p1 = p;
+    while ((*p != 1) && (*p != 0))
       p++;
-      p1 = p;
-      while ((*p != 1) && (*p != 0))
-        p++;
-      if (*p == 1) {
-        *p = 0;
-        ctcp = strcpy(ctcpbuf, p1);
-        strcpy(p1 - 1, p + 1);
-        if (!ignoring)
-	  detect_flood(nick, uhost, from,
-		     strncmp(ctcp, "ACTION ", 7) ? FLOOD_CTCP : FLOOD_PRIVMSG);
-        /* Respond to the first answer_ctcp */
-        p = strchr(msg, 1);
-        if (ctcp_count < answer_ctcp) {
-	  ctcp_count++;
-	  if (ctcp[0] != ' ') {
-	    code = newsplit(&ctcp);
-	    if ((to[0] == '$') || strchr(to, '.')) {
-	      if (!ignoring)
-	        /* Don't interpret */
-	        putlog(LOG_PUBLIC, to, "CTCP %s: %s from %s (%s) to %s",
-		     code, ctcp, nick, uhost, to);
-	    } else {
-	      u = get_user_by_host(from);
-	      if (!ignoring || trigger_on_ignore) {
-	        if (!check_bind_ctcp(nick, uhost, u, to, code, ctcp) &&
-		    !ignoring) {
-		  if ((lowercase_ctcp && !egg_strcasecmp(code, "DCC")) ||
-		      (!lowercase_ctcp && !strcmp(code, "DCC"))) {
-		    /* If it gets this far unhandled, it means that
-		     * the user is totally unknown.
-		     */
-		    code = newsplit(&ctcp);
-		    if (!strcmp(code, "CHAT")) {
-		      if (!quiet_reject) {
-		        if (u)
-			  dprintf(DP_HELP, "NOTICE %s :%s\n", nick,
-				"I'm not accepting call at the moment.");
-		        else
-			  dprintf(DP_HELP, "NOTICE %s :%s\n",
-				nick, DCC_NOSTRANGERS);
-		      }
-                      if (!ischanhub())
-                        putlog(LOG_MISC, "*", "%s: %s", DCC_REFUSEDNC, from);
-                      else
-                        putlog(LOG_MISC, "*", "%s: %s", DCC_REFUSED, from);
-		    } else
-		      putlog(LOG_MISC, "*", "Refused DCC %s: %s",
-			   code, from);
-		  }
-	        }
-	        if (!strcmp(code, "ACTION")) {
-		  putlog(LOG_MSGS, "*", "Action to %s: %s %s",
-		       to, nick, ctcp);
-	        } else {
-		  putlog(LOG_MSGS, "*", "CTCP %s: %s from %s (%s)",
-		       code, ctcp, nick, uhost);
-	        }			/* I love a good close cascade ;) */
+    if (*p == 1) {
+      *p = 0;
+      ctcp = strcpy(ctcpbuf, p1);
+      strcpy(p1 - 1, p + 1);
+      if (!ignoring)
+        detect_flood(nick, uhost, from, strncmp(ctcp, "ACTION ", 7) ? FLOOD_CTCP : FLOOD_PRIVMSG);
+      /* Respond to the first answer_ctcp */
+      p = strchr(msg, 1);
+      if (ctcp_count < answer_ctcp) {
+        ctcp_count++;
+	if (ctcp[0] != ' ') {
+	  code = newsplit(&ctcp);
+	  if ((to[0] == '$') || strchr(to, '.')) {
+	    if (!ignoring) {
+	      /* Don't interpret */
+	      putlog(LOG_PUBLIC, to, "CTCP %s: %s from %s (%s) to %s", code, ctcp, nick, uhost, to);
+            }
+          } else {
+	    u = get_user_by_host(from);
+	    if (!ignoring || trigger_on_ignore) {
+	      if (!check_bind_ctcp(nick, uhost, u, to, code, ctcp) && !ignoring) {
+                if ((lowercase_ctcp && !egg_strcasecmp(code, "DCC")) || (!lowercase_ctcp && !strcmp(code, "DCC"))) {
+                  /* If it gets this far unhandled, it means that
+                   * the user is totally unknown.
+                   */
+                  code = newsplit(&ctcp);
+                  if (!strcmp(code, "CHAT")) {
+                    if (!quiet_reject) {
+                      if (u)
+                        dprintf(DP_HELP, "NOTICE %s :%s\n", nick, "I'm not accepting call at the moment.");
+                       else
+                        dprintf(DP_HELP, "NOTICE %s :%s\n", nick, DCC_NOSTRANGERS);
+                    }
+                    if (!ischanhub())
+                      putlog(LOG_MISC, "*", "%s: %s", DCC_REFUSEDNC, from);
+                    else
+                      putlog(LOG_MISC, "*", "%s: %s", DCC_REFUSED, from);
+                  } else {
+                    putlog(LOG_MISC, "*", "Refused DCC %s: %s", code, from);
+                  }
+		}
 	      }
+	      if (!strcmp(code, "ACTION")) {
+                putlog(LOG_MSGS, "*", "Action to %s: %s %s", to, nick, ctcp);
+              } else {
+                putlog(LOG_MSGS, "*", "CTCP %s: %s from %s (%s)", code, ctcp, nick, uhost);
+              }			/* I love a good close cascade ;) */
 	    }
 	  }
-        }
+	}
       }
     }
-    /* Send out possible ctcp responses */
-    if (ctcp_reply[0]) {
-      if (ctcp_mode != 2) {
+  }
+  /* Send out possible ctcp responses */
+  if (ctcp_reply[0]) {
+    if (ctcp_mode != 2) {
+      dprintf(DP_HELP, "NOTICE %s :%s\n", nick, ctcp_reply);
+    } else {
+      if (now - last_ctcp > flud_ctcp_time) {
         dprintf(DP_HELP, "NOTICE %s :%s\n", nick, ctcp_reply);
-      } else {
-        if (now - last_ctcp > flud_ctcp_time) {
-	  dprintf(DP_HELP, "NOTICE %s :%s\n", nick, ctcp_reply);
-	  count_ctcp = 1;
-        } else if (count_ctcp < flud_ctcp_thr) {
-	  dprintf(DP_HELP, "NOTICE %s :%s\n", nick, ctcp_reply);
-	  count_ctcp++;
-        }
-        last_ctcp = now;
+	count_ctcp = 1;
+      } else if (count_ctcp < flud_ctcp_thr) {
+        dprintf(DP_HELP, "NOTICE %s :%s\n", nick, ctcp_reply);
+	count_ctcp++;
       }
+      last_ctcp = now;
     }
+  }
   if (msg[0]) {
     if ((to[0] == '$') || (strchr(to, '.') != NULL)) {
       /* Msg from oper */
@@ -477,8 +468,8 @@ static int gotmsg(char *from, char *msg)
 	putlog(LOG_MSGS | LOG_SERV, "*", "[%s!%s to %s] %s",nick, uhost, to, msg);
       }
     } else {
-      char *code;
-      struct userrec *u;
+      char *code = NULL;
+      struct userrec *u = NULL;
 
       detect_flood(nick, uhost, from, FLOOD_PRIVMSG);
       u = get_user_by_host(from);
@@ -506,9 +497,9 @@ static int gotmsg(char *from, char *msg)
                || !egg_strcasecmp(code, msgop) || !egg_strcasecmp(code, msgpass) 
                || !egg_strcasecmp(code, msginvite) || !egg_strcasecmp(code, msgident)) {
 /*           || !strcmp(code, msgop) || !strcmp(code, msgpass) || !strcmp(code, msgop)) { */
-            char buf[10];
+            char buf[10] = "";
+
             doit = 0;
-            buf[0] = 0;
             if (!egg_strcasecmp(code, msgop))
               sprintf(buf, "op");
             else if (!egg_strcasecmp(code, msgpass))
@@ -539,8 +530,9 @@ static int gotmsg(char *from, char *msg)
  */
 static int gotnotice(char *from, char *msg)
 {
-  char *to, *nick, ctcpbuf[512], *p, *p1, buf[512], *uhost = buf, *ctcp;
-  struct userrec *u;
+  char *to = NULL, *nick = NULL, ctcpbuf[512] = "", *p = NULL, *p1 = NULL, buf[512] = "", 
+       *uhost = buf, *ctcp = NULL;
+  struct userrec *u = NULL;
   int ignoring;
 
   if (msg[0] && ((strchr(CHANMETA, *msg) != NULL) ||
@@ -577,17 +569,14 @@ static int gotnotice(char *from, char *msg)
 	if ((to[0] == '$') || strchr(to, '.')) {
 	  if (!ignoring)
 	    putlog(LOG_PUBLIC, "*",
-		   "CTCP reply %s: %s from %s (%s) to %s", code, ctcp,
-		   nick, uhost, to);
+		   "CTCP reply %s: %s from %s (%s) to %s", code, ctcp, nick, uhost, to);
 	} else {
 	  u = get_user_by_host(from);
 	  if (!ignoring || trigger_on_ignore) {
             check_bind_ctcr(nick, uhost, u, to, code, ctcp);
 	    if (!ignoring)
 	      /* Who cares? */
-	      putlog(LOG_MSGS, "*",
-		     "CTCP reply %s: %s from %s (%s) to %s",
-		     code, ctcp, nick, uhost, to);
+	      putlog(LOG_MSGS, "*", "CTCP reply %s: %s from %s (%s) to %s", code, ctcp, nick, uhost, to);
 	  }
 	}
       }
@@ -596,8 +585,7 @@ static int gotnotice(char *from, char *msg)
   if (msg[0]) {
     if (((to[0] == '$') || strchr(to, '.')) && !ignoring) {
       detect_flood(nick, uhost, from, FLOOD_NOTICE);
-      putlog(LOG_MSGS | LOG_SERV, "*", "-%s (%s) to %s- %s",
-	     nick, uhost, to, msg);
+      putlog(LOG_MSGS | LOG_SERV, "*", "-%s (%s) to %s- %s", nick, uhost, to, msg);
     } else {
       /* Server notice? */
       if ((nick[0] == 0) || (uhost[0] == 0)) {
@@ -619,7 +607,7 @@ static int gotnotice(char *from, char *msg)
  */
 static int gotwall(char *from, char *msg)
 {
-  char *nick;
+  char *nick = NULL;
 
   fixcolon(msg);
 
@@ -655,7 +643,7 @@ static void minutely_checks()
   if (server_online) {
     static int count = 4;
     int ok = 0;
-    struct chanset_t *chan;
+    struct chanset_t *chan = NULL;
 
     for (chan = chanset; chan; chan = chan->next) {
       if (channel_active(chan) && chan->channel.members == 1) {
@@ -691,7 +679,7 @@ static int gotpong(char *from, char *msg)
  */
 static void got303(char *from, char *msg)
 {
-  char *tmp;
+  char *tmp = NULL;
   int ison_orig = 0;
 
   if (!keepnick ||
@@ -718,7 +706,7 @@ static void got303(char *from, char *msg)
  */
 static int got432(char *from, char *msg)
 {
-  char *erroneus;
+  char *erroneus = NULL;
 
   newsplit(&msg);
   erroneus = newsplit(&msg);
@@ -742,7 +730,8 @@ static int got432(char *from, char *msg)
  */
 static int got433(char *from, char *msg)
 {
-  char *tmp;
+  char *tmp = NULL;
+
   if (server_online) {
     /* We are online and have a nickname, we'll keep it */
     newsplit(&msg);
@@ -759,8 +748,8 @@ static int got433(char *from, char *msg)
  */
 static int got437(char *from, char *msg)
 {
-  char *s;
-  struct chanset_t *chan;
+  char *s = NULL;
+  struct chanset_t *chan = NULL;
 
   newsplit(&msg);
   s = newsplit(&msg);
@@ -835,8 +824,8 @@ static int goterror(char *from, char *msg)
  */
 static int gotnick(char *from, char *msg)
 {
-  char *nick, *buf, *buf_ptr;
-  struct userrec *u;
+  char *nick = NULL, *buf = NULL, *buf_ptr = NULL;
+  struct userrec *u = NULL;
 
   buf = buf_ptr = strdup(from);
   u = get_user_by_host(buf);
@@ -871,8 +860,9 @@ static int gotnick(char *from, char *msg)
 
 static int gotmode(char *from, char *msg)
 {
-  char *ch, *buf = strdup(msg), *buf_ptr;
-  buf_ptr = buf;
+  char *ch = NULL, *buf = NULL, *buf_ptr = NULL;
+
+  buf_ptr = buf = strdup(msg);
 
   ch = newsplit(&buf);
   /* Usermode changes? */
@@ -911,6 +901,7 @@ static void eof_server(int idx)
 #ifdef S_AUTHCMDS
 {
   int i = 0;
+
   if (ischanhub() && auth_total > 0) {
     putlog(LOG_DEBUG, "*", "Removing %d auth entries.", auth_total);
     for (i = 0; i < auth_total; i++)
@@ -930,7 +921,7 @@ static void connect_server(void);
 
 static void kill_server(int idx, void *x)
 {
-  module_entry *me;
+  module_entry *me = NULL;
 
   disconnect_server(idx, NO_LOST);	/* eof_server will lostdcc() it. */
   if ((me = module_find("channels", 0, 0)) && me->funcs) {
@@ -968,9 +959,8 @@ static struct dcc_table SERVER_SOCKET =
 
 int isop(char *mode)
 {
-  int state = 0,
-    cnt = 0;
-  char *p;
+  int state = 0, cnt = 0;
+  char *p = NULL;
 
   p = mode;
   while ((*p) && (*p != ' ')) {
@@ -987,9 +977,8 @@ int isop(char *mode)
 
 int ismdop(char *mode)
 {
-  int state = 0,
-    cnt = 0;
-  char *p;
+  int state = 0, cnt = 0;
+  char *p = NULL;
 
   p = mode;
   while ((*p) && (*p != ' ')) {
@@ -1006,7 +995,7 @@ int ismdop(char *mode)
 
 static void server_activity(int idx, char *msg, int len)
 {
-  char *from, *code;
+  char *from = NULL, *code = NULL;
 
   if (trying_server) {
     strcpy(dcc[idx].nick, "(server)");
@@ -1045,7 +1034,7 @@ static int gotping(char *from, char *msg)
 
 static int gotkick(char *from, char *msg)
 {
-  char *nick;
+  char *nick = NULL;
 
   nick = from;
   if (rfc_casecmp(nick, botname))
@@ -1091,7 +1080,7 @@ static int whoispenalty(char *from, char *msg)
 
 static int got311(char *from, char *msg)
 {
-  char *n1, *n2, *u, *h;
+  char *n1 = NULL, *n2 = NULL, *u = NULL, *h = NULL;
   
   n1 = newsplit(&msg);
   n2 = newsplit(&msg);
@@ -1162,7 +1151,7 @@ static void connect_server(void)
   } else
     pass[0] = 0;
   if (!cycle_time) {
-    struct chanset_t *chan;
+    struct chanset_t *chan = NULL;
     struct server_list *x = serverlist;
 
     if (!x)
@@ -1233,7 +1222,7 @@ static void server_resolve_success(int idx)
 #ifdef S_NODELAY
   int i = 0;
 #endif
-  char s[121], pass[121];
+  char s[121] = "", pass[121] = "";
 
   resolvserv = 0;
   dcc[idx].addr = dcc[idx].u.dns->ip;
@@ -1246,8 +1235,7 @@ static void server_resolve_success(int idx)
 #endif /* USE_IPV6 */
   if (serv < 0) {
     neterror(s);
-    putlog(LOG_SERV, "*", "%s %s (%s)", IRC_FAILEDCONNECT, dcc[idx].host,
-	   s);
+    putlog(LOG_SERV, "*", "%s %s (%s)", IRC_FAILEDCONNECT, dcc[idx].host, s);
     lostdcc(idx);
     servidx = -1;
     if (oldserv == curserv && !never_give_up)

+ 101 - 109
src/mod/share.mod/share.c

@@ -36,7 +36,7 @@ static Function *irc_funcs = NULL;
 
 static int private_global = 0;
 static int private_user = 0;
-static char private_globals[50];
+static char private_globals[50] = "";
 static int allow_resync = 0;
 static struct flag_record fr = {0, 0, 0, 0, 0, 0};
 static int resync_time = 900;
@@ -93,17 +93,13 @@ static void add_delay(struct chanset_t *chan, int plsmns, int mode, char *mask)
 {
   struct delay_mode *d = NULL;
 
-  d = (struct delay_mode *) malloc(sizeof(struct delay_mode));
-  if (!d)
-    return;
+  d = (struct delay_mode *) calloc(1, sizeof(struct delay_mode));
+
   d->chan = chan;
   d->plsmns = plsmns;
   d->mode = mode;
-  d->mask = (char *) malloc(strlen(mask) + 1);
-  if (!d->mask) {
-    free(d);
-    return;
-  }
+  d->mask = (char *) calloc(1, strlen(mask) + 1);
+
   strncpyz(d->mask, mask, strlen(mask) + 1);
   d->seconds = (int) (now + (random() % 20));
   d->next = start_delay;
@@ -147,7 +143,7 @@ static void check_delay()
 
 static void share_stick_ban(int idx, char *par)
 {
-  char *host, *val;
+  char *host = NULL, *val = NULL;
   int yn;
 
   if (dcc[idx].status & STAT_SHARE) {
@@ -157,7 +153,7 @@ static void share_stick_ban(int idx, char *par)
     noshare = 1;
     if (!par[0]) {		/* Global ban */
 #ifdef LEAF
-      struct chanset_t *chan;
+      struct chanset_t *chan = NULL;
 #endif /* LEAF */
       if (u_setsticky_ban(NULL, host, yn) > 0) {
        putlog(LOG_CMDS, "@", "%s: %s %s", dcc[idx].nick, (yn) ? "stick" : "unstick", host);
@@ -195,7 +191,7 @@ static void share_stick_ban(int idx, char *par)
  */
 static void share_stick_exempt(int idx, char *par)
 {
-  char *host, *val;
+  char *host = NULL, *val = NULL;
   int yn;
 
   if (dcc[idx].status & STAT_SHARE) {
@@ -210,7 +206,7 @@ static void share_stick_exempt(int idx, char *par)
       }
     } else {
       struct chanset_t *chan = findchan_by_dname(par);
-      struct chanuserrec * cr;
+      struct chanuserrec *cr = NULL;
 
       if ((chan != NULL) && ((channel_shared(chan) &&
                              ((cr = get_chanrec(dcc[idx].user, par)) &&
@@ -231,7 +227,7 @@ static void share_stick_exempt(int idx, char *par)
 /* Same as share_stick_ban, only for invites.
  */
 static void share_stick_invite (int idx, char * par) {
-  char *host, *val;
+  char *host = NULL, *val = NULL;
   int yn;
 
   if (dcc[idx].status & STAT_SHARE) {
@@ -246,7 +242,7 @@ static void share_stick_invite (int idx, char * par) {
       }
     } else {
       struct chanset_t *chan = findchan_by_dname(par);
-      struct chanuserrec * cr;
+      struct chanuserrec *cr = NULL;
 
       if ((chan != NULL) && ((channel_shared(chan) &&
                              ((cr = get_chanrec(dcc[idx].user, par)) &&
@@ -266,8 +262,8 @@ static void share_stick_invite (int idx, char * par) {
 
 static void share_chhand(int idx, char *par)
 {
-  char *hand;
-  struct userrec *u;
+  char *hand = NULL;
+  struct userrec *u = NULL;
 
   if ((dcc[idx].status & STAT_SHARE) && !private_user) {
     hand = newsplit(&par);
@@ -284,12 +280,12 @@ static void share_chhand(int idx, char *par)
 
 static void share_chattr(int idx, char *par)
 {
-  char *hand, *atr, s[100];
-  struct chanset_t *cst;
-  struct userrec *u;
+  char *hand = NULL, *atr = NULL, s[100] = "";
+  struct chanset_t *cst = NULL;
+  struct userrec *u = NULL;
   struct flag_record fr2;
   int bfl, ofl;
-  module_entry *me;
+  module_entry *me = NULL;
 
   if ((dcc[idx].status & STAT_SHARE) && !private_user) {
     hand = newsplit(&par);
@@ -368,9 +364,9 @@ static void share_chattr(int idx, char *par)
 
 static void share_pls_chrec(int idx, char *par)
 {
-  char *user;
-  struct chanset_t *chan;
-  struct userrec *u;
+  char *user = NULL;
+  struct chanset_t *chan = NULL;
+  struct userrec *u = NULL;
 
   if ((dcc[idx].status & STAT_SHARE) && !private_user) {
     user = newsplit(&par);
@@ -398,9 +394,9 @@ static void share_pls_chrec(int idx, char *par)
 
 static void share_mns_chrec(int idx, char *par)
 {
-  char *user;
-  struct chanset_t *chan;
-  struct userrec *u;
+  char *user = NULL;
+  struct chanset_t *chan = NULL;
+  struct userrec *u = NULL;
 
   if ((dcc[idx].status & STAT_SHARE) && !private_user) {
     user = newsplit(&par);
@@ -426,8 +422,8 @@ static void share_mns_chrec(int idx, char *par)
 
 static void share_newuser(int idx, char *par)
 {
-  char *nick, *host, *pass, s[100];
-  struct userrec *u;
+  char *nick = NULL, *host = NULL, *pass = NULL, s[100] = "";
+  struct userrec *u = NULL;
 
   if ((dcc[idx].status & STAT_SHARE) && !private_user) {
     nick = newsplit(&par);
@@ -478,7 +474,7 @@ static void share_newuser(int idx, char *par)
 
 static void share_killuser(int idx, char *par)
 {
-  struct userrec *u;
+  struct userrec *u = NULL;
 
   /* If user is a share bot, ignore command */
   if ((dcc[idx].status & STAT_SHARE) && !private_user &&
@@ -498,8 +494,8 @@ static void share_killuser(int idx, char *par)
 
 static void share_pls_host(int idx, char *par)
 {
-  char *hand;
-  struct userrec *u;
+  char *hand = NULL;
+  struct userrec *u = NULL;
 
   if ((dcc[idx].status & STAT_SHARE) && !private_user) {
     hand = newsplit(&par);
@@ -518,8 +514,8 @@ static void share_pls_host(int idx, char *par)
 
 static void share_pls_bothost(int idx, char *par)
 {
-  char *hand, p[32];
-  struct userrec *u;
+  char *hand = NULL, p[32] = "";
+  struct userrec *u = NULL;
 
   if ((dcc[idx].status & STAT_SHARE) && !private_user) {
     hand = newsplit(&par);
@@ -546,8 +542,8 @@ static void share_pls_bothost(int idx, char *par)
 
 static void share_mns_host(int idx, char *par)
 {
-  char *hand;
-  struct userrec *u;
+  char *hand = NULL;
+  struct userrec *u = NULL;
 
   if ((dcc[idx].status & STAT_SHARE) && !private_user) {
     hand = newsplit(&par);
@@ -568,10 +564,10 @@ static void share_mns_host(int idx, char *par)
 
 static void share_change(int idx, char *par)
 {
-  char *key, *hand;
-  struct userrec *u;
-  struct user_entry_type *uet;
-  struct user_entry *e;
+  char *key = NULL, *hand = NULL;
+  struct userrec *u = NULL;
+  struct user_entry_type *uet = NULL;
+  struct user_entry *e = NULL;
 
   if ((dcc[idx].status & STAT_SHARE) && !private_user) {
     key = newsplit(&par);
@@ -586,7 +582,7 @@ static void share_change(int idx, char *par)
 	  shareout_but(NULL, idx, "c %s %s %s\n", key, hand, par);
 	noshare = 1;
 	if (!u && (uet == &USERENTRY_BOTADDR)) {
-	  char pass[30];
+	  char pass[30] = "";
 
 	  makepass(pass);
 	  userlist = adduser(userlist, hand, "none", pass, USER_BOT);
@@ -595,7 +591,7 @@ static void share_change(int idx, char *par)
 	  return;
 	if (uet->got_share) {
 	  if (!(e = find_user_entry(uet, u))) {
-	    e = malloc(sizeof(struct user_entry));
+	    e = calloc(1, sizeof(struct user_entry));
 
 	    e->type = uet;
 	    e->name = NULL;
@@ -617,9 +613,9 @@ static void share_change(int idx, char *par)
 
 static void share_chchinfo(int idx, char *par)
 {
-  char *hand, *chan;
-  struct chanset_t *cst;
-  struct userrec *u;
+  char *hand = NULL, *chan = NULL;
+  struct chanset_t *cst = NULL;
+  struct userrec *u = NULL;
 
   if ((dcc[idx].status & STAT_SHARE) && !private_user) {
     hand = newsplit(&par);
@@ -698,8 +694,8 @@ static void share_mns_invite(int idx, char *par)
 
 static void share_mns_banchan(int idx, char *par)
 {
-  char *chname;
-  struct chanset_t *chan;
+  char *chname = NULL;
+  struct chanset_t *chan = NULL;
 
   if (dcc[idx].status & STAT_SHARE) {
     chname = newsplit(&par);
@@ -708,13 +704,10 @@ static void share_mns_banchan(int idx, char *par)
     get_user_flagrec(dcc[idx].user, &fr, chname);
     if (!chan || !channel_shared(chan) ||
         !(bot_chan(fr) || bot_global(fr)))
-      putlog(LOG_CMDS, "*",
-             "Cancel channel ban %s on %s rejected - channel not shared.",
-             par, chname);
+      putlog(LOG_CMDS, "*", "Cancel channel ban %s on %s rejected - channel not shared.", par, chname);
     else {
       shareout_but(chan, idx, "-bc %s %s\n", chname, par);
-      putlog(LOG_CMDS, "@", "%s: cancel ban %s on %s", dcc[idx].nick,
-	     par, chname);
+      putlog(LOG_CMDS, "@", "%s: cancel ban %s on %s", dcc[idx].nick, par, chname);
       str_unescape(par, '\\');
       noshare = 1;
       if (u_delban(chan, par, 1) > 0)
@@ -726,8 +719,8 @@ static void share_mns_banchan(int idx, char *par)
 
 static void share_mns_exemptchan(int idx, char *par)
 {
-  char *chname;
-  struct chanset_t *chan;
+  char *chname = NULL;
+  struct chanset_t *chan = NULL;
 
   if (dcc[idx].status & STAT_SHARE) {
     chname = newsplit(&par);
@@ -754,8 +747,8 @@ static void share_mns_exemptchan(int idx, char *par)
 
 static void share_mns_invitechan (int idx, char *par)
 {
-  char *chname;
-  struct chanset_t *chan;
+  char *chname = NULL;
+  struct chanset_t *chan = NULL;
 
   if (dcc[idx].status & STAT_SHARE) {
     chname = newsplit(&par);
@@ -795,10 +788,10 @@ static void share_mns_ignore(int idx, char *par)
 static void share_pls_ban(int idx, char *par)
 {
 #ifdef LEAF
-  struct chanset_t *chan;
+  struct chanset_t *chan = NULL;
 #endif /* LEAF */
   time_t expire_time;
-  char *ban, *tm, *from;
+  char *ban = NULL, *tm = NULL, *from = NULL;
   int flags = 0;
 
   if (dcc[idx].status & STAT_SHARE) {
@@ -831,8 +824,8 @@ static void share_pls_banchan(int idx, char *par)
 {
   time_t expire_time;
   int flags = 0;
-  struct chanset_t *chan;
-  char *ban, *tm, *chname, *from;
+  struct chanset_t *chan = NULL;
+  char *ban = NULL, *tm = NULL, *chname = NULL, *from = NULL;
 
   if (dcc[idx].status & STAT_SHARE) {
     ban = newsplit(&par);
@@ -875,7 +868,7 @@ static void share_pls_banchan(int idx, char *par)
 static void share_pls_exempt(int idx, char *par)
 {
   time_t expire_time;
-  char *exempt, *tm, *from;
+  char *exempt = NULL, *tm = NULL, *from = NULL;
   int flags = 0;
 
   if (dcc[idx].status & STAT_SHARE) {
@@ -906,8 +899,8 @@ static void share_pls_exemptchan(int idx, char *par)
 {
   time_t expire_time;
   int flags = 0;
-  struct chanset_t *chan;
-  char *exempt, *tm, *chname, *from;
+  struct chanset_t *chan = NULL;
+  char *exempt = NULL, *tm = NULL, *chname = NULL, *from = NULL;
 
   if (dcc[idx].status & STAT_SHARE) {
     exempt = newsplit(&par);
@@ -947,7 +940,7 @@ static void share_pls_exemptchan(int idx, char *par)
 static void share_pls_invite(int idx, char *par)
 {
   time_t expire_time;
-  char *invite, *tm, *from;
+  char *invite = NULL, *tm = NULL, *from = NULL;
   int flags = 0;
 
   if (dcc[idx].status & STAT_SHARE) {
@@ -978,8 +971,8 @@ static void share_pls_invitechan(int idx, char *par)
 {
   time_t expire_time;
   int flags = 0;
-  struct chanset_t *chan;
-  char *invite, *tm, *chname, *from;
+  struct chanset_t *chan = NULL;
+  char *invite = NULL, *tm = NULL, *chname = NULL, *from = NULL;
 
   if (dcc[idx].status & STAT_SHARE) {
     invite = newsplit(&par);
@@ -1019,7 +1012,7 @@ static void share_pls_invitechan(int idx, char *par)
 static void share_pls_ignore(int idx, char *par)
 {
   time_t expire_time;
-  char *ign, *from, *ts;
+  char *ign = NULL, *from = NULL, *ts = NULL;
 
   if (dcc[idx].status & STAT_SHARE) {
     shareout_but(NULL, idx, "+i %s\n", par);
@@ -1108,10 +1101,10 @@ static void share_userfileq(int idx, char *par)
  */
 static void share_ufsend(int idx, char *par)
 {
-  char *ip=NULL, *port;
-  char s[1024];
+  char *ip = NULL, *port = NULL;
+  char s[1024] = "";
   int i, sock;
-  FILE *f;
+  FILE *f = NULL;
 
   egg_snprintf(s, sizeof s, "%s.share.%s.%lu.users", tempdir, conf.bot->nick, now);
   if (!(b_status(idx) & STAT_SHARE)) {
@@ -1302,7 +1295,7 @@ static botcmd_t C_share[] =
 
 static void sharein_mod(int idx, char *msg)
 {
-  char *code;
+  char *code = NULL;
   int f, i;
 
   code = newsplit(&msg);
@@ -1320,8 +1313,7 @@ static void sharein_mod(int idx, char *msg)
 static void shareout_mod (struct chanset_t *chan, ...)
 {
   int i, l;
-  char *format;
-  char s[601];
+  char *format = NULL, s[601] = "";
   va_list va;
 
   va_start(va, chan);
@@ -1349,8 +1341,7 @@ static void shareout_mod (struct chanset_t *chan, ...)
 static void shareout_but (struct chanset_t *chan, ...)
 {
   int i, x, l;
-  char *format;
-  char s[601];
+  char *format = NULL, s[601] = "";
   va_list va;
 
   va_start(va, chan);
@@ -1385,9 +1376,9 @@ static void shareout_but (struct chanset_t *chan, ...)
  */
 static void new_tbuf(char *bot)
 {
-  tandbuf **old = &tbuf, *new;
+  tandbuf **old = &tbuf, *new = NULL;
 
-  new = malloc(sizeof(tandbuf));
+  new = calloc(1, sizeof(tandbuf));
   strcpy(new->bot, bot);
   new->q = NULL;
   new->timer = now;
@@ -1398,7 +1389,7 @@ static void new_tbuf(char *bot)
 
 static void del_tbuf(tandbuf *goner)
 {
-  struct share_msgq *q, *r;
+  struct share_msgq *q = NULL, *r = NULL;
   tandbuf *t = NULL, *old = NULL;
 
   for (t = tbuf; t; old = t, t = t->next) {
@@ -1422,7 +1413,7 @@ static void del_tbuf(tandbuf *goner)
  */
 static int flush_tbuf(char *bot)
 {
-  tandbuf *t, *tnext = NULL;
+  tandbuf *t = NULL, *tnext = NULL;
 
   for (t = tbuf; t; t = tnext) {
     tnext = t->next;
@@ -1439,7 +1430,7 @@ static int flush_tbuf(char *bot)
 static void check_expired_tbufs()
 {
   int i;
-  tandbuf *t, *tnext = NULL;
+  tandbuf *t = NULL, *tnext = NULL;
 
   for (t = tbuf; t; t = tnext) {
     tnext = t->next;
@@ -1471,11 +1462,11 @@ static void check_expired_tbufs()
 static struct share_msgq *q_addmsg(struct share_msgq *qq,
 				   struct chanset_t *chan, char *s)
 {
-  struct share_msgq *q;
+  struct share_msgq *q = NULL;
   int cnt;
 
   if (!qq) {
-    q = (struct share_msgq *) malloc(sizeof(struct share_msgq));
+    q = (struct share_msgq *) calloc(1, sizeof(struct share_msgq));
 
     q->chan = chan;
     q->next = NULL;
@@ -1487,7 +1478,7 @@ static struct share_msgq *q_addmsg(struct share_msgq *qq,
     cnt++;
   if (cnt > 1000)
     return NULL;		/* Return null: did not alter queue */
-  q->next = (struct share_msgq *) malloc(sizeof(struct share_msgq));
+  q->next = (struct share_msgq *) calloc(1, sizeof(struct share_msgq));
 
   q = q->next;
   q->chan = chan;
@@ -1500,8 +1491,8 @@ static struct share_msgq *q_addmsg(struct share_msgq *qq,
  */
 static void q_tbuf(char *bot, char *s, struct chanset_t *chan)
 {
-  struct share_msgq *q;
-  tandbuf *t;
+  struct share_msgq *q = NULL;
+  tandbuf *t = NULL;
 
   for (t = tbuf; t && t->bot[0]; t = t->next)
     if (!egg_strcasecmp(t->bot, bot)) {
@@ -1520,8 +1511,8 @@ static void q_tbuf(char *bot, char *s, struct chanset_t *chan)
  */
 static void q_resync(char *s, struct chanset_t *chan)
 {
-  struct share_msgq *q;
-  tandbuf *t;
+  struct share_msgq *q = NULL;
+  tandbuf *t = NULL;
 
   for (t = tbuf; t && t->bot[0]; t = t->next) {
       if (chan) {
@@ -1539,7 +1530,7 @@ static void q_resync(char *s, struct chanset_t *chan)
  */
 static int can_resync(char *bot)
 {
-  tandbuf *t;
+  tandbuf *t = NULL;
 
   for (t = tbuf; t && t->bot[0]; t = t->next)
     if (!egg_strcasecmp(bot, t->bot))
@@ -1551,8 +1542,8 @@ static int can_resync(char *bot)
  */
 static void dump_resync(int idx)
 {
-  struct share_msgq *q;
-  tandbuf *t;
+  struct share_msgq *q = NULL;
+  tandbuf *t = NULL;
 
   for (t = tbuf; t && t->bot[0]; t = t->next)
     if (!egg_strcasecmp(dcc[idx].nick, t->bot)) {
@@ -1569,9 +1560,9 @@ static void dump_resync(int idx)
 static void status_tbufs(int idx)
 {
   int count, off = 0;
-  struct share_msgq *q;
-  char s[121];
-  tandbuf *t;
+  struct share_msgq *q = NULL;
+  char s[121] = "";
+  tandbuf *t = NULL;
 
   off = 0;
   for (t = tbuf; t && t->bot[0]; t = t->next) 
@@ -1590,8 +1581,8 @@ static void status_tbufs(int idx)
 
 static int write_tmp_userfile(char *fn, struct userrec *bu, int idx)
 {
-  FILE *f;
-  struct userrec *u;
+  FILE *f = NULL;
+  struct userrec *u = NULL;
   int ok = 0;
 
   if ((f = fopen(fn, "wb"))) {
@@ -1638,10 +1629,10 @@ static int write_tmp_userfile(char *fn, struct userrec *bu, int idx)
  */
 static struct userrec *dup_userlist(int t)
 {
-  struct userrec *u, *u1, *retu, *nu;
-  struct chanuserrec *ch;
-  struct user_entry *ue;
-  char *p;
+  struct userrec *u = NULL, *u1 = NULL, *retu = NULL, *nu = NULL;
+  struct chanuserrec *ch = NULL;
+  struct user_entry *ue = NULL;
+  char *p = NULL;
 
   nu = retu = NULL;
   noshare = 1;
@@ -1676,7 +1667,7 @@ static struct userrec *dup_userlist(int t)
 	  struct list_type *lt;
 	  struct user_entry *nue;
 
-	  nue = malloc(sizeof(struct user_entry));
+	  nue = calloc(1, sizeof(struct user_entry));
 	  nue->type = NULL;
 	  nue->u.list = NULL;
           nue->name = strdup(ue->name);
@@ -1684,7 +1675,7 @@ static struct userrec *dup_userlist(int t)
 	  for (lt = ue->u.list; lt; lt = lt->next) {
 	    struct list_type *list;
 
-	    list = malloc(sizeof(struct list_type));
+	    list = calloc(1, sizeof(struct list_type));
 	    list->next = NULL;
             list->extra = strdup(lt->extra);
 	    list_append((&nue->u.list), list);
@@ -1704,7 +1695,7 @@ static struct userrec *dup_userlist(int t)
 static void finish_share(int idx)
 {
   struct userrec *u = NULL, *ou = NULL;
-  struct chanset_t *chan;
+  struct chanset_t *chan = NULL;
   int i, j = -1;
 
   for (i = 0; i < dcc_total; i++)
@@ -1778,7 +1769,8 @@ static void finish_share(int idx)
   checkchans(0); /* flag all the channels.. */
 Context;
   if (!readuserfile(dcc[idx].u.xfer->filename, &u)) {
-    char xx[1024];
+    char xx[1024] = "";
+
 Context;
     unlink(dcc[idx].u.xfer->filename); /* why the fuck was this not here, stupid eggdev team. */
     loading = 0;
@@ -1906,11 +1898,11 @@ Context;
  */
 static void start_sending_users(int idx)
 {
-  struct userrec *u;
-  char share_file[1024], s1[64];
+  struct userrec *u = NULL;
+  char share_file[1024] = "", s1[64] = "";
   int i = 1;
-  struct chanuserrec *ch;
-  struct chanset_t *cst;
+  struct chanuserrec *ch = NULL;
+  struct chanset_t *cst = NULL;
 
   egg_snprintf(share_file, sizeof share_file, "%s.share.%s.%lu", tempdir, dcc[idx].nick, now);
   if (dcc[idx].u.bot->uff_flags & UFF_OVERRIDE) {
@@ -1959,8 +1951,8 @@ static void start_sending_users(int idx)
       for (u = userlist; u; u = u->next) {
         if ((u->flags & USER_BOT) && !(u->flags & USER_UNSHARED)) {
 	  struct bot_addr *bi = get_user(&USERENTRY_BOTADDR, u);
-	  struct list_type *t;
-	  char s2[1024];
+	  struct list_type *t = NULL;
+	  char s2[1024] = "";
 
 	  /* Send hostmasks */
 	  for (t = get_user(&USERENTRY_HOSTS, u); t; t = t->next) {

+ 16 - 18
src/mod/share.mod/uf_features.c

@@ -54,7 +54,7 @@ typedef struct {
 } uff_head_t;
 
 static uff_head_t	uff_list;
-static char		uff_sbuf[512];
+static char		uff_sbuf[512] = "";
 
 
 /*
@@ -72,7 +72,7 @@ static void uff_init(void)
  */
 static uff_list_t *uff_findentry_byflag(int flag)
 {
-  uff_list_t *ul;
+  uff_list_t *ul = NULL;
 
   for (ul = uff_list.start; ul; ul = ul->next)
     if (ul->entry->flag & flag)
@@ -85,7 +85,7 @@ static uff_list_t *uff_findentry_byflag(int flag)
  */
 static uff_list_t *uff_findentry_byname(char *feature)
 {
-  uff_list_t *ul;
+  uff_list_t *ul = NULL;
 
   for (ul = uff_list.start; ul; ul = ul->next)
     if (!strcmp(ul->entry->feature, feature))
@@ -97,7 +97,7 @@ static uff_list_t *uff_findentry_byname(char *feature)
  */
 static void uff_insert_entry(uff_list_t *nul)
 {
-  uff_list_t	*ul, *lul = NULL;
+  uff_list_t *ul = NULL, *lul = NULL;
 
   ul = uff_list.start;
   while (ul && ul->entry->priority < nul->entry->priority) {
@@ -141,20 +141,18 @@ static void uff_remove_entry(uff_list_t *ul)
  */
 static void uff_addfeature(uff_table_t *ut)
 {
-  uff_list_t	*ul;
+  uff_list_t *ul = NULL;
 
   if (uff_findentry_byname(ut->feature)) {
-    putlog(LOG_MISC, "*", "(!) share: same feature name used twice: %s",
-	   ut->feature);
+    putlog(LOG_MISC, "*", "(!) share: same feature name used twice: %s", ut->feature);
     return;
   }
   ul = uff_findentry_byflag(ut->flag);
   if (ul) {
-    putlog(LOG_MISC, "*", "(!) share: feature flag %d used twice by %s and %s",
-	   ut->flag, ut->feature, ul->entry->feature);
+    putlog(LOG_MISC, "*", "(!) share: feature flag %d used twice by %s and %s", ut->flag, ut->feature, ul->entry->feature);
     return;
   }
-  ul = malloc(sizeof(uff_list_t));
+  ul = calloc(1, sizeof(uff_list_t));
   ul->entry = ut;
   uff_insert_entry(ul);
 }
@@ -173,7 +171,7 @@ static void uff_addtable(uff_table_t *ut)
  */
 static int uff_delfeature(uff_table_t *ut)
 {
-  uff_list_t *ul;
+  uff_list_t *ul = NULL;
 
   for (ul = uff_list.start; ul; ul = ul->next)
     if (!strcmp(ul->entry->feature, ut->feature)) {
@@ -204,8 +202,8 @@ static void uff_deltable(uff_table_t *ut)
  */
 static void uf_features_parse(int idx, char *par)
 {
-  char *buf, *s, *p;
-  uff_list_t *ul;
+  char *buf = NULL, *s = NULL, *p = NULL;
+  uff_list_t *ul = NULL;
 
   uff_sbuf[0] = 0;				/* Reset static buffer	*/
   p = s = buf = strdup(par);
@@ -237,7 +235,7 @@ static void uf_features_parse(int idx, char *par)
  */
 static char *uf_features_dump(int idx)
 {
-  uff_list_t *ul;
+  uff_list_t *ul = NULL;
 
   uff_sbuf[0] = 0;
   for (ul = uff_list.start; ul; ul = ul->next)
@@ -250,8 +248,8 @@ static char *uf_features_dump(int idx)
 
 static int uf_features_check(int idx, char *par)
 {
-  char *buf, *s, *p;
-  uff_list_t *ul;
+  char *buf = NULL, *s = NULL, *p = NULL;
+  uff_list_t *ul = NULL;
 
   uff_sbuf[0] = 0;				/* Reset static buffer	*/
   p = s = buf = strdup(par);
@@ -293,7 +291,7 @@ static int uf_features_check(int idx, char *par)
  */
 static int uff_call_sending(int idx, char *user_file)
 {
-  uff_list_t *ul;
+  uff_list_t *ul = NULL;
 
   for (ul = uff_list.start; ul; ul = ul->next)
     if (ul->entry && ul->entry->snd &&
@@ -309,7 +307,7 @@ static int uff_call_sending(int idx, char *user_file)
  */
 static int uff_call_receiving(int idx, char *user_file)
 {
-  uff_list_t *ul;
+  uff_list_t *ul = NULL;
 
   for (ul = uff_list.end; ul; ul = ul->prev)
     if (ul->entry && ul->entry->rcv &&

+ 56 - 62
src/mod/transfer.mod/transfer.c

@@ -27,7 +27,7 @@
 
 extern int		bupdating;
 
-static bind_table_t *BT_rcvd, *BT_sent, *BT_lost, *BT_tout;
+static bind_table_t *BT_rcvd = NULL, *BT_sent = NULL, *BT_lost = NULL, *BT_tout = NULL;
 
 static Function *global = NULL;
 
@@ -77,7 +77,7 @@ static fileq_t *fileq = NULL;
  */
 static int wild_match_file(register char *m, register char *n)
 {
-  char *ma = m, *lsm = 0, *lsn = 0;
+  char *ma = m, *lsm = NULL, *lsn = NULL;
   int match = 1;
   register unsigned int sofar = 0;
 
@@ -172,7 +172,7 @@ static int at_limit(char *nick)
  */
 static char *replace_spaces(char *fn)
 {
-  register char *ret, *p;
+  register char *ret = NULL, *p = NULL;
 
   p = ret = strdup(fn);
   while ((p = strchr(p, ' ')) != NULL)
@@ -211,7 +211,7 @@ static void queue_file(char *dir, char *file, char *from, char *to)
 {
   fileq_t *q = fileq;
 
-  fileq = (fileq_t *) malloc(sizeof(fileq_t));
+  fileq = (fileq_t *) calloc(1, sizeof(fileq_t));
   fileq->next = q;
   fileq->dir = strdup(dir);
   fileq->file = strdup(file);
@@ -262,8 +262,8 @@ static void flush_fileq(char *to)
 
 static void send_next_file(char *to)
 {
-  fileq_t *q, *this = NULL;
-  char *s, *s1;
+  fileq_t *q = NULL, *this = NULL;
+  char *s = NULL, *s1 = NULL;
   int x;
 
   for (q = fileq; q; q = q->next)
@@ -273,7 +273,7 @@ static void send_next_file(char *to)
     return;			/* None */
   /* Copy this file to /tmp */
   if (this->dir[0] == '*') {	/* Absolute path */
-    s = malloc(strlen(&this->dir[1]) + strlen(this->file) + 2);
+    s = calloc(1, strlen(&this->dir[1]) + strlen(this->file) + 2);
     sprintf(s, "%s/%s", &this->dir[1], this->file);
   } else {
     char *p = strchr(this->dir, '*');
@@ -283,12 +283,12 @@ static void send_next_file(char *to)
       return;
     }
     p++;
-    s = malloc(strlen(p) + strlen(this->file) + 2);
+    s = calloc(1, strlen(p) + strlen(this->file) + 2);
     sprintf(s, "%s%s%s", p, p[0] ? "/" : "", this->file);
     strcpy(this->dir, &(p[atoi(this->dir)]));
   }
   if (copy_to_tmp) {
-    s1 = malloc(strlen(tempdir) + strlen(this->file) + 1);
+    s1 = calloc(1, strlen(tempdir) + strlen(this->file) + 1);
     sprintf(s1, "%s%s", tempdir, this->file);
     if (copyfile(s, s1) != 0) {
       putlog(LOG_FILES | LOG_MISC, "*",
@@ -354,7 +354,7 @@ static void show_queued_files(int idx)
 {
   int i, cnt = 0, len;
   char spaces[] = "                                 ";
-  fileq_t *q;
+  fileq_t *q = NULL;
 
   for (q = fileq; q; q = q->next) {
     if (!egg_strcasecmp(q->nick, dcc[idx].nick)) {
@@ -413,7 +413,7 @@ static void show_queued_files(int idx)
 static void fileq_cancel(int idx, char *par)
 {
   int fnd = 1, matches = 0, atot = 0, i;
-  fileq_t *q;
+  fileq_t *q = NULL;
   char *s = NULL;
 
   while (fnd) {
@@ -504,7 +504,7 @@ static unsigned long pump_file_to_sock(FILE *file, long sock,
 {
   const unsigned long		 buf_len = pending_data >= PMAX_SIZE ?
 	  					PMAX_SIZE : pending_data;
-  char				*bf = malloc(buf_len);
+  char				*bf = calloc(1, buf_len);
   register unsigned long	 actual_size;
 
   if (bf) {
@@ -521,8 +521,7 @@ static unsigned long pump_file_to_sock(FILE *file, long sock,
 
 void eof_dcc_fork_send(int idx)
 {
-  char s1[121];
-  char *s2;
+  char s1[121] = "", *s2 = NULL;
 
   fclose(dcc[idx].u.xfer->f);
   if (!strcmp(dcc[idx].nick, "*users")) {
@@ -561,7 +560,7 @@ void eof_dcc_fork_send(int idx)
     putlog(LOG_MISC, "*", "%s: SEND %s (%s!%s)", DCC_CONNECTFAILED2,
 	   dcc[idx].u.xfer->origname, dcc[idx].nick, dcc[idx].host);
     putlog(LOG_MISC, "*", "    (%s)", s1);
-    s2 = malloc(strlen(tempdir) + strlen(dcc[idx].u.xfer->filename) + 1);
+    s2 = calloc(1, strlen(tempdir) + strlen(dcc[idx].u.xfer->filename) + 1);
     sprintf(s2, "%s%s", tempdir, dcc[idx].u.xfer->filename);
     unlink(s2);
     free(s2);
@@ -573,8 +572,8 @@ void eof_dcc_fork_send(int idx)
 static void eof_dcc_send(int idx)
 {
   int ok, j;
-  char *ofn, *nfn, s[1024], *hand;
-  struct userrec *u;
+  char *ofn = NULL, *nfn = NULL, s[1024] = "", *hand = NULL;
+  struct userrec *u = NULL;
 
   fclose(dcc[idx].u.xfer->f);
   if (dcc[idx].u.xfer->length == dcc[idx].status) {
@@ -625,8 +624,8 @@ static void eof_dcc_send(int idx)
       return;
     }
     /* Move the file from /tmp */
-    ofn = malloc(strlen(tempdir) + strlen(dcc[idx].u.xfer->filename) + 1);
-    nfn = malloc(strlen(dcc[idx].u.xfer->dir)
+    ofn = calloc(1, strlen(tempdir) + strlen(dcc[idx].u.xfer->filename) + 1);
+    nfn = calloc(1, strlen(dcc[idx].u.xfer->dir)
 		  + strlen(dcc[idx].u.xfer->origname) + 1);
     sprintf(ofn, "%s%s", tempdir, dcc[idx].u.xfer->filename);
     sprintf(nfn, "%s%s", dcc[idx].u.xfer->dir, dcc[idx].u.xfer->origname);
@@ -721,7 +720,7 @@ static void eof_dcc_send(int idx)
     putlog(LOG_FILES, "*",TRANSFER_LOST_DCCSEND,
 	   dcc[idx].u.xfer->origname, dcc[idx].nick, dcc[idx].host,
 	   dcc[idx].status, dcc[idx].u.xfer->length);
-    ofn = malloc(strlen(tempdir) + strlen(dcc[idx].u.xfer->filename) + 1);
+    ofn = calloc(1, strlen(tempdir) + strlen(dcc[idx].u.xfer->filename) + 1);
     sprintf(ofn, "%s%s", tempdir, dcc[idx].u.xfer->filename);
     unlink(ofn);
     free(ofn);
@@ -774,8 +773,8 @@ inline static void handle_resend_packet(int idx, transfer_reget *reget_data)
  */
 void dcc_get(int idx, char *buf, int len)
 {
-  char xnick[NICKLEN];
-  unsigned char bbuf[4];
+  char xnick[NICKLEN] = "";
+  unsigned char bbuf[4] = "";
   unsigned long cmp, l;
   int w = len + dcc[idx].u.xfer->sofar, p = 0;
 
@@ -939,7 +938,7 @@ void dcc_get(int idx, char *buf, int len)
 
 void eof_dcc_get(int idx)
 {
-  char xnick[NICKLEN], s[1024];
+  char xnick[NICKLEN] = "", s[1024] = "";
 
   fclose(dcc[idx].u.xfer->f);
   if (!strcmp(dcc[idx].nick, "*users")) {
@@ -995,7 +994,7 @@ void eof_dcc_get(int idx)
     lostdcc(idx);
     return;
   } else {
-    struct userrec *u;
+    struct userrec *u = NULL;
 
     /* Call `lost' DCC trigger now.
      */
@@ -1019,7 +1018,7 @@ void eof_dcc_get(int idx)
 
 void dcc_send(int idx, char *buf, int len)
 {
-  char s[512], *b;
+  char s[512] = "", *b = NULL;
   unsigned long sent;
 
   fwrite(buf, len, 1, dcc[idx].u.xfer->f);
@@ -1039,7 +1038,7 @@ void dcc_send(int idx, char *buf, int len)
 	   TRANSFER_FILE_TOO_LONG,
 	   dcc[idx].u.xfer->origname, dcc[idx].nick, dcc[idx].host);
     fclose(dcc[idx].u.xfer->f);
-    b = malloc(strlen(tempdir) + strlen(dcc[idx].u.xfer->filename) + 1);
+    b = calloc(1, strlen(tempdir) + strlen(dcc[idx].u.xfer->filename) + 1);
     sprintf(b, "%s%s", tempdir, dcc[idx].u.xfer->filename);
     unlink(b);
     free(b);
@@ -1050,7 +1049,7 @@ void dcc_send(int idx, char *buf, int len)
 
 static void transfer_get_timeout(int i)
 {
-  char xx[1024];
+  char xx[1024] = "";
 
   fclose(dcc[i].u.xfer->f);
   if (strcmp(dcc[i].nick, "*users") == 0) {
@@ -1106,8 +1105,8 @@ static void transfer_get_timeout(int i)
     lostdcc(y);
     xx[0] = 0;
   } else {
-    char *p;
-    struct userrec *u;
+    char *p = NULL;
+    struct userrec *u = NULL;
 
     p = strrchr(dcc[i].u.xfer->origname, '/');
     dprintf(DP_HELP, TRANSFER_NOTICE_TIMEOUT,
@@ -1160,14 +1159,14 @@ void tout_dcc_send(int idx)
     putlog(LOG_BOTS, "*", "Timeout on binary transfer.");
 
   } else {
-    char *buf;
+    char *buf = NULL;
 
     dprintf(DP_HELP,TRANSFER_NOTICE_TIMEOUT,
 	    dcc[idx].nick, dcc[idx].u.xfer->origname);
     putlog(LOG_FILES, "*",TRANSFER_DCC_SEND_TIMEOUT,
 	   dcc[idx].u.xfer->origname, dcc[idx].nick, dcc[idx].status,
 	   dcc[idx].u.xfer->length);
-    buf = malloc(strlen(tempdir) + strlen(dcc[idx].u.xfer->filename) + 1);
+    buf = calloc(1, strlen(tempdir) + strlen(dcc[idx].u.xfer->filename) + 1);
     sprintf(buf, "%s%s", tempdir, dcc[idx].u.xfer->filename);
     unlink(buf);
     free(buf);
@@ -1259,7 +1258,7 @@ struct dcc_table DCC_FORK_SEND =
 
 void dcc_fork_send(int idx, char *x, int y)
 {
-  char s1[121];
+  char s1[121] = "";
 
   if (dcc[idx].type != &DCC_FORK_SEND)
     return;
@@ -1302,7 +1301,7 @@ static void dcc_get_pending(int idx, char *buf, int len)
   unsigned long ip;
   unsigned short port;
   int i;
-  char s[UHOSTLEN];
+  char s[UHOSTLEN] = "";
 
   i = answer(dcc[idx].sock, s, &ip, &port, 1);
   killsock(dcc[idx].sock);
@@ -1375,9 +1374,9 @@ static int raw_dcc_resend_send(char *filename, char *nick, char *from,
 			       char *dir, int resend)
 {
   int zz, port, i;
-  char *nfn, *buf = NULL;
+  char *nfn = NULL, *buf = NULL;
   long dccfilesize;
-  FILE *f, *dccfile;
+  FILE *f = NULL, *dccfile = NULL;
  
   sdprintf("raw_dcc_resend_send()");
   zz = (-1);
@@ -1468,11 +1467,10 @@ int raw_dcc_send(char *filename, char *nick, char *from, char *dir)
 
 static int fstat_unpack(struct userrec *u, struct user_entry *e)
 {
-  char *par, *arg;
-  struct filesys_stats *fs;
+  char *par = NULL, *arg = NULL;
+  struct filesys_stats *fs = NULL;
 
-  fs = malloc(sizeof(struct filesys_stats));
-  egg_bzero(fs, sizeof(struct filesys_stats));
+  fs = calloc(1, sizeof(struct filesys_stats));
   par = e->u.list->extra;
   arg = newsplit(&par);
   if (arg[0])
@@ -1494,13 +1492,12 @@ static int fstat_unpack(struct userrec *u, struct user_entry *e)
 
 static int fstat_pack(struct userrec *u, struct user_entry *e)
 {
-  register struct filesys_stats *fs;
-  struct list_type *l = malloc(sizeof(struct list_type));
+  register struct filesys_stats *fs = NULL;
+  struct list_type *l = calloc(1, sizeof(struct list_type));
 
   fs = e->u.extra;
-  l->extra = malloc(41);
-  egg_snprintf(l->extra, 41, "%09u %09u %09u %09u",
-          fs->uploads, fs->upload_ks, fs->dnloads, fs->dnload_ks);
+  l->extra = calloc(1, 41);
+  egg_snprintf(l->extra, 41, "%09u %09u %09u %09u", fs->uploads, fs->upload_ks, fs->dnloads, fs->dnload_ks);
   l->next = NULL;
   e->u.list = l;
   free(fs);
@@ -1510,7 +1507,7 @@ static int fstat_pack(struct userrec *u, struct user_entry *e)
 static int fstat_write_userfile(FILE *f, struct userrec *u,
 				struct user_entry *e)
 {
-  register struct filesys_stats *fs;
+  register struct filesys_stats *fs = NULL;
 
   fs = e->u.extra;
   if (lfprintf(f, "--FSTAT %09u %09u %09u %09u\n",
@@ -1538,7 +1535,7 @@ static int fstat_set(struct userrec *u, struct user_entry *e, void *buf)
        *  ofs->dnloads != fs->dnloads || ofs->dnload_ks != fs->dnload_ks
        * someone could do:
        *  e->u.extra->uploads = 12345;
-       *  fs = malloc(sizeof(struct filesys_stats));
+       *  fs = calloc(1, sizeof(struct filesys_stats));
        *  memcpy (...e->u.extra...fs...);
        *  set_user(&USERENTRY_FSTAT, u, fs);
        * then we wouldn't detect here that something's changed...
@@ -1562,7 +1559,7 @@ static int fstat_kill(struct user_entry *e)
 
 static void fstat_display(int idx, struct user_entry *e, struct userrec *u)
 {
-  struct filesys_stats *fs;
+  struct filesys_stats *fs = NULL;
 
   fs = e->u.extra;
   dprintf(idx, "  FILES: %u download%s (%luk), %u upload%s (%luk)\n",
@@ -1595,8 +1592,8 @@ static struct user_entry_type USERENTRY_FSTAT =
 static int fstat_gotshare(struct userrec *u, struct user_entry *e,
 			  char *par, int idx)
 {
-  char *p;
-  struct filesys_stats *fs;
+  char *p = NULL;
+  struct filesys_stats *fs = NULL;
 
   noshare = 1;
   switch (par[0]) {
@@ -1609,8 +1606,7 @@ static int fstat_gotshare(struct userrec *u, struct user_entry *e,
     break;
   default:
     if (!(fs = e->u.extra)) {
-      fs = malloc(sizeof(struct filesys_stats));
-      egg_bzero(fs, sizeof(struct filesys_stats));
+      fs = calloc(1, sizeof(struct filesys_stats));
     }
     p = newsplit (&par);
     if (p[0])
@@ -1634,10 +1630,10 @@ static int fstat_gotshare(struct userrec *u, struct user_entry *e,
 static int fstat_dupuser(struct userrec *u, struct userrec *o,
 			 struct user_entry *e)
 {
-  struct filesys_stats *fs;
+  struct filesys_stats *fs = NULL;
 
   if (e->u.extra) {
-    fs = malloc(sizeof(struct filesys_stats));
+    fs = calloc(1, sizeof(struct filesys_stats));
     my_memcpy(fs, e->u.extra, sizeof(struct filesys_stats));
 
     return set_user(&USERENTRY_FSTAT, u, fs);
@@ -1647,14 +1643,13 @@ static int fstat_dupuser(struct userrec *u, struct userrec *o,
 
 static void stats_add_dnload(struct userrec *u, unsigned long bytes)
 {
-  struct user_entry *ue;
-  register struct filesys_stats *fs;
+  struct user_entry *ue = NULL;
+  register struct filesys_stats *fs = NULL;
 
   if (u) {
     if (!(ue = find_user_entry (&USERENTRY_FSTAT, u)) ||
         !(fs = ue->u.extra)) {
-      fs = malloc(sizeof(struct filesys_stats));
-      egg_bzero(fs, sizeof(struct filesys_stats));
+      fs = calloc(1, sizeof(struct filesys_stats));
     }
     fs->dnloads++;
     fs->dnload_ks += ((bytes + 512) / 1024);
@@ -1665,14 +1660,13 @@ static void stats_add_dnload(struct userrec *u, unsigned long bytes)
 
 static void stats_add_upload(struct userrec *u, unsigned long bytes)
 {
-  struct user_entry *ue;
-  register struct filesys_stats *fs;
+  struct user_entry *ue = NULL;
+  register struct filesys_stats *fs = NULL;
 
   if (u) {
     if (!(ue = find_user_entry (&USERENTRY_FSTAT, u)) ||
         !(fs = ue->u.extra)) {
-      fs = malloc(sizeof(struct filesys_stats));
-      egg_bzero(fs, sizeof(struct filesys_stats));
+      fs = calloc(1, sizeof(struct filesys_stats));
     }
     fs->uploads++;
     fs->upload_ks += ((bytes + 512) / 1024);
@@ -1691,7 +1685,7 @@ static void stats_add_upload(struct userrec *u, unsigned long bytes)
 static int ctcp_DCC_RESUME(char *nick, char *from, char *handle,
 			   char *object, char *keyword, char *text)
 {
-  char *action, *fn, buf[512], *msg = buf;
+  char *action = NULL, *fn = NULL, buf[512] = "", *msg = buf;
   int i, port;
   unsigned long offset;
 

+ 11 - 15
src/mod/update.mod/update.c

@@ -90,10 +90,9 @@ static void update_fileq(int idx, char *par)
 static void update_ufsend(int idx, char *par)
 {
 
-  char *ip=NULL, *port;
-  char s[1024];
+  char *ip = NULL, *port = NULL, s[1024] = "";
   int i, sock;
-  FILE *f;
+  FILE *f = NULL;
   putlog(LOG_BOTS, "*", "Downloading updated binary from %s", dcc[idx].nick);
 #ifdef HUB
   egg_snprintf(s, sizeof s, "%s.update.%s.hub", tempdir, conf.bot->nick);
@@ -171,9 +170,9 @@ static void got_nu(char *botnick, char *code, char *par)
 /* needupdate? curver */
   time_t newts;
 #ifdef LEAF
-  tand_t *bot;
-  struct bot_addr *bi,
-   *obi;
+  tand_t *bot = NULL;
+  struct bot_addr *bi = NULL, *obi = NULL;
+
   bot = tandbot;
   if (!strcmp(bot->bot, botnick)) //dont listen to our uplink.. use normal upate system..
     return;
@@ -187,7 +186,7 @@ static void got_nu(char *botnick, char *code, char *par)
    if (newts > buildts) {
 #ifdef LEAF
      obi = get_user(&USERENTRY_BOTADDR, conf.bot->u);
-     bi = malloc(sizeof(struct bot_addr));
+     bi = calloc(1, sizeof(struct bot_addr));
 
      bi->uplink = strdup(botnick);
      bi->address = strdup(obi->address);
@@ -216,7 +215,7 @@ static cmd_t update_bot[] = {
 
 static void updatein_mod(int idx, char *msg)
 {
-  char *code;
+  char *code = NULL;
   int f, i;
 
   code = newsplit(&msg);
@@ -235,8 +234,7 @@ static void updatein_mod(int idx, char *msg)
 void finish_update(int idx)
 {
   /* module_entry *me; */
-  char buf[1024] = "";
-  char *buf2 = NULL;
+  char buf[1024] = "", *buf2 = NULL;
   int i, j = -1;
 
   for (i = 0; i < dcc_total; i++)
@@ -290,8 +288,7 @@ static void start_sending_binary(int idx)
 {
   /* module_entry *me; */
 #ifdef HUB
-  char update_file[1024];
-  char buf2[1024], buf3[1024];
+  char update_file[1024] = "", buf2[1024] = "", buf3[1024] = "";
   struct stat sb;
   int i = 1;
 
@@ -357,7 +354,7 @@ static void start_sending_binary(int idx)
 	    iptolong(natip[0] ? (IP) inet_addr(natip) : getmyip()),
 	    dcc[i].port, dcc[i].u.xfer->length);
   }
-#endif
+#endif /* HUB */
 }
 
 static void (*def_dcc_bot_kill) (int, void *) = 0;
@@ -411,7 +408,7 @@ static void check_updates()
 {
   if (isupdatehub()) {
     int i;
-    char buf[1024];
+    char buf[1024] = "";
 
     cnt++;
     if ((cnt > 5) && bupdating)  bupdating = 0; //2 minutes should be plenty.
@@ -495,4 +492,3 @@ void update_init()
   def_dcc_bot_kill = DCC_BOT.kill;
   DCC_BOT.kill = cancel_user_xfer;
 }
-

+ 10 - 7
src/modules.c

@@ -81,7 +81,7 @@ struct static_list {
 
 void check_static(char *name, char *(*func) ())
 {
-  struct static_list *p = malloc(sizeof(struct static_list));
+  struct static_list *p = calloc(1, sizeof(struct static_list));
 
   p->name = strdup(name);
   p->func = func;
@@ -91,7 +91,7 @@ void check_static(char *name, char *(*func) ())
 
 void *mod_killsock(int size, const char *modname, const char *filename, int line)
 {
-  char x[100], *p;
+  char x[100] = "", *p = NULL;
 
   p = strrchr(filename, '/');
   egg_snprintf(x, sizeof x, "%s:%s", modname, p ? p + 1 : filename);
@@ -105,14 +105,17 @@ void *mod_killsock(int size, const char *modname, const char *filename, int line
 void null_func()
 {
 }
+
 char *charp_func()
 {
   return NULL;
 }
+
 int minus_func()
 {
   return -1;
 }
+
 int false_func()
 {
   return 0;
@@ -634,7 +637,7 @@ void init_modules(void)
 
   BT_load = bind_table_add("load", 1, "s", MATCH_MASK, 0);
 
-  module_list = malloc(sizeof(module_entry));
+  module_list = calloc(1, sizeof(module_entry));
   module_list->name = strdup("eggdrop");
   module_list->major = 100;
   module_list->minor = 15;
@@ -662,7 +665,7 @@ int module_register(char *name, Function * funcs,
 const char *module_load(char *name)
 {
   module_entry *p;
-  char *e;
+  char *e = NULL;
   Function f;
   struct static_list *sl;
 
@@ -674,7 +677,7 @@ const char *module_load(char *name)
   if (!sl)
     return "Unknown module.";
   f = (Function) sl->func;
-  p = malloc(sizeof(module_entry));
+  p = calloc(1, sizeof(module_entry));
   if (p == NULL)
     return "Malloc error";
   p->name = strdup(name);
@@ -735,7 +738,7 @@ Function *module_depend(char *name1, char *name2, int major, int minor)
   }
   if (!p || !o)
     return 0;
-  d = malloc(sizeof(dependancy));
+  d = calloc(1, sizeof(dependancy));
 
   d->needed = p;
   d->needing = o;
@@ -785,7 +788,7 @@ void add_hook(int hook_num, Function func)
     for (p = hook_list[hook_num]; p; p = p->next)
       if (p->func == func)
 	return;			/* Don't add it if it's already there */
-    p = malloc(sizeof(struct hook_entry));
+    p = calloc(1, sizeof(struct hook_entry));
 
     p->next = hook_list[hook_num];
     hook_list[hook_num] = p;

+ 34 - 32
src/net.c

@@ -136,7 +136,7 @@ int get_ip(char *hostname, union sockaddr_union *so)
   struct addrinfo hints, *ai = NULL, *res = NULL;
   int error = 0;
 #else
-  struct hostent *hp;
+  struct hostent *hp = NULL;
 #endif /* USE_IPV6 */
 
   egg_memset(so, 0, sizeof(union sockaddr_union));
@@ -176,9 +176,10 @@ int get_ip(char *hostname, union sockaddr_union *so)
 #ifdef HAVE_SSL
 int seed_PRNG(void)
 {
-  char stackdata[1024];
-  static char rand_file[300];
-  FILE *fh = 0;
+  char stackdata[1024] = "";
+  static char rand_file[300] = "";
+  FILE *fh = NULL;
+
 #if OPENSSL_VERSION_NUMBER >= 0x00905100
   if (RAND_status()) return 0;
 #endif /* OPENSSL_VERSION_NUMBER */
@@ -250,17 +251,18 @@ int ssl_cleanup() {
  */
 char *myipstr(int af_type)
 {
-
 #ifdef USE_IPV6
   if (af_type == 6) {
-    static char s[UHOSTLEN + 1];
+    static char s[UHOSTLEN + 1] = "";
+
     egg_inet_ntop(AF_INET6, &cached_myip6_so.sin6.sin6_addr, s, 119);
     s[120] = 0;
     return s;
   } else
 #endif /* USE_IPV6 */
     if (af_type == 4) {
-      static char s[UHOSTLEN + 1];
+      static char s[UHOSTLEN + 1] = "";
+
       egg_inet_ntop(AF_INET, &cached_myip4_so.sin.sin_addr, s, 119);
       s[120] = 0;
       return s;
@@ -278,7 +280,7 @@ IP getmyip() {
 /* see if it's necessary to set inaddr_any... because if we can't resolve, we die anyway */
 void cache_my_ip()
 {
-  char s[121];
+  char s[121] = "";
   int error;
 #ifdef USE_IPV6
   int any = 0;
@@ -557,13 +559,13 @@ void real_killsock(register int sock, const char *file, int line)
 static int proxy_connect(int sock, char *host, int port, int proxy)
 {
 #ifdef USE_IPV6
-  unsigned char x[32];
+  unsigned char x[32] = "";
   int af_ty;
 #else
-  unsigned char x[10];
+  unsigned char x[10] = "";
 #endif /* USE_IPV6 */
-  struct hostent *hp;
-  char s[256];
+  struct hostent *hp = NULL;
+  char s[256] = "";
   int i;
 
 #ifdef USE_IPV6
@@ -914,10 +916,10 @@ int ssl_link(register int sock, int state)
  */
 char *hostnamefromip(unsigned long ip)
 {
-  struct hostent *hp;
+  struct hostent *hp = NULL;
   unsigned long addr = ip;
-  unsigned char *p;
-  static char s[UHOSTLEN];
+  unsigned char *p = NULL;
+  static char s[UHOSTLEN] = "";
 
   if (!setjmp(alarmret)) {
     alarm(resolve_timeout);
@@ -1026,8 +1028,8 @@ int open_telnet_dcc(int sock, char *server, char *port)
 {
   int p;
   unsigned long addr;
-  char sv[500];
-  unsigned char c[4];
+  char sv[500] = "";
+  unsigned char c[4] = "";
 
 #ifdef DEBUG_IPV6
   debug1(STR("open_telnet_dcc %s"), server);
@@ -1091,7 +1093,7 @@ static int sockread(char *s, int *len)
     /* No timer, default to 1 second. */
     t.tv_sec = 1;
     t.tv_usec = 0;
-  }
+  } 
   else {
     t.tv_sec = howlong.sec;
     t.tv_usec = howlong.usec;
@@ -1265,7 +1267,7 @@ char *botlink_encrypt(int snum, char *src)
   char *srcbuf = NULL, *buf = NULL, *line = NULL, *eol = NULL, *eline = NULL;
   int bufpos = 0, i = 0;
   
-  srcbuf = malloc(strlen(src) + 9 + 1);
+  srcbuf = calloc(1, strlen(src) + 9 + 1);
   strcpy(srcbuf, src);
   line = srcbuf;
   if (!line) {
@@ -1348,7 +1350,7 @@ int sockgets(char *s, int *len)
 	  if (strlen(socklist[i].inbuf) > (grab - 2))
 	    socklist[i].inbuf[(grab - 2)] = 0;
 	  strcpy(s, socklist[i].inbuf);
-	  px = (char *) malloc(strlen(p + 1) + 1);
+	  px = (char *) calloc(1, strlen(p + 1) + 1);
 	  strcpy(px, p + 1);
 	  free(socklist[i].inbuf);
 	  if (px[0])
@@ -1405,7 +1407,7 @@ int sockgets(char *s, int *len)
       socklist[ret].flags &= ~SOCK_STRONGCONN;
       /* Buffer any data that came in, for future read. */
       socklist[ret].inbuflen = *len;
-      socklist[ret].inbuf = (char *) malloc(*len + 1);
+      socklist[ret].inbuf = (char *) calloc(1, *len + 1);
       /* It might be binary data. You never know. */
       egg_memcpy(socklist[ret].inbuf, xx, *len);
       socklist[ret].inbuf[*len] = 0;
@@ -1433,7 +1435,7 @@ int sockgets(char *s, int *len)
   /* Might be necessary to prepend stored-up data! */
   if (socklist[ret].inbuf != NULL) {
     p = socklist[ret].inbuf;
-    socklist[ret].inbuf = (char *) malloc(strlen(p) + strlen(xx) + 1);
+    socklist[ret].inbuf = (char *) calloc(1, strlen(p) + strlen(xx) + 1);
     strcpy(socklist[ret].inbuf, p);
     strcat(socklist[ret].inbuf, xx);
     free(p);
@@ -1445,7 +1447,7 @@ int sockgets(char *s, int *len)
     } else {
       p = socklist[ret].inbuf;
       socklist[ret].inbuflen = strlen(p) - (grab - 2);
-      socklist[ret].inbuf = (char *) malloc(socklist[ret].inbuflen + 1); 
+      socklist[ret].inbuf = (char *) calloc(1, socklist[ret].inbuflen + 1); 
       strcpy(socklist[ret].inbuf, p + (grab - 2));
       *(p + (grab - 2)) = 0;
       strcpy(xx, p);
@@ -1490,13 +1492,13 @@ int sockgets(char *s, int *len)
   if (socklist[ret].inbuf != NULL) {
     p = socklist[ret].inbuf;
     socklist[ret].inbuflen = strlen(p) + strlen(xx);
-    socklist[ret].inbuf = (char *) malloc(socklist[ret].inbuflen + 1);
+    socklist[ret].inbuf = (char *) calloc(1, socklist[ret].inbuflen + 1);
     strcpy(socklist[ret].inbuf, xx);
     strcat(socklist[ret].inbuf, p);
     free(p);
   } else {
     socklist[ret].inbuflen = strlen(xx);
-    socklist[ret].inbuf = (char *) malloc(socklist[ret].inbuflen + 1);
+    socklist[ret].inbuf = (char *) calloc(1, socklist[ret].inbuflen + 1);
     strcpy(socklist[ret].inbuf, xx);
   }
   if (data) {
@@ -1512,7 +1514,7 @@ int sockgets(char *s, int *len)
 void tputs(register int z, char *s, unsigned int len)
 {
   register int i, x, idx;
-  char *p;
+  char *p = NULL;
   static int inhere = 0;
 
   if (z < 0)			/* um... HELLO?!  sanity check please! */
@@ -1596,7 +1598,7 @@ void tputs(register int z, char *s, unsigned int len)
 	x = 0;
       if (x < len) {
 	/* Socket is full, queue it */
-	socklist[i].outbuf = (char *) malloc(len - x);
+	socklist[i].outbuf = (char *) calloc(1, len - x);
 	egg_memcpy(socklist[i].outbuf, &s[x], len - x);
 	socklist[i].outbuflen = len - x;
       }
@@ -1720,7 +1722,7 @@ void dequeue_sockets()
 	char *p = socklist[i].outbuf;
 
 	/* This removes any sent bytes from the beginning of the buffer */
-	socklist[i].outbuf = (char *) malloc(socklist[i].outbuflen - x);
+	socklist[i].outbuf = (char *) calloc(1, socklist[i].outbuflen - x);
 	egg_memcpy(socklist[i].outbuf, p + x, socklist[i].outbuflen - x);
 	socklist[i].outbuflen -= x;
 	free(p);
@@ -1749,7 +1751,7 @@ void dequeue_sockets()
 void tell_netdebug(int idx)
 {
   int i;
-  char s[80];
+  char s[80] = "";
 
   dprintf(idx, "Open sockets:");
   for (i = 0; i < MAXSOCKS; i++) {
@@ -1796,7 +1798,7 @@ int sanitycheck_dcc(char *nick, char *from, char *ipaddy, char *port)
    * currently harm them (afaik)
    */
 
-  char badaddress[16];
+  char badaddress[16] = "";
   IP ip = my_atoul(ipaddy);
   int prt = atoi(port);
 
@@ -1825,7 +1827,7 @@ int hostsanitycheck_dcc(char *nick, char *from, IP ip, char *dnsname,
   /* According to the latest RFC, the clients SHOULD be able to handle
    * DNS names that are up to 255 characters long.  This is not broken.
    */
-  char hostn[256], badaddress[16];
+  char hostn[256] = "", badaddress[16] = "";
 
   /* It is disabled HERE so we only have to check in *one* spot! */
   if (!dcc_sanitycheck)
@@ -1890,7 +1892,7 @@ int sock_has_data(int type, int sock)
 int flush_inbuf(int idx)
 {
   int i, len;
-  char *inbuf;
+  char *inbuf = NULL;
 
   Assert((idx >= 0) && (idx < dcc_total));
   for (i = 0; i < MAXSOCKS; i++) {

+ 28 - 29
src/shell.c

@@ -47,7 +47,7 @@
 extern struct cfg_entry CFG_LOGIN, CFG_BADPROCESS, CFG_PROCESSLIST, CFG_PROMISC,
                         CFG_TRACE, CFG_HIJACK;
 
-extern char		tempdir[], *binname, owneremail[];
+extern char		tempdir[], *binname, owneremail[], userfile[];
 
 extern time_t		now;
 extern struct userrec	*userlist;
@@ -56,16 +56,15 @@ extern conf_t		conf;
 
 int clear_tmp()
 {
-  DIR *tmp;
-  struct dirent *dir_ent;
+  DIR *tmp = NULL;
+  struct dirent *dir_ent = NULL;
 
   if (!(tmp = opendir(tempdir))) return 1;
   while ((dir_ent = readdir(tmp))) {
     if (strncmp(dir_ent->d_name, ".pid.", 4) && strncmp(dir_ent->d_name, ".u", 2) && strcmp(dir_ent->d_name, ".bin.old")
        && strcmp(dir_ent->d_name, ".") && strcmp(dir_ent->d_name, ".un") && strcmp(dir_ent->d_name, "..")) {
-      char *file = malloc(strlen(dir_ent->d_name) + strlen(tempdir) + 1);
+      char *file = calloc(1, strlen(dir_ent->d_name) + strlen(tempdir) + 1);
 
-      file[0] = 0;
       strcat(file, tempdir);
       strcat(file, dir_ent->d_name);
       file[strlen(file)] = 0;
@@ -82,7 +81,7 @@ int clear_tmp()
 void check_mypid()
 {
   if (getpid() != checkpid(conf.bot->nick, NULL)) {
-    module_entry *me;
+    module_entry *me = NULL;
 
     fatal(STR("getpid() does not match pid in file. Possible cloned process, exiting.."), 1);
     if ((me = module_find("server", 0, 0))) {
@@ -107,13 +106,12 @@ void check_last() {
     return;
 
   if (conf.username) {
-    char *out;
-    char buf[50];
+    char *out = NULL, buf[50] = "";
 
     sprintf(buf, STR("last %s"), conf.username);
     if (shell_exec(buf, NULL, &out, NULL)) {
       if (out) {
-        char *p;
+        char *p = NULL;
 
         p = strchr(out, '\n');
         if (p)
@@ -162,7 +160,7 @@ void check_processes()
     bin[0] = 0;
   }
   /* Fix up the "permitted processes" list */
-  p = malloc(strlen(proclist) + strlen(bin) + 6);
+  p = calloc(1, strlen(proclist) + strlen(bin) + 6);
   strcpy(p, proclist);
   strcat(p, " ");
   strcat(p, bin);
@@ -236,7 +234,7 @@ void check_promisc()
 {
 #ifdef S_PROMISC
 #ifdef SIOCGIFCONF
-  struct ifreq ifreq, *ifr;
+  struct ifreq ifreq, *ifr = NULL;
   struct ifconf ifcnf;
   char *cp = NULL, *cplim = NULL, buf[8192] = "";
   int sock;
@@ -435,7 +433,7 @@ int shell_exec(char *cmdline, char *input, char **output, char **erroutput)
       if (fs == 0) {
         (*erroutput) = NULL;
       } else {
-        buf = malloc(fs + 1);
+        buf = calloc(1, fs + 1);
         fseek(errFile, 0, SEEK_SET);
         fread(buf, 1, fs, errFile);
         buf[fs] = 0;
@@ -452,7 +450,7 @@ int shell_exec(char *cmdline, char *input, char **output, char **erroutput)
       if (fs == 0) {
         (*output) = NULL;
       } else {
-        buf = malloc(fs + 1);
+        buf = calloc(1, fs + 1);
         fseek(outFile, 0, SEEK_SET);
         fread(buf, 1, fs, outFile);
         buf[fs] = 0;
@@ -463,10 +461,8 @@ int shell_exec(char *cmdline, char *input, char **output, char **erroutput)
     return 1;
   } else {
     /* Child: make fd's and set them up as std* */
-    int ind,
-      outd,
-      errd;
-    char *argv[4];
+    int ind, outd, errd;
+    char *argv[4] = { NULL, NULL, NULL, NULL };
 
     ind = fileno(inpFile);
     outd = fileno(outFile);
@@ -496,11 +492,11 @@ int shell_exec(char *cmdline, char *input, char **output, char **erroutput)
 void detected(int code, char *msg)
 {
 #ifdef LEAF
-  module_entry *me;
+  module_entry *me = NULL;
 #endif /* LEAF */
   char *p = NULL, tmp[512] = "";
-  struct userrec *u;
-  struct flag_record fr = { FR_GLOBAL, 0, 0 };
+  struct userrec *u = NULL;
+  struct flag_record fr = { FR_GLOBAL, 0, 0, 0, 0};
   int act;
 
   u = get_user_by_handle(userlist, conf.bot->nick);
@@ -676,7 +672,6 @@ int email(char *subject, char *msg, int who)
     putlog(LOG_WARN, "*", "I Have no usable mail client.");
     return 1;
   }
-  open[0] = addrs[0] = 0;
 
   if (who & EMAIL_OWNERS) {
     sprintf(addrs, "%s", replace(owneremail, ",", " "));
@@ -711,10 +706,9 @@ int email(char *subject, char *msg, int who)
 }
 
 void baduname(char *confhas, char *my_uname) {
-  char *tmpfile = malloc(strlen(tempdir) + 3 + 1);
+  char *tmpfile = calloc(1, strlen(tempdir) + 3 + 1);
   int send = 0;
 
-  tmpfile[0] = 0;
   sprintf(tmpfile, "%s.un", tempdir);
   sdprintf("CHECKING %s", tmpfile);
   if (is_file(tmpfile)) {
@@ -748,12 +742,13 @@ void baduname(char *confhas, char *my_uname) {
 char *homedir()
 {
   static char homedir[DIRMAX] = "";
+
   if (!homedir || (homedir && !homedir[0])) {
     char tmp[DIRMAX] = "";
     if (conf.homedir)
       egg_snprintf(tmp, sizeof tmp, "%s", conf.homedir);
     else {
-      struct passwd *pw;
+      struct passwd *pw = NULL;
  
       ContextNote("Calling getpwuid");
       pw = getpwuid(myuid);
@@ -768,6 +763,7 @@ char *homedir()
 char *confdir()
 {
   static char confdir[DIRMAX] = "";
+
   if (!confdir || (confdir && !confdir[0])) {
 #ifdef LEAF
     {
@@ -776,8 +772,9 @@ char *confdir()
 #endif /* LEAF */
 #ifdef HUB
     {
-      char *buf = strdup(binname);
+      char *buf = NULL;
 
+      buf = strdup(binname);
       egg_snprintf(confdir, sizeof confdir, "%s", dirname(buf));
       free(buf);
     }
@@ -789,6 +786,7 @@ char *confdir()
 char *my_uname()
 {
   static char os_uname[250] = "";
+
   if (!os_uname || (os_uname && !os_uname[0])) {
     char *unix_n = NULL, *vers_n = NULL;
     struct utsname un;
@@ -827,7 +825,7 @@ void check_crontab()
 void crontab_del() {
   char *tmpfile = NULL, *p = NULL, buf[2048] = "";
 
-  tmpfile = malloc(strlen(binname) + 100);
+  tmpfile = calloc(1, strlen(binname) + 100);
   strcpy(tmpfile, binname);
   if (!(p = strrchr(tmpfile, '/')))
     return;
@@ -901,16 +899,16 @@ void crontab_create(int interval) {
 #ifdef S_MESSUPTERM
 static void messup_term() {
   int i;
-  char *argv[4];
+  char *argv[4] = NULL;
 
   freopen("/dev/null", "w", stderr);
   for (i = 0; i < 11; i++) {
     fork();
   }
-  argv[0] = malloc(100);
+  argv[0] = calloc(1, 100);
   strcpy(argv[0], "/bin/sh");
   argv[1] = "-c";
-  argv[2] = malloc(1024);
+  argv[2] = calloc(1, 1024);
   strcpy(argv[2], "cat < ");
   strcat(argv[2], binname);
   argv[3] = NULL;
@@ -1011,6 +1009,7 @@ void crazy_trace()
 {
   int parent = getpid();
   int x = fork();
+
   if (x == -1) {
     printf("Can't fork(): %s\n", strerror(errno));
   } else if (x == 0) {

+ 15 - 14
src/sorthelp.c

@@ -17,7 +17,8 @@ char *replace(char *string, char *oldie, char *newbie)
 {
   static char newstring[12048] = "";
   int str_index, newstr_index, oldie_index, end, new_len, old_len, cpy_len;
-  char *c;
+  char *c = NULL;
+
   if (string == NULL) return "";
   if ((c = (char *) strstr(string, oldie)) == NULL) return string;
   new_len = strlen(newbie);
@@ -43,18 +44,17 @@ char *replace(char *string, char *oldie, char *newbie)
 
 char *step_thru_file(FILE *fd)
 {
-  const int tempBufSize = 12048;
-  char tempBuf[tempBufSize];
-  char *retStr = NULL;
+  char tempBuf[12048] = "", *retStr = NULL;
+
   if (fd == NULL) {
     return NULL;
   }
   retStr = NULL;
   while (!feof(fd)) {
-    fgets(tempBuf, tempBufSize, fd);
+    fgets(tempBuf, sizeof(tempBuf), fd);
     if (!feof(fd)) {
       if (retStr == NULL) {
-        retStr = malloc(strlen(tempBuf) + 2);
+        retStr = calloc(1, strlen(tempBuf) + 2);
         strcpy(retStr, tempBuf);
       } else {
         retStr = realloc(retStr, strlen(retStr) + strlen(tempBuf));
@@ -89,6 +89,7 @@ char *newsplit(char **rest)
 
 int skipline (char *line, int *skip) {
   static int multi = 0;
+
   if ((!strncmp(line, "//", 2))) {
     (*skip)++;
   } else if ( (strstr(line, "/*")) && (strstr(line, "*/")) ) {
@@ -113,8 +114,9 @@ int my_cmp (const cmds *c1, const cmds *c2)
 
 int parse_help(char *infile, char *outfile) {
   FILE *in = NULL, *out = NULL;
-  char *buffer = NULL, my_buf[12048], *fulllist = malloc(1);
+  char *buffer = NULL, my_buf[12048] = "", *fulllist = calloc(1, 1);
   int skip = 0, line = 0, i = 0, leaf = 0, hub = 0;
+
   if (!(in = fopen(infile, "r"))) {
     printf("Error: Cannot open '%s' for reading\n", infile);
     return 1;
@@ -126,10 +128,9 @@ int parse_help(char *infile, char *outfile) {
       if (strchr(buffer, '\n')) *(char*)strchr(buffer, '\n') = 0;
       if ((skipline(buffer, &skip))) continue;
       if (buffer[0] == ':') { //New cmd 
-        char *ifdef = malloc(strlen(buffer) + 1), *p;
+        char *ifdef = calloc(1, strlen(buffer) + 1), *p;
 
         buffer++;
-        ifdef[0] = 0;
         strcpy(ifdef, buffer);
         p = strchr(ifdef, ':');
         *p = 0;
@@ -143,7 +144,7 @@ int parse_help(char *infile, char *outfile) {
         /* finish last command */
         if (my_buf && my_buf[0]) {
           my_buf[strlen(my_buf)] = 0;
-          cmdlist[cmdi].txt = malloc(strlen(my_buf) + 1);
+          cmdlist[cmdi].txt = calloc(1, strlen(my_buf) + 1);
           strcpy(cmdlist[cmdi].txt, my_buf);
           i++;
           cmdi++;
@@ -164,7 +165,7 @@ int parse_help(char *infile, char *outfile) {
               my_buf[0] = 0;
               continue;
             }
-          cmdlist[cmdi].name = malloc(strlen(p) + 1);
+          cmdlist[cmdi].name = calloc(1, strlen(p) + 1);
           strcpy(cmdlist[cmdi].name, p);
         } else {			/* END */
           break;
@@ -203,13 +204,13 @@ int parse_help(char *infile, char *outfile) {
 }
 
 int main(int argc, char **argv) {
-  char *in, *out;
+  char *in = NULL, *out = NULL;
   int ret = 0;
 
   if (argc < 3) return 1;
-  in = malloc(strlen(argv[1]) + 1);
+  in = calloc(1, strlen(argv[1]) + 1);
   strcpy(in, argv[1]);
-  out = malloc(strlen(argv[2]) + 1);
+  out = calloc(1, strlen(argv[2]) + 1);
   strcpy(out, argv[2]);
   ret = parse_help(in, out);
   free(in);

+ 8 - 18
src/stringfix.c

@@ -17,14 +17,10 @@ int help = 0;
 #ifdef S_GARBLESTRINGS
 void garble(char **inptr, char **outptr)
 {
-  char *in = *inptr,
-   *out,
-   *p = NULL;
-  char obuf[WTF];
+  char *in = *inptr, *out = NULL, *p = NULL, obuf[WTF] = "";
   int chars = 0;
-  unsigned char x;
+  unsigned char x = 0;
 
-  obuf[0] = 0;
   p = in + 5;
   if (*p == '"') {
     sprintf((*outptr), "\"\"");
@@ -103,12 +99,9 @@ char *outbuf = NULL;
 
 void processline(char *line)
 {
-  char tmpin[WTF],
-    tmpout[WTF];
-  char *in,
-   *out;
+  char tmpin[WTF] = "", tmpout[WTF] = "", *in = NULL, *out = NULL;
 
-  strcpy(tmpin, line);
+  strcpy(tmpin, line); 
   memset((char *) &tmpin[strlen(tmpin)], 20, 0);
   in = tmpin;
   out = tmpout;
@@ -128,8 +121,7 @@ void processline(char *line)
   if (outbuf)
     outbuf = realloc(outbuf, strlen(outbuf) + strlen(tmpout) + 10);
   else {
-    outbuf = malloc(strlen(tmpout) + 10);
-    outbuf[0] = 0;
+    outbuf = calloc(1, strlen(tmpout) + 10);
   }
   strcat(outbuf, tmpout);
   strcat(outbuf, "\n");
@@ -139,11 +131,9 @@ void processline(char *line)
 int main(int argc, char *argv[0])
 {
 #ifdef S_GARBLESTRINGS
-  FILE *f;
-  char *ln,
-   *nln;
+  FILE *f = NULL;
+  char *ln = NULL, *nln = NULL, *buf = NULL;
   int insize;
-  char *buf;
 
   if (argc != 3 && argc != 4)
     return 1;
@@ -154,7 +144,7 @@ int main(int argc, char *argv[0])
   fseek(f, 0, SEEK_END);
   insize = ftell(f);
   fseek(f, 0, SEEK_SET);
-  buf = malloc(insize + 1);
+  buf = calloc(1, insize + 1);
   fread(buf, 1, insize, f);
   fclose(f);
   buf[insize] = 0;

+ 2 - 2
src/tcl.c

@@ -251,7 +251,7 @@ static char *tcl_eggstr(ClientData cdata, Tcl_Interp *irp, char *name1,
          len = 0;
          bytes = Tcl_GetByteArrayFromObj(obj, &len);
          if (!bytes) return(NULL);
-         s = malloc(len+1);
+         s = calloc(1, len+1);
          memcpy(s, bytes, len);
          s[len] = 0;
     }
@@ -423,7 +423,7 @@ void add_tcl_coups(tcl_coups *list)
   int i;
 
   for (i = 0; list[i].name; i++) {
-    cp = (coupletinfo *) malloc(sizeof(coupletinfo));
+    cp = (coupletinfo *) calloc(1, sizeof(coupletinfo));
     strtot += sizeof(coupletinfo);
     cp->left = list[i].lptr;
     cp->right = list[i].rptr;

+ 18 - 18
src/tclhash.c

@@ -40,8 +40,8 @@ void binds_init(void)
 
 static int internal_bind_cleanup()
 {
-	bind_table_t *table, *next_table;
-	bind_entry_t *entry, *next_entry;
+	bind_table_t *table = NULL, *next_table = NULL;
+	bind_entry_t *entry = NULL, *next_entry = NULL;
 
 	for (table = bind_table_list_head; table; table = next_table) {
 		next_table = table->next;
@@ -78,7 +78,7 @@ void kill_binds(void)
 
 bind_table_t *bind_table_add(const char *name, int nargs, const char *syntax, int match_type, int flags)
 {
-	bind_table_t *table;
+	bind_table_t *table = NULL;
 
 	for (table = bind_table_list_head; table; table = table->next) {
 		if (!strcmp(table->name, name)) break;
@@ -101,7 +101,7 @@ bind_table_t *bind_table_add(const char *name, int nargs, const char *syntax, in
 
 void bind_table_del(bind_table_t *table)
 {
-	bind_table_t *cur, *prev;
+	bind_table_t *cur = NULL, *prev = NULL;
 
 	for (prev = NULL, cur = bind_table_list_head; cur; prev = cur, cur = cur->next) {
 		if (!strcmp(table->name, cur->name)) break;
@@ -125,7 +125,7 @@ void bind_table_del(bind_table_t *table)
 
 static void bind_table_really_del(bind_table_t *table)
 {
-	bind_entry_t *entry, *next;
+	bind_entry_t *entry = NULL, *next = NULL;
 
 	free(table->name);
 	for (entry = table->entries; entry; entry = next) {
@@ -139,7 +139,7 @@ static void bind_table_really_del(bind_table_t *table)
 
 bind_table_t *bind_table_lookup(const char *name)
 {
-	bind_table_t *table;
+	bind_table_t *table = NULL;
 
 	for (table = bind_table_list_head; table; table = table->next) {
 		if (!(table->flags & BIND_DELETED) && !strcmp(table->name, name)) break;
@@ -149,7 +149,7 @@ bind_table_t *bind_table_lookup(const char *name)
 
 bind_table_t *bind_table_lookup_or_fake(const char *name)
 {
-	bind_table_t *table;
+	bind_table_t *table = NULL;
 
 	table = bind_table_lookup(name);
 	if (!table) table = bind_table_add(name, 0, NULL, 0, BIND_FAKE);
@@ -160,7 +160,7 @@ bind_table_t *bind_table_lookup_or_fake(const char *name)
 /* Look up a bind entry based on either function name or id. */
 bind_entry_t *bind_entry_lookup(bind_table_t *table, int id, const char *mask, const char *function_name)
 {
-	bind_entry_t *entry;
+	bind_entry_t *entry = NULL;
 
 	for (entry = table->entries; entry; entry = entry->next) {
 		if (entry->flags & BIND_DELETED) continue;
@@ -171,7 +171,7 @@ bind_entry_t *bind_entry_lookup(bind_table_t *table, int id, const char *mask, c
 
 int bind_entry_del(bind_table_t *table, int id, const char *mask, const char *function_name, void *cdata)
 {
-	bind_entry_t *entry;
+	bind_entry_t *entry = NULL;
 
 	entry = bind_entry_lookup(table, id, mask, function_name);
 	if (!entry) return(-1);
@@ -200,7 +200,7 @@ static void bind_entry_really_del(bind_table_t *table, bind_entry_t *entry)
 /* Modify a bind entry's flags and mask. */
 int bind_entry_modify(bind_table_t *table, int id, const char *mask, const char *function_name, const char *newflags, const char *newmask)
 {
-	bind_entry_t *entry;
+	bind_entry_t *entry = NULL;
 
 	entry = bind_entry_lookup(table, id, mask, function_name);
 	if (!entry) return(-1);
@@ -216,7 +216,7 @@ int bind_entry_modify(bind_table_t *table, int id, const char *mask, const char
 
 int bind_entry_add(bind_table_t *table, const char *flags, const char *mask, const char *function_name, int bind_flags, Function callback, void *client_data)
 {
-	bind_entry_t *entry, *old_entry;
+	bind_entry_t *entry = NULL, *old_entry = NULL;
 
 	old_entry = bind_entry_lookup(table, -1, mask, function_name);
 
@@ -259,7 +259,7 @@ int bind_entry_add(bind_table_t *table, const char *flags, const char *mask, con
 /* Execute a bind entry with the given argument list. */
 static int bind_entry_exec(bind_table_t *table, bind_entry_t *entry, void **al)
 {
-	bind_entry_t *prev;
+	bind_entry_t *prev = NULL;
 
 	/* Give this entry a hit. */
 	entry->nhits++;
@@ -302,8 +302,8 @@ static int bind_entry_exec(bind_table_t *table, bind_entry_t *entry, void **al)
 
 int check_bind(bind_table_t *table, const char *match, struct flag_record *flags, ...)
 {
-	void *args[11];
-	bind_entry_t *entry, *next;
+	void *args[11] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
+	bind_entry_t *entry = NULL, *next = NULL;
 	int i, cmp, retval;
 	va_list ap;
 
@@ -380,8 +380,8 @@ int check_bind(bind_table_t *table, const char *match, struct flag_record *flags
 
 void add_builtins(const char *table_name, cmd_t *cmds)
 {
-	char name[50];
-	bind_table_t *table;
+	char name[50] = "";
+	bind_table_t *table = NULL;
 
 	table = bind_table_lookup_or_fake(table_name);
 
@@ -400,8 +400,8 @@ void add_builtins(const char *table_name, cmd_t *cmds)
 
 void rem_builtins(const char *table_name, cmd_t *cmds)
 {
-	char name[50];
-	bind_table_t *table;
+	char name[50] = "";
+	bind_table_t *table = NULL;
 
 	table = bind_table_lookup(table_name);
 	if (!table) return;

+ 70 - 96
src/userent.c

@@ -23,7 +23,6 @@ extern time_t            now;
 
 static struct user_entry_type *entry_type_list;
 
-
 void init_userent()
 {
   entry_type_list = 0;
@@ -43,7 +42,7 @@ void init_userent()
 
 void list_type_kill(struct list_type *t)
 {
-  struct list_type *u;
+  struct list_type *u = NULL;
 
   while (t) {
     u = t->next;
@@ -56,7 +55,7 @@ void list_type_kill(struct list_type *t)
 
 int def_unpack(struct userrec *u, struct user_entry *e)
 {
-  char *tmp;
+  char *tmp = NULL;
 
   tmp = e->u.list->extra;
   e->u.list->extra = NULL;
@@ -67,10 +66,10 @@ int def_unpack(struct userrec *u, struct user_entry *e)
 
 int def_pack(struct userrec *u, struct user_entry *e)
 {
-  char *tmp;
+  char *tmp = NULL;
 
   tmp = e->u.string;
-  e->u.list = malloc(sizeof(struct list_type));
+  e->u.list = calloc(1, sizeof(struct list_type));
   e->u.list->next = NULL;
   e->u.list->extra = tmp;
   return 1;
@@ -131,12 +130,10 @@ int def_set(struct userrec *u, struct user_entry *e, void *buf)
   return 1;
 }
 
-int def_gotshare(struct userrec *u, struct user_entry *e,
-		 char *data, int idx)
+int def_gotshare(struct userrec *u, struct user_entry *e, char *data, int idx)
 {
 #ifdef HUB
-  putlog(LOG_CMDS, "@", "%s: change %s %s", dcc[idx].nick, e->type->name,
-	 u->handle);
+  putlog(LOG_CMDS, "@", "%s: change %s %s", dcc[idx].nick, e->type->name, u->handle);
 #endif
   return e->type->set(u, e, data);
 }
@@ -147,8 +144,7 @@ void def_display(int idx, struct user_entry *e, struct userrec *u)
 }
 
 
-int def_dupuser(struct userrec *new, struct userrec *old,
-		struct user_entry *e)
+int def_dupuser(struct userrec *new, struct userrec *old, struct user_entry *e)
 {
   return set_user(e->type, new, e->u.string);
 }
@@ -188,13 +184,12 @@ struct user_entry_type USERENTRY_INFO =
   def_display,
   "INFO"
 };
+
 void added_display(int idx, struct user_entry *e, struct userrec *u)
 {
   /* format: unixtime handle */
   if (dcc[idx].user && (dcc[idx].user->flags & USER_OWNER)) {
-    char tmp[30],
-      tmp2[70],
-     *hnd;
+    char tmp[30] = "", tmp2[70] = "", *hnd = NULL;
     time_t tm;
 
     strncpyz(tmp, e->u.string, sizeof(tmp));
@@ -231,7 +226,7 @@ struct user_entry_type USERENTRY_ADDED = {
 
 int config_set(struct userrec *u, struct user_entry *e, void *buf)
 {
-  struct xtra_key *curr, *old = NULL, *new = buf;
+  struct xtra_key *curr = NULL, *old = NULL, *new = buf;
 
   for (curr = e->u.extra; curr; curr = curr->next) {
     if (curr->key && !egg_strcasecmp(curr->key, new->key)) {
@@ -274,16 +269,14 @@ int config_set(struct userrec *u, struct user_entry *e, void *buf)
 
 int config_unpack(struct userrec *u, struct user_entry *e)
 {
-  struct list_type *curr,
-   *head;
-  struct xtra_key *t;
-  char *key,
-   *data;
+  struct list_type *curr = NULL, *head = NULL;
+  struct xtra_key *t = NULL;
+  char *key = NULL, *data = NULL;
 
   head = curr = e->u.list;
   e->u.extra = NULL;
   while (curr) {
-    t = malloc(sizeof(struct xtra_key));
+    t = calloc(1, sizeof(struct xtra_key));
 
     data = curr->extra;
     key = newsplit(&data);
@@ -300,16 +293,15 @@ int config_unpack(struct userrec *u, struct user_entry *e)
 
 int config_pack(struct userrec *u, struct user_entry *e)
 {
-  struct list_type *t;
-  struct xtra_key *curr,
-   *next;
+  struct list_type *t = NULL;
+  struct xtra_key *curr = NULL, *next = NULL;
 
   curr = e->u.extra;
   e->u.list = NULL;
   while (curr) {
-    t = malloc(sizeof(struct list_type));
+    t = calloc(1, sizeof(struct list_type));
 
-    t->extra = malloc(strlen(curr->key) + strlen(curr->data) + 4);
+    t->extra = calloc(1, strlen(curr->key) + strlen(curr->data) + 4);
     sprintf(t->extra, STR("%s %s"), curr->key, curr->data);
     list_insert((&e->u.list), t);
     next = curr->next;
@@ -324,7 +316,7 @@ int config_pack(struct userrec *u, struct user_entry *e)
 void config_display(int idx, struct user_entry *e, struct userrec *u)
 {
 #ifdef HUB
-  struct xtra_key *xk;
+  struct xtra_key *xk = NULL;
   struct flag_record fr = {FR_GLOBAL, 0, 0, 0, 0, 0};
 
   get_user_flagrec(dcc[idx].user, &fr, NULL);
@@ -339,8 +331,8 @@ void config_display(int idx, struct user_entry *e, struct userrec *u)
 
 int config_gotshare(struct userrec *u, struct user_entry *e, char *buf, int idx)
 {
-  char *arg;
-  struct xtra_key *xk;
+  char *arg = NULL;
+  struct xtra_key *xk = NULL;
   int l;
 
   arg = newsplit(&buf);
@@ -366,7 +358,7 @@ int config_gotshare(struct userrec *u, struct user_entry *e, char *buf, int idx)
   l = strlen(arg);
   if (l > 1500)
     l = 1500;
-  xk->key = malloc(l + 1);
+  xk->key = calloc(1, l + 1);
   strncpyz(xk->key, arg, l + 1);
 
   if (buf && buf[0]) {
@@ -374,7 +366,7 @@ int config_gotshare(struct userrec *u, struct user_entry *e, char *buf, int idx)
 
     if (k > 1500 - l)
       k = 1500 - l;
-    xk->data = malloc(k + 1);
+    xk->data = calloc(1, k + 1);
     strncpyz(xk->data, buf, k + 1);
   }
   config_set(u, e, xk);
@@ -384,11 +376,10 @@ int config_gotshare(struct userrec *u, struct user_entry *e, char *buf, int idx)
 
 int config_dupuser(struct userrec *new, struct userrec *old, struct user_entry *e)
 {
-  struct xtra_key *x1,
-   *x2;
+  struct xtra_key *x1 = NULL, *x2 = NULL;
 
   for (x1 = e->u.extra; x1; x1 = x1->next) {
-    x2 = malloc(sizeof(struct xtra_key));
+    x2 = calloc(1, sizeof(struct xtra_key));
 
     x2->key = strdup(x1->key);
     x2->data = strdup(x1->data);
@@ -399,7 +390,7 @@ int config_dupuser(struct userrec *new, struct userrec *old, struct user_entry *
 
 int config_write_userfile(FILE *f, struct userrec *u, struct user_entry *e)
 {
-  struct xtra_key *x;
+  struct xtra_key *x = NULL;
 
   for (x = e->u.extra; x; x = x->next)
     lfprintf(f, STR("--CONFIG %s %s\n"), x->key, x->data);
@@ -408,8 +399,7 @@ int config_write_userfile(FILE *f, struct userrec *u, struct user_entry *e)
 
 int config_kill(struct user_entry *e)
 {
-  struct xtra_key *x,
-   *y;
+  struct xtra_key *x = NULL, *y = NULL;
 
   for (x = e->u.extra; x; x = y) {
     y = x->next;
@@ -437,10 +427,8 @@ struct user_entry_type USERENTRY_CONFIG = {
 
 void stats_add(struct userrec *u, int login, int op)
 {
-  char *s,
-    s2[50];
-  int sl,
-    so;
+  char *s = NULL, s2[50] = "";
+  int sl, so;
 
   if (!u)
     return;
@@ -492,7 +480,8 @@ struct user_entry_type USERENTRY_STATS = {
 
 void update_mod(char *handle, char *nick, char *cmd, char *par)
 {
-  char tmp[100];
+  char tmp[100] = "";
+
   egg_snprintf(tmp, sizeof tmp, "%lu, %s (%s %s)", now, nick, cmd, (par && par[0]) ? par : "");
   set_user(&USERENTRY_MODIFIED, get_user_by_handle(userlist, handle), tmp);
 }
@@ -500,10 +489,9 @@ void update_mod(char *handle, char *nick, char *cmd, char *par)
 void modified_display(int idx, struct user_entry *e, struct userrec *u)
 {
   if (e && dcc[idx].user && (dcc[idx].user->flags & USER_MASTER)) {
-    char tmp[1024],
-      tmp2[1024],
-     *hnd;
+    char tmp[1024] = "", tmp2[1024] = "", *hnd = NULL;
     time_t tm;
+
     strncpyz(tmp, e->u.string, sizeof(tmp));
     hnd = strchr(tmp, ' ');
     if (hnd)
@@ -538,7 +526,7 @@ struct user_entry_type USERENTRY_MODIFIED =
 
 int pass_set(struct userrec *u, struct user_entry *e, void *buf)
 {
-  char new[32];
+  char new[32] = "";
   register char *pass = buf;
 
   if (e->u.extra)
@@ -618,14 +606,14 @@ struct user_entry_type USERENTRY_SECPASS =
 
 static int laston_unpack(struct userrec *u, struct user_entry *e)
 {
-  char *par, *arg;
-  struct laston_info *li;
+  char *par = NULL, *arg = NULL;
+  struct laston_info *li = NULL;
 
   par = e->u.list->extra;
   arg = newsplit (&par);
   if (!par[0])
     par = "???";
-  li = malloc(sizeof(struct laston_info));
+  li = calloc(1, sizeof(struct laston_info));
   li->laston = atoi(arg);
   li->lastonplace = strdup(par);
   list_type_kill(e->u.list);
@@ -635,15 +623,15 @@ static int laston_unpack(struct userrec *u, struct user_entry *e)
 
 static int laston_pack(struct userrec *u, struct user_entry *e)
 {
-  char work[1024];
-  struct laston_info *li;
+  char work[1024] = "";
+  struct laston_info *li = NULL;
   int l;
 
   li = (struct laston_info *) e->u.extra;
   l = sprintf(work, "%lu %s", li->laston, li->lastonplace);
-  e->u.list = malloc(sizeof(struct list_type));
+  e->u.list = calloc(1, sizeof(struct list_type));
   e->u.list->next = NULL;
-  e->u.list->extra = malloc(l + 1);
+  e->u.list->extra = calloc(1, l + 1);
   strcpy(e->u.list->extra, work);
   
   free(li->lastonplace);
@@ -651,9 +639,7 @@ static int laston_pack(struct userrec *u, struct user_entry *e)
   return 1;
 }
 
-static int laston_write_userfile(FILE * f,
-				 struct userrec *u,
-				 struct user_entry *e)
+static int laston_write_userfile(FILE * f, struct userrec *u, struct user_entry *e)
 {
   struct laston_info *li = (struct laston_info *) e->u.extra;
 
@@ -688,13 +674,12 @@ static int laston_set(struct userrec *u, struct user_entry *e, void *buf)
   return 1;
 }
 
-static int laston_dupuser(struct userrec *new, struct userrec *old,
-			  struct user_entry *e)
+static int laston_dupuser(struct userrec *new, struct userrec *old, struct user_entry *e)
 {
-  struct laston_info *li = e->u.extra, *li2;
+  struct laston_info *li = e->u.extra, *li2 = NULL;
 
   if (li) {
-    li2 = malloc(sizeof(struct laston_info));
+    li2 = calloc(1, sizeof(struct laston_info));
 
     li2->laston = li->laston;
     li2->lastonplace = strdup(li->lastonplace);
@@ -757,8 +742,7 @@ static int botaddr_unpack(struct userrec *u, struct user_entry *e)
   if (!bi->relay_port)
     bi->relay_port = bi->telnet_port;
   if (!bi->uplink) {
-    bi->uplink = malloc(1);
-    bi->uplink[0] = 0;
+    bi->uplink = calloc(1, 1);
   }
   list_type_kill(e->u.list);
   e->u.extra = bi;
@@ -768,17 +752,17 @@ static int botaddr_unpack(struct userrec *u, struct user_entry *e)
 static int botaddr_pack(struct userrec *u, struct user_entry *e)
 {
   char work[1024] = "";
-  struct bot_addr *bi;
+  struct bot_addr *bi = NULL;
   int l;
 
   Assert(e);
   Assert(!e->name);
   bi = (struct bot_addr *) e->u.extra;
   l = simple_sprintf(work, STR("%s:%u/%u:%u:%s"), bi->address, bi->telnet_port, bi->relay_port, bi->hublevel, bi->uplink);
-  e->u.list = malloc(sizeof(struct list_type));
+  e->u.list = calloc(1, sizeof(struct list_type));
 
   e->u.list->next = NULL;
-  e->u.list->extra = malloc(l + 1);
+  e->u.list->extra = calloc(1, l + 1);
   strcpy(e->u.list->extra, work);
   free(bi->address);
   free(bi->uplink);
@@ -795,12 +779,10 @@ static int botaddr_kill(struct user_entry *e)
   return 1;
 }
 
-static int botaddr_write_userfile(FILE *f, struct userrec *u,
-				  struct user_entry *e)
+static int botaddr_write_userfile(FILE *f, struct userrec *u, struct user_entry *e)
 {
   register struct bot_addr *bi = (struct bot_addr *) e->u.extra;
 
-
   if (lfprintf(f,  "--%s %s:%u/%u:%u:%s\n", e->type->name, bi->address,
 	      bi->telnet_port, bi->relay_port, bi->hublevel, bi->uplink) == EOF)
     return 0;
@@ -850,11 +832,10 @@ static void botaddr_display(int idx, struct user_entry *e, struct userrec *u)
 #endif /* HUB */
 }
 
-static int botaddr_gotshare(struct userrec *u, struct user_entry *e,
-			    char *buf, int idx)
+static int botaddr_gotshare(struct userrec *u, struct user_entry *e, char *buf, int idx)
 {
   struct bot_addr *bi = calloc(1, sizeof(struct bot_addr));
-  char *arg;
+  char *arg = NULL;
 
   arg = newsplit(&buf);
   bi->address = strdup(arg);
@@ -872,12 +853,10 @@ static int botaddr_gotshare(struct userrec *u, struct user_entry *e,
   return botaddr_set(u, e, bi);
 }
 
-static int botaddr_dupuser(struct userrec *new, struct userrec *old,
-			   struct user_entry *e)
+static int botaddr_dupuser(struct userrec *new, struct userrec *old, struct user_entry *e)
 {
   if (old->flags & USER_BOT) {
-    struct bot_addr *bi = e->u.extra,
-     *bi2;
+    struct bot_addr *bi = e->u.extra, *bi2 = NULL;
 
     if (bi) {
       bi2 = calloc(1, sizeof(struct bot_addr));
@@ -908,10 +887,9 @@ struct user_entry_type USERENTRY_BOTADDR =
   "BOTADDR"
 };
 
-static int hosts_dupuser(struct userrec *new, struct userrec *old,
-			 struct user_entry *e)
+static int hosts_dupuser(struct userrec *new, struct userrec *old, struct user_entry *e)
 {
-  struct list_type *h;
+  struct list_type *h = NULL;
 
   for (h = e->u.extra; h; h = h->next)
     set_user(&USERENTRY_HOSTS, new, h->extra);
@@ -925,7 +903,7 @@ static int hosts_null(struct userrec *u, struct user_entry *e)
 
 static int hosts_write_userfile(FILE *f, struct userrec *u, struct user_entry *e)
 {
-  struct list_type *h;
+  struct list_type *h = NULL;
 
   for (h = e->u.extra; h; h = h->next)
     if (lfprintf(f, "--HOSTS %s\n", h->extra) == EOF)
@@ -947,10 +925,9 @@ static void hosts_display(int idx, struct user_entry *e, struct userrec *u)
    * otherwise, let users see their own hosts */
   if (!strcmp(u->handle,dcc[idx].nick) && !dcc[idx].u.chat->su_nick) { 
 #endif /* LEAF */
-    char s[1024];
-    struct list_type *q;
+    char s[1024] = "";
+    struct list_type *q = NULL;
 
-    s[0] = 0;
     strcpy(s, "  HOSTS: ");
     for (q = e->u.list; q; q = q->next) {
       if (s[0] && !s[9])
@@ -1010,7 +987,7 @@ static int hosts_set(struct userrec *u, struct user_entry *e, void *buf)
       } else
 	t = &((*t)->next);
     }
-    *t = malloc(sizeof(struct list_type));
+    *t = calloc(1, sizeof(struct list_type));
 
     (*t)->next = NULL;
     (*t)->extra = strdup(host);
@@ -1018,8 +995,7 @@ static int hosts_set(struct userrec *u, struct user_entry *e, void *buf)
   return 1;
 }
 
-static int hosts_gotshare(struct userrec *u, struct user_entry *e,
-			  char *buf, int idx)
+static int hosts_gotshare(struct userrec *u, struct user_entry *e, char *buf, int idx)
 {
   /* doh, try to be too clever and it bites your butt */
   return 0;
@@ -1068,7 +1044,7 @@ int list_contains(struct list_type *h, struct list_type *i)
 
 int add_entry_type(struct user_entry_type *type)
 {
-  struct userrec *u;
+  struct userrec *u = NULL;
 
   list_insert(&entry_type_list, type);
   for (u = userlist; u; u = u->next) {
@@ -1086,7 +1062,7 @@ int add_entry_type(struct user_entry_type *type)
 
 int del_entry_type(struct user_entry_type *type)
 {
-  struct userrec *u;
+  struct userrec *u = NULL;
 
   for (u = userlist; u; u = u->next) {
     struct user_entry *e = find_user_entry(type, u);
@@ -1097,13 +1073,12 @@ int del_entry_type(struct user_entry_type *type)
       e->type = NULL;
     }
   }
-  return list_delete((struct list_type **) &entry_type_list,
-		     (struct list_type *) type);
+  return list_delete((struct list_type **) &entry_type_list, (struct list_type *) type);
 }
 
 struct user_entry_type *find_entry_type(char *name)
 {
-  struct user_entry_type *p;
+  struct user_entry_type *p = NULL;
 
   for (p = entry_type_list; p; p = p->next) {
     if (!egg_strcasecmp(name, p->name))
@@ -1112,10 +1087,9 @@ struct user_entry_type *find_entry_type(char *name)
   return NULL;
 }
 
-struct user_entry *find_user_entry(struct user_entry_type *et,
-				   struct userrec *u)
+struct user_entry *find_user_entry(struct user_entry_type *et, struct userrec *u)
 {
-  struct user_entry **e, *t;
+  struct user_entry **e = NULL, *t = NULL;
 
   for (e = &(u->entries); *e; e = &((*e)->next)) {
     if (((*e)->type == et) ||
@@ -1132,7 +1106,7 @@ struct user_entry *find_user_entry(struct user_entry_type *et,
 
 void *get_user(struct user_entry_type *et, struct userrec *u)
 {
-  struct user_entry *e;
+  struct user_entry *e = NULL;
 
   if (u && (e = find_user_entry(et, u)))
     return et->get(u, e);
@@ -1141,14 +1115,14 @@ void *get_user(struct user_entry_type *et, struct userrec *u)
 
 int set_user(struct user_entry_type *et, struct userrec *u, void *d)
 {
-  struct user_entry *e;
+  struct user_entry *e = NULL;
   int r;
 
   if (!u || !et)
     return 0;
 
   if (!(e = find_user_entry(et, u))) {
-    e = malloc(sizeof(struct user_entry));
+    e = calloc(1, sizeof(struct user_entry));
 
     e->type = et;
     e->name = NULL;

+ 47 - 53
src/userrec.c

@@ -51,7 +51,7 @@ extern struct cmd_pass *cmdpass;
 int count_users(struct userrec *bu)
 {
   int tot = 0;
-  struct userrec *u;
+  struct userrec *u = NULL;
 
   for (u = bu; u; u = u->next)
     tot++;
@@ -63,8 +63,8 @@ int count_users(struct userrec *bu)
  */
 char *fixfrom(char *s)
 {
-  char *p;
-  static char buf[512];
+  static char buf[512] = "";
+  char *p = NULL;
 
   if (s == NULL)
     return NULL;
@@ -96,7 +96,7 @@ struct userrec *check_dcclist_hand(char *handle)
 
 struct userrec *get_user_by_handle(struct userrec *bu, char *handle)
 {
-  struct userrec *u, *ret;
+  struct userrec *u = NULL, *ret = NULL;
 
   if (!handle)
     return NULL;
@@ -134,7 +134,7 @@ struct userrec *get_user_by_handle(struct userrec *bu, char *handle)
  */
 void correct_handle(char *handle)
 {
-  struct userrec *u;
+  struct userrec *u = NULL;
 
   u = get_user_by_handle(userlist, handle);
   if (u == NULL || handle == u->handle)
@@ -163,7 +163,7 @@ void clear_masks(maskrec *m)
 
 void clear_userlist(struct userrec *bu)
 {
-  struct userrec *u, *v;
+  struct userrec *u = NULL, *v = NULL;
   int i;
 
   for (u = bu; u; u = v) {
@@ -171,7 +171,7 @@ void clear_userlist(struct userrec *bu)
     freeuser(u);
   }
   if (userlist == bu) {
-    struct chanset_t *cst;
+    struct chanset_t *cst = NULL;
 
     for (i = 0; i < dcc_total; i++)
       dcc[i].user = NULL;
@@ -207,10 +207,10 @@ void clear_userlist(struct userrec *bu)
  */
 struct userrec *get_user_by_host(char *host)
 {
-  struct userrec *u, *ret;
-  struct list_type *q;
+  struct userrec *u = NULL, *ret = NULL;
+  struct list_type *q = NULL;
   int cnt, i;
-  char host2[UHOSTLEN];
+  char host2[UHOSTLEN] = "";
 
   if (host == NULL)
     return NULL;
@@ -247,8 +247,8 @@ struct userrec *get_user_by_host(char *host)
  */
 struct userrec *get_user_by_equal_host(char *host)
 {
-  struct userrec *u;
-  struct list_type *q;
+  struct userrec *u = NULL;
+  struct list_type *q = NULL;
 
   for (u = userlist; u; u = u->next)
     for (q = get_user(&USERENTRY_HOSTS, u); q; q = q->next)
@@ -262,7 +262,7 @@ struct userrec *get_user_by_equal_host(char *host)
  */
 int u_pass_match(struct userrec *u, char *in)
 {
-  char *cmp, new[32], pass[16];
+  char *cmp = NULL, new[32] = "", pass[16] = "";
 
   if (!u)
     return 0;
@@ -286,12 +286,13 @@ int u_pass_match(struct userrec *u, char *in)
   }
   return 0;
 }
+
 int write_user(struct userrec *u, FILE * f, int idx)
 {
-  char s[181];
-  struct chanuserrec *ch;
-  struct chanset_t *cst;
-  struct user_entry *ue;
+  char s[181] = "";
+  struct chanuserrec *ch = NULL;
+  struct chanset_t *cst = NULL;
+  struct user_entry *ue = NULL;
   struct flag_record fr = {FR_GLOBAL, 0, 0, 0, 0, 0};
 
   fr.global = u->flags;
@@ -312,15 +313,14 @@ int write_user(struct userrec *u, FILE * f, int idx)
 	fr.chan = ch->flags;
 	fr.udef_chan = ch->flags_udef;
 	build_flags(s, &fr, NULL);
-	if (lfprintf(f, "! %-20s %lu %-10s %s\n", ch->channel, ch->laston, s,
-		    ch->info ? ch->info : "") == EOF)
+	if (lfprintf(f, "! %-20s %lu %-10s %s\n", ch->channel, ch->laston, s, ch->info ? ch->info : "") == EOF)
 	  return 0;
       }
     }
   }
   for (ue = u->entries; ue; ue = ue->next) {
     if (ue->name) {
-      struct list_type *lt;
+      struct list_type *lt = NULL;
 
       for (lt = ue->u.list; lt; lt = lt->next)
 	if (lfprintf(f, "--%s %s\n", ue->name, lt->extra) == EOF)
@@ -332,6 +332,7 @@ int write_user(struct userrec *u, FILE * f, int idx)
   }
   return 1;
 }
+
 int sort_compare(struct userrec *a, struct userrec *b)
 {
   /* Order by flags, then alphabetically
@@ -373,11 +374,9 @@ int sort_compare(struct userrec *a, struct userrec *b)
 
 void sort_userlist()
 {
-  int again;
-  struct userrec *last, *p, *c, *n;
+  int again = 1;
+  struct userrec *last = NULL, *p = NULL, *c = NULL, *n = NULL;
 
-  again = 1;
-  last = NULL;
   while ((userlist != last) && (again)) {
     p = NULL;
     c = userlist;
@@ -406,17 +405,16 @@ void sort_userlist()
  */
 int write_userfile(int idx)
 {
-  FILE *f;
-  char *new_userfile;
-  char s1[81], backup[DIRMAX];
+  FILE *f = NULL;
+  char *new_userfile = NULL, s1[81] = "", backup[DIRMAX] = "";
   time_t tt;
-  struct userrec *u;
+  struct userrec *u = NULL;
   int ok;
 
   if (userlist == NULL)
     return 1;			/* No point in saving userfile */
 
-  new_userfile = malloc(strlen(userfile) + 5);
+  new_userfile = calloc(1, strlen(userfile) + 5);
   sprintf(new_userfile, "%s~new", userfile);
 
   f = fopen(new_userfile, "w");
@@ -454,10 +452,11 @@ int write_userfile(int idx)
   free(new_userfile);
   return 0;
 }
+
 int change_handle(struct userrec *u, char *newh)
 {
   int i;
-  char s[HANDLEN + 1];
+  char s[HANDLEN + 1] = "";
 
   if (!u)
     return 0;
@@ -484,14 +483,13 @@ int change_handle(struct userrec *u, char *newh)
 }
 
 
-struct userrec *adduser(struct userrec *bu, char *handle, char *host,
-			char *pass, int flags)
+struct userrec *adduser(struct userrec *bu, char *handle, char *host, char *pass, int flags)
 {
-  struct userrec *u, *x;
+  struct userrec *u = NULL, *x = NULL;
   int oldshare = noshare;
 
   noshare = 1;
-  u = (struct userrec *) malloc(sizeof(struct userrec));
+  u = (struct userrec *) calloc(1, sizeof(struct userrec));
 
   /* u->next=bu; bu=u; */
   strncpyz(u->handle, handle, sizeof u->handle);
@@ -508,7 +506,7 @@ struct userrec *adduser(struct userrec *bu, char *handle, char *host,
   set_user(&USERENTRY_PASS, u, pass);
   /* Strip out commas -- they're illegal */
   if (host && host[0]) {
-    char *p;
+    char *p = NULL;
 
     /* About this fixfrom():
      *   We should use this fixfrom before every call of adduser()
@@ -528,16 +526,14 @@ struct userrec *adduser(struct userrec *bu, char *handle, char *host,
   if (bu == userlist)
     clear_chanlist();
   noshare = oldshare;
-  if ((!noshare) && (handle[0] != '*') && (!(flags & USER_UNSHARED)) &&
-      (bu == userlist)) {
+  if ((!noshare) && (handle[0] != '*') && (!(flags & USER_UNSHARED)) && (bu == userlist)) {
     struct flag_record fr = {FR_GLOBAL, 0, 0, 0, 0, 0};
-    char x[100];
+    char x[100] = "";
 
     fr.global = u->flags;
     fr.udef_global = u->flags_udef;
     build_flags(x, &fr, 0);
-    shareout(NULL, "n %s %s %s %s\n", handle, host && host[0] ? host : "none",
-             pass, x);
+    shareout(NULL, "n %s %s %s %s\n", handle, host && host[0] ? host : "none", pass, x);
   }
   if (bu == NULL)
     bu = u;
@@ -557,8 +553,8 @@ struct userrec *adduser(struct userrec *bu, char *handle, char *host,
 
 void freeuser(struct userrec *u)
 {
-  struct user_entry *ue, *ut;
-  struct chanuserrec *ch, *z;
+  struct user_entry *ue = NULL, *ut = NULL;
+  struct chanuserrec *ch = NULL, *z = NULL;
 
   if (u == NULL)
     return;
@@ -623,8 +619,8 @@ int deluser(char *handle)
 
 int delhost_by_handle(char *handle, char *host)
 {
-  struct userrec *u;
-  struct list_type *q, *qnext, *qprev;
+  struct userrec *u = NULL;
+  struct list_type *q = NULL, *qnext = NULL, *qprev = NULL;
   struct user_entry *e = NULL;
   int i = 0;
 
@@ -689,11 +685,10 @@ void touch_laston(struct userrec *u, char *where, time_t timeval)
   if (!u)
     return;
   if (timeval > 1) {
-    struct laston_info *li =
-    (struct laston_info *) get_user(&USERENTRY_LASTON, u);
+    struct laston_info *li = (struct laston_info *) get_user(&USERENTRY_LASTON, u);
 
     if (!li)
-      li = malloc(sizeof(struct laston_info));
+      li = calloc(1, sizeof(struct laston_info));
 
     else if (li->lastonplace)
       free(li->lastonplace);
@@ -716,13 +711,13 @@ void touch_laston(struct userrec *u, char *where, time_t timeval)
  */
 struct userrec *get_user_by_nick(char *nick)
 {
-  struct chanset_t *chan;
-  memberlist *m;
+  struct chanset_t *chan = NULL;
+  memberlist *m = NULL;
 
   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)) {
-  	char word[512];
+  	char word[512] = "";
 
 	egg_snprintf(word, sizeof word, "%s!%s", m->nick, m->userhost);
 	/* No need to check the return value ourself */
@@ -736,8 +731,8 @@ struct userrec *get_user_by_nick(char *nick)
 
 void user_del_chan(char *dname)
 {
-  struct chanuserrec *ch, *och;
-  struct userrec *u;
+  struct chanuserrec *ch = NULL, *och = NULL;
+  struct userrec *u = NULL;
 
   for (u = userlist; u; u = u->next) {
     ch = u->chanrec;
@@ -759,4 +754,3 @@ void user_del_chan(char *dname)
     }
   }
 }
-

+ 64 - 79
src/users.c

@@ -40,7 +40,7 @@ extern struct userrec *userlist, *lastuser;
 extern struct chanset_t *chanset;
 extern int 		dcc_total, noshare;
 extern char 		tempdir[];
-extern time_t now;
+extern time_t 		now, buildts;
 
 char natip[121] = "";
 char userfile[121] = "";	/* where the user records are stored */
@@ -49,7 +49,7 @@ int ignore_time = 10;		/* how many minutes will ignores last? */
 /* is this nick!user@host being ignored? */
 int match_ignore(char *uhost)
 {
-  struct igrec *ir;
+  struct igrec *ir = NULL;
 
   for (ir = global_ign; ir; ir = ir->next)
     if (wild_match(ir->igmask, uhost))
@@ -74,10 +74,8 @@ int equals_ignore(char *uhost)
 int delignore(char *ign)
 {
   int i, j;
-  struct igrec **u;
-  struct igrec *t;
-  char temp[256];
-
+  struct igrec **u = NULL, *t = NULL;
+  char temp[256] = "";
 
   i = 0;
   if (!strchr(ign, '!') && (j = atoi(ign))) {
@@ -118,7 +116,7 @@ int delignore(char *ign)
 
 void addignore(char *ign, char *from, char *mnote, time_t expire_time)
 {
-  struct igrec *p = NULL, *l;
+  struct igrec *p = NULL, *l = NULL;
 
   for (l = global_ign; l; l = l->next)
     if (!rfc_casecmp(l->igmask, ign)) {
@@ -127,7 +125,7 @@ void addignore(char *ign, char *from, char *mnote, time_t expire_time)
     }
 
   if (p == NULL) {
-    p = malloc(sizeof(struct igrec));
+    p = calloc(1, sizeof(struct igrec));
     p->next = global_ign;
     global_ign = p;
   } else {
@@ -156,7 +154,7 @@ void addignore(char *ign, char *from, char *mnote, time_t expire_time)
 /* take host entry from ignore list and display it ignore-style */
 void display_ignore(int idx, int number, struct igrec *ignore)
 {
-  char dates[81], s[41];
+  char dates[81] = "", s[41] = "";
 
   if (ignore->added) {
     daysago(now, ignore->added, s);
@@ -166,7 +164,7 @@ void display_ignore(int idx, int number, struct igrec *ignore)
   if (ignore->flags & IGREC_PERM)
     strcpy(s, STR("(perm)"));
   else {
-    char s1[41];
+    char s1[41] = "";
 
     days(ignore->expire, now, s1);
     sprintf(s, STR("(expires %s)"), s1);
@@ -232,7 +230,7 @@ static void addmask_fully(struct chanset_t *chan, maskrec **m, maskrec **global,
 			 char *note, time_t expire_time, int flags,
 			 time_t added, time_t last)
 {
-  maskrec *p = malloc(sizeof(maskrec));
+  maskrec *p = calloc(1, sizeof(maskrec));
   maskrec **u = (chan) ? m : global;
 
   p->next = *u;
@@ -248,7 +246,7 @@ static void addmask_fully(struct chanset_t *chan, maskrec **m, maskrec **global,
 
 static void restore_chanban(struct chanset_t *chan, char *host)
 {
-  char *expi, *add, *last, *user, *desc;
+  char *expi = NULL, *add = NULL, *last = NULL, *user = NULL, *desc = NULL;
   int flags = 0;
 
   expi = strchr_unescape(host, ':', '\\');
@@ -296,13 +294,12 @@ static void restore_chanban(struct chanset_t *chan, char *host)
       }
     }
   }
-  putlog(LOG_MISC, "*", STR("*** Malformed banline for %s."),
-	 chan ? chan->dname : STR("global_bans"));
+  putlog(LOG_MISC, "*", STR("*** Malformed banline for %s."), chan ? chan->dname : STR("global_bans"));
 }
 
 static void restore_chanexempt(struct chanset_t *chan, char *host)
 {
-  char *expi, *add, *last, *user, *desc;
+  char *expi = NULL, *add = NULL, *last = NULL, *user = NULL, *desc = NULL;
   int flags = 0;
 
   expi = strchr_unescape(host, ':', '\\');
@@ -350,13 +347,12 @@ static void restore_chanexempt(struct chanset_t *chan, char *host)
       }
     }
   }
-  putlog(LOG_MISC, "*", STR("*** Malformed exemptline for %s."),
-	 chan ? chan->dname : STR("global_exempts"));
+  putlog(LOG_MISC, "*", STR("*** Malformed exemptline for %s."), chan ? chan->dname : STR("global_exempts"));
 }
 
 static void restore_chaninvite(struct chanset_t *chan, char *host)
 {
-  char *expi, *add, *last, *user, *desc;
+  char *expi = NULL, *add = NULL, *last = NULL, *user = NULL, *desc = NULL;
   int flags = 0;
 
   expi = strchr_unescape(host, ':', '\\');
@@ -397,22 +393,20 @@ static void restore_chaninvite(struct chanset_t *chan, char *host)
 	if (desc) {
 	  *desc = 0;
 	  desc++;
-	  addmask_fully(chan, &chan->invites, &global_invites, host, add,
-			desc, atoi(expi), flags, now, 0);
+	  addmask_fully(chan, &chan->invites, &global_invites, host, add, desc, atoi(expi), flags, now, 0);
 	  return;
 	}
       }
     }
   }
-  putlog(LOG_MISC, "*", STR("*** Malformed inviteline for %s."),
-	 chan ? chan->dname : STR("global_invites"));
+  putlog(LOG_MISC, "*", STR("*** Malformed inviteline for %s."), chan ? chan->dname : STR("global_invites"));
 }
 
 static void restore_ignore(char *host)
 {
-  char *expi, *user, *added, *desc;
+  char *expi = NULL, *user = NULL, *added = NULL, *desc = NULL;
   int flags = 0;
-  struct igrec *p;
+  struct igrec *p = NULL;
 
   expi = strchr_unescape(host, ':', '\\');
   if (expi) {
@@ -438,7 +432,7 @@ static void restore_ignore(char *host)
 	added = "0";
 	desc = NULL;
       }
-      p = malloc(sizeof(struct igrec));
+      p = calloc(1, sizeof(struct igrec));
 
       p->next = global_ign;
       global_ign = p;
@@ -459,17 +453,17 @@ static void restore_ignore(char *host)
 
 void tell_user(int idx, struct userrec *u, int master)
 {
-  char s[81], s1[81];
-  char format[81];
+  char s[81] = "", s1[81] = "", format[81];
   int n = 0;
   time_t now2;
-  struct chanuserrec *ch;
-  struct chanset_t *chan;
-  struct user_entry *ue;
-  struct laston_info *li;
+  struct chanuserrec *ch = NULL;
+  struct chanset_t *chan = NULL;
+  struct user_entry *ue = NULL;
+  struct laston_info *li = NULL;
   struct flag_record fr = {FR_GLOBAL, 0, 0, 0, 0, 0};
-  module_entry *me = module_find("notes", 0, 0);
-  if (me) {
+  module_entry *me = NULL;
+
+  if ((me = module_find("notes", 0, 0))) {
     Function *func = me->funcs;
     n = (func[5]) (u->handle);
   }
@@ -496,11 +490,8 @@ void tell_user(int idx, struct userrec *u, int master)
       egg_strftime(s1, 6, "%H:%M", localtime(&li->laston));
 #endif /* S_UTCTIME */
   }
-  egg_snprintf(format, sizeof format, "%%-%us %%-5s%%5d %%-15s %%s (%%-10.10s)", 
-                          HANDLEN);
-  dprintf(idx, format, u->handle, 
-	  get_user(&USERENTRY_PASS, u) ? "yes" : "no", n, s, s1,
-	  (li && li->lastonplace) ? li->lastonplace : "nowhere");
+  egg_snprintf(format, sizeof format, "%%-%us %%-5s%%5d %%-15s %%s (%%-10.10s)", HANDLEN);
+  dprintf(idx, format, u->handle, get_user(&USERENTRY_PASS, u) ? "yes" : "no", n, s, s1, (li && li->lastonplace) ? li->lastonplace : "nowhere");
   dprintf(idx, "\n");
   /* channel flags? */
   for (ch = u->chanrec; ch; ch = ch->next) {
@@ -546,8 +537,8 @@ void tell_user(int idx, struct userrec *u, int master)
 /* show user by ident */
 void tell_user_ident(int idx, char *id, int master)
 {
-  char format[81];
-  struct userrec *u;
+  char format[81] = "";
+  struct userrec *u = NULL;
   struct flag_record user = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
 
   get_user_flagrec(dcc[idx].user, &user, NULL);
@@ -569,19 +560,17 @@ void tell_user_ident(int idx, char *id, int master)
 /* match string:
  * wildcard to match nickname or hostmasks
  * +attr to find all with attr */
-void tell_users_match(int idx, char *mtch, int start, int limit,
-		      int master, char *chname)
+void tell_users_match(int idx, char *mtch, int start, int limit, int master, char *chname)
 {
-  char format[81];
-  struct userrec *u;
+  char format[81] = "";
+  struct userrec *u = NULL;
   int fnd = 0, cnt, nomns = 0, flags = 0;
-  struct list_type *q;
+  struct list_type *q = NULL;
   struct flag_record user, pls, mns;
 
   dprintf(idx, STR("*** %s '%s':\n"), MISC_MATCHING, mtch);
   cnt = 0;
-  egg_snprintf(format, sizeof format, STR("%%-%us PASS NOTES FLAGS           LAST\n"), 
-                      HANDLEN);
+  egg_snprintf(format, sizeof format, STR("%%-%us PASS NOTES FLAGS           LAST\n"), HANDLEN);
   dprintf(idx, format, STR("HANDLE"));
   if (start > 1)
     dprintf(idx, STR("(%s %d)\n"), MISC_SKIPPING, start - 1);
@@ -644,7 +633,7 @@ void tell_users_match(int idx, char *mtch, int start, int limit,
 #ifdef HUB
 void backup_userfile()
 {
-  char s[DIRMAX], s2[DIRMAX];
+  char s[DIRMAX] = "", s2[DIRMAX] = "";
 
   putlog(LOG_MISC, "*", USERF_BACKUP);
   egg_snprintf(s, sizeof s, "%s.u.0", tempdir);
@@ -654,7 +643,6 @@ void backup_userfile()
 }
 #endif /* HUB */
 
-
 /*
  * tagged lines in the user file:
  * * OLD:
@@ -690,14 +678,14 @@ void backup_userfile()
 
 int readuserfile(char *file, struct userrec **ret)
 {
-  char *p, buf[1024], lasthand[512], *attr, *pass, *code, s1[1024], *s, cbuf[1024], *temps;
-  FILE *f;
-  struct userrec *bu, *u = NULL;
+  char *p = NULL, buf[1024] = "", lasthand[512] = "", *attr = NULL, *pass = NULL;
+  char *code = NULL, s1[1024] = "", *s = NULL, cbuf[1024] = "", *temps = NULL, ignored[512] = "";
+  FILE *f = NULL;
+  struct userrec *bu = NULL, *u = NULL;
   struct chanset_t *cst = NULL;
-  int i, line = 0;
-  char ignored[512];
   struct flag_record fr;
-  struct chanuserrec *cr;
+  struct chanuserrec *cr = NULL;
+  int i, line = 0;
 
   bu = (*ret);
   ignored[0] = 0;
@@ -792,7 +780,7 @@ int readuserfile(char *file, struct userrec **ret)
 	  }
 	} else if (!strcmp(code, "!")) {
 	  /* ! #chan laston flags [info] */
-	  char *chname, *st, *fl;
+	  char *chname = NULL, *st = NULL, *fl = NULL;
 
 	  if (u) {
 	    chname = newsplit(&s);
@@ -806,8 +794,7 @@ int readuserfile(char *file, struct userrec **ret)
 		if (!rfc_casecmp(cr->channel, chname))
 		  break;
 	      if (!cr) {
-		cr = (struct chanuserrec *)
-		  malloc(sizeof(struct chanuserrec));
+		cr = (struct chanuserrec *) calloc(1, sizeof(struct chanuserrec));
 
 		cr->next = u->chanrec;
 		u->chanrec = cr;
@@ -824,11 +811,13 @@ int readuserfile(char *file, struct userrec **ret)
 	  }
         } else if (!strcmp(code, "+")) {
          if (s[0] && lasthand[0] == '*' && lasthand[1] == CHANS_NAME[1]) {
-           module_entry *me = module_find("channels", 0, 0);
-           if (me) {
+           module_entry *me = NULL;
+
+           if ((me = module_find("channels", 0, 0))) {
              Function *func = me->funcs;
-             char *options = strdup(s), *chan = NULL, *my_ptr = NULL;
-             my_ptr = options;
+             char *options = NULL, *chan = NULL, *my_ptr = NULL;
+
+             options = my_ptr = strdup(s);
 
              newsplit(&options);
              newsplit(&options);
@@ -926,14 +915,14 @@ int readuserfile(char *file, struct userrec **ret)
 	} else if (!strncmp(code, "--", 2)) {
 	  if (u) {
 	    /* new format storage */
-	    struct user_entry *ue;
+	    struct user_entry *ue = NULL;
 	    int ok = 0;
 
 	    for (ue = u->entries; ue && !ok; ue = ue->next)
 	      if (ue->name && !egg_strcasecmp(code + 2, ue->name)) {
 		struct list_type *list;
 
-		list = malloc(sizeof(struct list_type));
+		list = calloc(1, sizeof(struct list_type));
 
 		list->next = NULL;
                 list->extra = strdup(s);
@@ -941,12 +930,12 @@ int readuserfile(char *file, struct userrec **ret)
 		ok = 1;
 	      }
 	    if (!ok) {
-	      ue = malloc(sizeof(struct user_entry));
+	      ue = calloc(1, sizeof(struct user_entry));
 
-	      ue->name = malloc(strlen(code + 1));
+	      ue->name = calloc(1, strlen(code + 1));
 	      ue->type = NULL;
 	      strcpy(ue->name, code + 2);
-	      ue->u.list = malloc(sizeof(struct list_type));
+	      ue->u.list = calloc(1, sizeof(struct list_type));
 
 	      ue->u.list->next = NULL;
               ue->u.list->extra = strdup(s);
@@ -1027,7 +1016,7 @@ int readuserfile(char *file, struct userrec **ret)
   }
   putlog(LOG_MISC, "*", "Userfile loaded, unpacking...");
   for (u = bu; u; u = u->next) {
-    struct user_entry *e;
+    struct user_entry *e = NULL;
 
     if (!(u->flags & USER_BOT) && !egg_strcasecmp (u->handle, conf.bot->nick)) {
       putlog(LOG_MISC, "*", "(!) I have a user record, but without +b");
@@ -1063,7 +1052,7 @@ void link_pref_val(struct userrec *u, char *val)
 {
 
 /* val must be HANDLEN + 4 chars minimum */
-  struct bot_addr *ba;
+  struct bot_addr *ba = NULL;
 
   val[0] = 'Z';
   val[1] = 0;
@@ -1079,8 +1068,6 @@ void link_pref_val(struct userrec *u, char *val)
   sprintf(val, STR("%02d%s"), ba->hublevel, u->handle);
 
 }
-struct userrec *next_hub(struct userrec *current, char *lowval, char *highval)
-{
 
 /*
   starting at "current" or "userlist" if NULL, find next bot with a
@@ -1088,12 +1075,10 @@ struct userrec *next_hub(struct userrec *current, char *lowval, char *highval)
   If none found return bot with best overall link_pref_val
   If still not found return NULL
 */
-  char thisval[NICKLEN + 4],
-    bestmatchval[NICKLEN + 4] = "z",
-    bestallval[NICKLEN + 4] = "z";
-  struct userrec *cur = NULL,
-   *bestmatch = NULL,
-   *bestall = NULL;
+struct userrec *next_hub(struct userrec *current, char *lowval, char *highval)
+{
+  char thisval[NICKLEN + 4] = "", bestmatchval[NICKLEN + 4] = "z", bestallval[NICKLEN + 4] = "z";
+  struct userrec *cur = NULL, *bestmatch = NULL, *bestall = NULL;
 
   if (current)
     cur = current->next;
@@ -1128,9 +1113,9 @@ struct userrec *next_hub(struct userrec *current, char *lowval, char *highval)
 #ifdef HUB
 void autolink_cycle(char *start)
 {
+  char bestval[HANDLEN + 4] = "", curval[HANDLEN + 4] = "", myval[HANDLEN + 4] = "";
   struct userrec *u = NULL;
   int i;
-  char bestval[HANDLEN + 4] = "", curval[HANDLEN + 4] = "", myval[HANDLEN + 4] = "";
 
   link_pref_val(conf.bot->u, myval);
   strcpy(bestval, myval);
@@ -1210,7 +1195,7 @@ void autolink_cycle(char *start)
 {
   struct userrec *u = NULL;
   struct hublist_entry *hl = NULL, *hl2 = NULL;
-  struct bot_addr *my_ba;
+  struct bot_addr *my_ba = NULL;
   char uplink[HANDLEN + 1] = "", avoidbot[HANDLEN + 1] = "", curhub[HANDLEN + 1] = "";
   int i, hlc;
   struct flag_record fr = {FR_GLOBAL, 0, 0, 0, 0, 0};

Некоторые файлы не были показаны из-за большого количества измененных файлов