ソースを参照

* Added attributes: format, noreturn
* Fixed various bugs found with format attribute


svn: 981

Bryan Drewery 22 年 前
コミット
76c954f09e

+ 1 - 0
doc/UPDATES

@@ -27,6 +27,7 @@ This is a summary of ChangeLog basically.
 22.Added channel flag +autoop (+o users only, +private accounted for). (+y bots op)
 23.Added user flag for autoop (+O). (+y bots op)
 24.Fixed a problem with my chmod() function.
+25.Fixed many various somewhat random bugs.
 
 1.1.5
 

+ 7 - 7
src/botnet.c

@@ -1051,7 +1051,7 @@ static void failed_tandem_relay(int idx)
 	(dcc[i].u.relay->sock == dcc[idx].sock))
       uidx = i;
   if (uidx < 0) {
-    putlog(LOG_MISC, "*", "%s  %d -> %d", BOT_CANTFINDRELAYUSER,
+    putlog(LOG_MISC, "*", "%s  %li -> %li", BOT_CANTFINDRELAYUSER,
 	   dcc[idx].sock, dcc[idx].u.relay->sock);
     killsock(dcc[idx].sock);
     lostdcc(idx);
@@ -1181,7 +1181,7 @@ static void tandem_relay_resolve_failure(int idx)
       break;
     }
   if (uidx < 0) {
-    putlog(LOG_MISC, "*", "%s  %d -> %d", BOT_CANTFINDRELAYUSER,
+    putlog(LOG_MISC, "*", "%s  %li -> %li", BOT_CANTFINDRELAYUSER,
 	   dcc[idx].sock, dcc[idx].u.relay->sock);
     killsock(dcc[idx].sock);
     lostdcc(idx);
@@ -1246,7 +1246,7 @@ static void pre_relay(int idx, char *buf, register int i)
       }
   }
   if (tidx < 0) {
-    putlog(LOG_MISC, "*", "%s  %d -> %d", BOT_CANTFINDRELAYUSER,
+    putlog(LOG_MISC, "*", "%s  %li -> %li", BOT_CANTFINDRELAYUSER,
 	   dcc[idx].sock, dcc[idx].u.relay->sock);
     killsock(dcc[idx].sock);
     lostdcc(idx);
@@ -1292,7 +1292,7 @@ static void failed_pre_relay(int idx)
       }
   }
   if (tidx < 0) {
-    putlog(LOG_MISC, "*", "%s  %d -> %d", BOT_CANTFINDRELAYUSER,
+    putlog(LOG_MISC, "*", "%s  %li -> %li", BOT_CANTFINDRELAYUSER,
 	   dcc[idx].sock, dcc[idx].u.relay->sock);
     killsock(dcc[idx].sock);
     lostdcc(idx);
@@ -1327,7 +1327,7 @@ static void cont_tandem_relay(int idx, char *buf, register int i)
 	(dcc[i].u.relay->sock == dcc[idx].sock))
       uidx = i;
   if (uidx < 0) {
-    putlog(LOG_MISC, "*", "%s  %d -> %d", BOT_CANTFINDRELAYUSER,
+    putlog(LOG_MISC, "*", "%s  %li -> %li", BOT_CANTFINDRELAYUSER,
 	   dcc[i].sock, dcc[i].u.relay->sock);
     killsock(dcc[i].sock);
     lostdcc(i);
@@ -1491,12 +1491,12 @@ static void dcc_relaying(int idx, char *buf, int j)
 
 static void display_relay(int i, char *other)
 {
-  sprintf(other, "rela  -> sock %d", dcc[i].u.relay->sock);
+  sprintf(other, "rela  -> sock %li", dcc[i].u.relay->sock);
 }
 
 static void display_relaying(int i, char *other)
 {
-  sprintf(other, ">rly  -> sock %d", dcc[i].u.relay->sock);
+  sprintf(other, ">rly  -> sock %li", dcc[i].u.relay->sock);
 }
 
 static void display_tandem_relay(int i, char *other)

+ 4 - 2
src/cmds.c

@@ -503,7 +503,7 @@ static void cmd_lagged(struct userrec *u, int idx, char *par)
   putlog(LOG_CMDS, "*", "#%s# lagged %s", u->handle, par);
   for (i = 0; i < dcc_total; i++) {
     if (dcc[i].type == &DCC_BOT) {
-      dprintf(idx, "%9s - %i seconds\n", dcc[i].nick, (dcc[i].pingtime > 120) ? (now - dcc[i].pingtime) : dcc[i].pingtime);
+      dprintf(idx, "%9s - %li seconds\n", dcc[i].nick, (dcc[i].pingtime > 120) ? (now - dcc[i].pingtime) : dcc[i].pingtime);
     }
   }
 }
@@ -1975,6 +1975,8 @@ static void cmd_decrypt(struct userrec *u, int idx, char *par)
   free(buf);
 }
 
+static void cmd_restart(struct userrec *, int, char *) __attribute__((noreturn));
+
 static void cmd_restart(struct userrec *u, int idx, char *par)
 {
   putlog(LOG_CMDS, "*", "#%s# restart", dcc[idx].nick);
@@ -3748,7 +3750,7 @@ void rcmd_pong(char *frombot, char *fromhand, char *fromidx, char *par) {
 
     timer_get_now(&tv);
     tm = ((tv.sec % 10000) * 100 + (tv.usec * 100) / (1000000)) - atoi(par);
-    dprintf(i, "Pong from %s: %i.%i seconds\n", frombot, (tm / 100), (tm % 100));
+    dprintf(i, "Pong from %s: %li.%li seconds\n", frombot, (tm / 100), (tm % 100));
   }
 }
 

+ 2 - 2
src/compat/snprintf.h

@@ -25,7 +25,7 @@
  * use our own.
  */
 #ifndef HAVE_VSNPRINTF
-int egg_vsnprintf(char *str, size_t count, const char *fmt, va_list ap);
+int egg_vsnprintf(char *str, size_t count, const char *fmt, va_list ap) __attribute__((format(printf, 3, 0)));
 #else
 #  define egg_vsnprintf	vsnprintf
 #endif
@@ -35,7 +35,7 @@ int egg_vsnprintf(char *str, size_t count, const char *fmt, va_list ap);
  */
 #ifndef HAVE_SNPRINTF
 #  ifdef __STDC__
-int egg_snprintf(char *str, size_t count, const char *fmt, ...);
+int egg_snprintf(char *str, size_t count, const char *fmt, ...) __attribute__((format(printf, 3, 4)));
 #  else
 int egg_snprintf();
 #  endif

+ 1 - 1
src/conf.h

@@ -53,7 +53,7 @@ void spawnbots();
 int killbot(char *);
 #endif /* LEAF */
 #ifdef S_CONFEDIT
-void confedit(char *);
+void confedit(char *) __attribute__((noreturn));
 #endif /* S_CONFEDIT */
 pid_t checkpid(char *, conf_bot *);
 void init_conf();

+ 2 - 2
src/dcc.c

@@ -436,7 +436,7 @@ static void dcc_bot_new(int idx, char *buf, int x)
 
 static void eof_dcc_bot_new(int idx)
 {
-  putlog(LOG_BOTS, "*", DCC_LOSTBOT, dcc[idx].nick, dcc[idx].port);
+  putlog(LOG_BOTS, "*", DCC_LOSTBOT, dcc[idx].nick);
   killsock(dcc[idx].sock);
   lostdcc(idx);
 }
@@ -1631,7 +1631,7 @@ static void dcc_telnet_pass(int idx, int atr)
       putlog(LOG_BOTS, "*", "Sending encrypted link handshake to %s...", dcc[idx].nick);
       socklist[snum].encstatus = 1;
       socklist[snum].gz = 1;
-      dprintf(idx, "elink %s %lu\n", tmp2, socklist[snum].oseed);
+      dprintf(idx, "elink %s %d\n", tmp2, socklist[snum].oseed);
       free(tmp2);
       strcpy(socklist[snum].okey, initkey);
       strcpy(socklist[snum].ikey, initkey);

+ 1 - 1
src/dcc.h

@@ -113,7 +113,7 @@ struct bot_info {
 
 struct relay_info {
   struct chat_info *chat;
-  int sock;
+  long sock;
   int old_status;
   port_t port;
 };

+ 5 - 10
src/dccutil.c

@@ -70,15 +70,13 @@ char *add_cr(char *buf)
   return WBUF;
 }
 
-void dprintf(int idx, ...)
+void dprintf(int idx, char *format, ...)
 {
   static char buf[1024] = "";
-  char *format = NULL;
   int len;
   va_list va;
 
-  va_start(va, idx);
-  format = va_arg(va, char *);
+  va_start(va, format);
   egg_vsnprintf(buf, 1023, format, va);
   va_end(va);
 
@@ -201,16 +199,13 @@ void chatout(char *format, ...)
 
 /* Print to all on this channel but one.
  */
-void chanout_but(int x, ...)
+void chanout_but(int x, int chan, char *format, ...)
 {
-  int i, chan, len;
-  char *format = NULL;
+  int i, len;
   char s[601] = "";
   va_list va;
 
-  va_start(va, x);
-  chan = va_arg(va, int);
-  format = va_arg(va, char *);
+  va_start(va, format);
   egg_vsnprintf(s, 511, format, va);
   va_end(va);
   len = strlen(s);

+ 3 - 3
src/dccutil.h

@@ -26,9 +26,9 @@ struct portmap {
 #define DP_HELP_NEXT    0x7FF9
 
 
-void dprintf (int, ...);
-void chatout (char *, ...);
-void chanout_but (int, ...);
+void dprintf(int, char *, ...) __attribute__((format(printf, 2, 3)));
+void chatout(char *, ...) __attribute__((format(printf, 1, 2)));
+void chanout_but(int, int, char *, ...) __attribute__((format(printf, 3, 4)));
 void dcc_chatter(int);
 void lostdcc(int);
 __inline__ void makepass(char *);

+ 2 - 0
src/debug.c

@@ -276,6 +276,8 @@ static void got_cont(int z)
 
 /* A call to resolver (gethostbyname, etc) timed out
  */
+static void got_alarm(int) __attribute__((noreturn));
+
 static void got_alarm(int z)
 {
   longjmp(alarmret, 1);

+ 1 - 1
src/debug.h

@@ -56,7 +56,7 @@
 extern int		sdebug;
 
 void setlimits();
-void sdprintf (char *, ...);
+void sdprintf (char *, ...) __attribute__((format(printf, 1, 2)));
 void init_signals();
 void init_debug();
 void eggContext(const char *, int, const char *);

+ 1 - 1
src/log.c

@@ -114,7 +114,7 @@ char *maskname(int x)
  *    Logging functions
  */
 
-__inline__ void logidx(int idx, char *format, ...)
+void logidx(int idx, char *format, ...)
 {
   char va_out[LOGLINEMAX + 1];
   va_list va;

+ 2 - 2
src/log.h

@@ -28,8 +28,8 @@
 #define LOG_BOTSHARE BIT22   /* h   share traffic                    */
 #define LOG_ALL      0xfffffff   /* (dump to all logfiles)               */
 
-__inline__ void logidx(int, char *, ...);
-void putlog (int, char *, char *, ...);
+void logidx(int, char *, ...) __attribute__((format(printf, 2, 3)));
+void putlog (int, char *, char *, ...) __attribute((format(printf, 3, 4)));
 int logmodes(char *);
 char *masktype(int);
 char *maskname(int);

+ 7 - 3
src/main.c

@@ -203,6 +203,8 @@ static void checkpass()
   }
 }
 
+static void got_ed(char *, char *, char*) __attribute__((noreturn));
+
 static void got_ed(char *which, char *in, char *out)
 {
   sdprintf("got_Ed called: -%s i: %s o: %s", which, in, out);
@@ -220,6 +222,8 @@ static void got_ed(char *which, char *in, char *out)
   exit(0);
 }
 
+static void show_help() __attribute__((noreturn));
+
 static void show_help()
 {
   char format[81] = "";
@@ -924,7 +928,7 @@ int main(int argc, char **argv)
 	    dcc[idx].type->activity(idx, buf, i);
 	  } else
 	    putlog(LOG_MISC, "*",
-		   "!!! untrapped dcc activity: type %s, sock %d",
+		   "!!! untrapped dcc activity: type %s, sock %li",
 		   dcc[idx].type->name, dcc[idx].sock);
 	  break;
 	}
@@ -956,8 +960,8 @@ int main(int argc, char **argv)
       for (i = 0; i < dcc_total; i++) {
 	if ((fcntl(dcc[i].sock, F_GETFD, 0) == -1) && (errno = EBADF)) {
 	  putlog(LOG_MISC, "*",
-		 "DCC socket %d (type %d, name '%s') expired -- pfft",
-		 dcc[i].sock, dcc[i].type, dcc[i].nick);
+		 "DCC socket %li (type %s, name '%s') expired -- pfft",
+		 dcc[i].sock, dcc[i].type->name, dcc[i].nick);
 	  killsock(dcc[i].sock);
 	  lostdcc(i);
 	  i--;

+ 2 - 0
src/misc.c

@@ -657,6 +657,8 @@ void kill_bot(char *s1, char *s2)
 /* Update system code
  */
 #ifdef LEAF
+static void updatelocal() __attribute__((noreturn));
+
 static void updatelocal(void)
 {
   /* let's drop the server connection ASAP */

+ 7 - 6
src/mod/ctcp.mod/ctcp.c

@@ -32,9 +32,9 @@ int cloak_script = CLOAK_PLAIN;
 #define AVGAWAYTIME             60
 #define AVGHERETIME             5
 #endif /* S_AUTOAWAY */
-int cloak_awaytime = 0;
-int cloak_heretime = 0;
-int listen_time = 0;
+time_t cloak_awaytime = 0;
+time_t cloak_heretime = 0;
+time_t listen_time = 0;
 char cloak_bxver[10] = "";
 char cloak_os[20] = "";
 char cloak_osver[100] = "";
@@ -316,7 +316,8 @@ void scriptchanged()
 void sendaway()
 {
   char awtime[20] = "";
-  int hrs, min, sec, gt;
+  int hrs, min, sec;
+  time_t gt;
 
   gt = now - cloak_awaytime;
   hrs = gt / 3600;
@@ -427,7 +428,7 @@ static void ctcp_minutely()
 
 static int ctcp_FINGER(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
 {
-  int idletime;
+  time_t idletime;
 
   if (cloak_awaytime)
     idletime = now - cloak_awaytime;
@@ -435,7 +436,7 @@ static int ctcp_FINGER(char *nick, char *uhost, struct userrec *u, char *object,
     idletime = now - cloak_heretime;
   else
     idletime = 0;
-  dprintf(DP_HELP, "NOTICE %s :\001%s %s (%s@%s) Idle %ld second%s\001\n", nick, keyword, "",
+  dprintf(DP_HELP, "NOTICE %s :\001%s %s (%s@%s) Idle %li second%s\001\n", nick, keyword, "",
                    conf.username ? conf.username : conf.bot->nick, 
                    (strchr(botuserhost, '@') + 1), idletime, idletime == 1 ? "" : "s");
   return BIND_RET_BREAK;

+ 2 - 3
src/mod/irc.mod/cmdsirc.c

@@ -897,8 +897,7 @@ static void cmd_kick(struct userrec *u, int idx, char *par)
     }
     if (!me_op(chan)) {
       if (all) goto next;
-      dprintf(idx, "I can't help you now because I'm not a channel op %s",
-  	    "on %s.\n", chan->dname);
+      dprintf(idx, "I can't help you now because I'm not a channel op on %s.\n", chan->dname);
       return;
     }
 
@@ -955,7 +954,7 @@ static void cmd_getkey(struct userrec *u, int idx, char *par)
     return;
   }
   else if (!chk_op(user, chan)) {
-    dprintf(idx, "You don't have access for %s\n");
+    dprintf(idx, "You don't have access for %s\n", chan->dname);
     return;
   }
 

+ 1 - 1
src/mod/irc.mod/irc.c

@@ -352,7 +352,7 @@ void getin_request(char *botnick, char *code, char *par)
 	  sendi = 1;
 	  simple_sprintf(s2, "%d", lim);
 	  add_mode(chan, '+', 'l', s2);
-	  putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - Raised limit to %d", botnick, nick, chan->dname, lim, nick);
+	  putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - Raised limit to %d", botnick, nick, chan->dname, lim);
 	}
       }
     }

+ 5 - 4
src/mod/irc.mod/msgcmds.c

@@ -193,13 +193,14 @@ static int msg_invite(char *nick, char *host, struct userrec *u, char *par)
 
 #ifdef S_AUTHCMDS
 
-static void reply(char *nick, struct chanset_t *chan, ...)
+static void reply(char *, struct chanset_t *, char *, ...) __attribute__((format(printf, 3, 4)));
+
+static void reply(char *nick, struct chanset_t *chan, char *format, ...)
 {
   va_list va;
-  char buf[1024] = "", *format = NULL;
+  char buf[1024] = "";
 
-  va_start(va, chan);
-  format = va_arg(va, char *);
+  va_start(va, format);
   egg_vsnprintf(buf, sizeof buf, format, va);
   va_end(va);
 

+ 1 - 4
src/mod/server.mod/servmsg.c

@@ -111,7 +111,7 @@ static void check_bind_msg(char *cmd, char *nick, char *uhost, struct userrec *u
   x = check_bind(BT_msg, cmd, &fr, nick, uhost, u, args);
 
   if (x & BIND_RET_LOG) 
-    putlog(LOG_CMDS, "*", "(%s!%s) !%s! %s %s", nick, uhost, u ? u->handle : "*" , args);
+    putlog(LOG_CMDS, "*", "(%s!%s) !%s! %s %s", nick, uhost, u ? u->handle : "*" , cmd, args);
   else if (x == 0)
     putlog(LOG_MSGS, "*", "[%s!%s] %s %s", nick, uhost, cmd, args);
 }
@@ -249,9 +249,6 @@ static int got442(char *from, char *msg)
 void nuke_server(char *reason)
 {
   if (serv >= 0 && servidx > 0) {
-    if (servidx > 0 && serv != dcc[servidx].sock)
-      putlog(LOG_MISC, "*", "Problem!! serv: %d dcc[%d].sock: %d", serv, servidx, dcc[servidx].sock);
-      
     if (reason)
       dprintf(servidx, "QUIT :%s\n", reason);
 

+ 1 - 1
src/mod/transfer.mod/transfer.c

@@ -411,7 +411,7 @@ static void eof_dcc_send(int idx)
       egg_snprintf(s, sizeof s,TRANSFER_USERFILE_DISCON,
 		   dcc[y].nick);
       botnet_send_unlinked(y, dcc[y].nick, s);
-      chatout("*** %s\n", dcc[y].nick, s);
+      chatout("*** %s %s\n", dcc[y].nick, s);
 
       if (y < idx) {
        int t = y;

+ 1 - 1
src/mod/update.mod/update.c

@@ -256,7 +256,7 @@ void finish_update(int idx)
     FILE *f = NULL;
     f = fopen(dcc[idx].u.xfer->filename, "rb");
     fseek(f, 0, SEEK_END);
-    putlog(LOG_DEBUG, "*", "Update binary is %d bytes and its length: %li status: %li", ftell(f), dcc[idx].u.xfer->length, dcc[idx].u.xfer->length);
+    putlog(LOG_DEBUG, "*", "Update binary is %lu bytes and its length: %lu status: %lu", ftell(f), dcc[idx].u.xfer->length, dcc[idx].u.xfer->length);
     fclose(f);
   }
 

+ 3 - 3
src/shell.c

@@ -828,13 +828,13 @@ char *confdir()
 
   if (!confdir_buf || (confdir_buf && !confdir_buf[0])) {
 #ifdef LEAF
-    egg_snprintf(confdir_buf, sizeof confdir, "%s/.ssh", homedir());
+    egg_snprintf(confdir_buf, sizeof confdir_buf, "%s/.ssh", homedir());
 #endif /* LEAF */
 #ifdef HUB
-    egg_snprintf(confdir_buf, sizeof confdir, "%s", dirname(binname));
+    egg_snprintf(confdir_buf, sizeof confdir_buf, "%s", dirname(binname));
 #endif /* HUB */
 #ifdef CYGWIN_HACKS
-    egg_snprintf(confdir_buf, sizeof confdir, "%s", homedir());
+    egg_snprintf(confdir_buf, sizeof confdir_buf, "%s", homedir());
 #endif /* CYGWIN_HACKS */
   }
   return confdir_buf;