瀏覽代碼

Add some pure/const attributes

Bryan Drewery 7 年之前
父節點
當前提交
3a84b0a664
共有 39 個文件被更改,包括 154 次插入144 次删除
  1. 1 1
      src/base64.cc
  2. 1 1
      src/base64.h
  3. 0 0
      src/binds.cc
  4. 4 4
      src/botnet.cc
  5. 5 5
      src/botnet.h
  6. 16 11
      src/chanprog.cc
  7. 10 7
      src/chanprog.h
  8. 5 13
      src/cmds.cc
  9. 14 5
      src/cmds.h
  10. 1 1
      src/conf.h
  11. 0 2
      src/crypt.h
  12. 4 3
      src/dcc.cc
  13. 1 1
      src/dcc.h
  14. 2 10
      src/dccutil.cc
  15. 9 3
      src/dccutil.h
  16. 2 1
      src/egg_timer.h
  17. 2 2
      src/flags.cc
  18. 13 11
      src/flags.h
  19. 1 1
      src/garble.cc
  20. 2 2
      src/log.cc
  21. 1 1
      src/log.h
  22. 5 5
      src/match.cc
  23. 3 3
      src/match.h
  24. 3 4
      src/misc.h
  25. 5 5
      src/misc_file.h
  26. 3 9
      src/net.cc
  27. 13 8
      src/net.h
  28. 2 1
      src/response.h
  29. 2 2
      src/rfc1459.cc
  30. 4 4
      src/rfc1459.h
  31. 4 2
      src/set.cc
  32. 1 1
      src/set.h
  33. 2 2
      src/shell.cc
  34. 5 5
      src/shell.h
  35. 1 1
      src/socket.cc
  36. 1 1
      src/socket.h
  37. 2 2
      src/tandem.h
  38. 1 1
      src/userent.cc
  39. 3 3
      src/users.h

+ 1 - 1
src/base64.cc

@@ -54,7 +54,7 @@ static const char base64r[256] = {
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 };
 
-static char base64to[256] =
+static const char base64to[256] =
 {
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

+ 1 - 1
src/base64.h

@@ -7,7 +7,7 @@ namespace bd {
 };
 
 char *int_to_base64(unsigned int);
-int base64_to_int(const char *);
+int base64_to_int(const char *) __attribute__((pure));
 
 bd::String broken_base64Encode(const bd::String&);
 char *b64enc(const unsigned char *data, size_t len);

文件差異過大導致無法顯示
+ 0 - 0
src/binds.cc


+ 4 - 4
src/botnet.cc

@@ -245,7 +245,7 @@ void partysetidle(char *bot, int sock, int secs)
 
 /* Return someone's chat channel.
  */
-int getparty(char *bot, int sock)
+int getparty(const char *bot, int sock)
 {
   for (int i = 0; i < parties; i++) {
     if (!strcasecmp(party[i].bot, bot) &&
@@ -852,7 +852,7 @@ void dump_links(int z)
   }
 }
 
-int in_chain(char *who)
+int in_chain(const char *who)
 {
   if (!strcasecmp(who, conf.bot->nick))
     return 1;
@@ -861,7 +861,7 @@ int in_chain(char *who)
   return 0;
 }
 
-int bots_in_subtree(tand_t *bot)
+int bots_in_subtree(const tand_t *bot)
 {
   if (!bot)
     return 0;
@@ -877,7 +877,7 @@ int bots_in_subtree(tand_t *bot)
   return nr;
 }
 
-int users_in_subtree(tand_t *bot)
+int users_in_subtree(const tand_t *bot)
 {
   if (!bot)
     return 0;

+ 5 - 5
src/botnet.h

@@ -13,9 +13,9 @@ extern int		tands;
 
 void lower_bot_linked(int idx);
 void answer_local_whom(int, int);
-char *lastbot(const char *);
-int nextbot(const char *);
-int in_chain(char *);
+char *lastbot(const char *) __attribute__((pure));
+int nextbot(const char *) __attribute__((pure));
+int in_chain(const char *) __attribute__((pure));
 void tell_bots(int, int, const char *);
 void tell_bottree(int);
 void dump_links(int);
@@ -24,7 +24,7 @@ int botunlink(int, const char *, const char *);
 void addbot(char *, char *, char *, char, int, time_t, char *, char *, int);
 void updatebot(int, char *, char, int, time_t, char *, char *, int);
 void rembot(const char *);
-tand_t *findbot(const char *);
+tand_t *findbot(const char *) __attribute__((pure));
 void unvia(int, struct tand_t_struct *);
 void check_botnet_pings();
 int addparty(char *, char *, int, char, int, char *, int *);
@@ -37,6 +37,6 @@ void partyaway(char *, int, char *);
 void botnet_send_cmdpass(int, char *, char *);
 void zapfbot(int);
 void tandem_relay(int, char *, int);
-int getparty(char *, int);
+int getparty(const char *, int) __attribute__((pure));
 void init_party(void);
 #endif /* !_BOTNET_H */

+ 16 - 11
src/chanprog.cc

@@ -117,8 +117,8 @@ struct chanset_t *findchan(const char *name)
 struct userrec *check_chanlist(const char *host)
 {
   char				*nick = NULL, *uhost = NULL, buf[UHOSTLEN] = "";
-  memberlist		*m = NULL;
-  struct chanset_t	*chan = NULL;
+  const memberlist		*m = NULL;
+  const struct chanset_t	*chan = NULL;
 
   strlcpy(buf, host, sizeof buf);
   uhost = buf;
@@ -134,8 +134,8 @@ struct userrec *check_chanlist(const char *host)
  */
 struct userrec *check_chanlist_hand(const char *hand)
 {
-  struct chanset_t	*chan = NULL;
-  memberlist		*m = NULL;
+  const struct chanset_t	*chan = NULL;
+  const memberlist		*m = NULL;
 
   for (chan = chanset; chan; chan = chan->next)
     for (m = chan->channel.member; m && m->nick[0]; m = m->next)
@@ -344,8 +344,10 @@ void reaffirm_owners()
 }
 
 bool is_hub(const char* nick) {
+  bd::String hub(size_t(HANDLEN));
+
   for (size_t idx = 0; idx < conf.hubs.length(); ++idx) {
-    bd::String hub(conf.hubs[idx]);
+    hub = conf.hubs[idx];
     if (!strncasecmp(nick, newsplit(hub).c_str(), HANDLEN)) {
       return true;
     }
@@ -674,14 +676,14 @@ void setup_HQ(int n) {
 
 /* Oddly enough, written by proton (Emech's coder)
  */
-int isowner(char *name)
+int isowner(const char *name)
 {
   if (!owner[0])
     return (0);
   if (!name || !name[0])
     return (0);
 
-  char *pa = owner, *pb = owner;
+  const char *pa = owner, *pb = owner;
   size_t nl = strlen(name), pl;
 
   while (1) {
@@ -704,7 +706,8 @@ int isowner(char *name)
   }
 }
 
-bool bot_shouldjoin(struct userrec* u, struct flag_record* fr, const struct chanset_t* chan, bool ignore_inactive)
+bool bot_shouldjoin(struct userrec* u, const struct flag_record* fr,
+    const struct chanset_t* chan, bool ignore_inactive)
 {
   // If restarting, keep this channel.
   if (restarting && (reset_chans == 2) && (channel_active(chan) || channel_pending(chan))) return 1;
@@ -810,11 +813,11 @@ int do_chanset(char *result, struct chanset_t *chan, const char *options, int fl
   return ret;
 }
 
-char *
+const char *
 samechans(const char *nick, const char *delim)
 {
   static char ret[1024] = "";
-  struct chanset_t *chan = NULL;
+  const struct chanset_t *chan = NULL;
 
   ret[0] = 0;		/* may be filled from last time */
   for (chan = chanset; chan; chan = chan->next) {
@@ -827,7 +830,9 @@ samechans(const char *nick, const char *delim)
   return ret;
 }
 
-static struct chanset_t* find_common_opped_chan(bd::String nick) {
+static struct chanset_t*
+__attribute__((pure))
+find_common_opped_chan(bd::String nick) {
   for (struct chanset_t* chan = chanset; chan; chan = chan->next) {
     if (channel_active(chan) && (me_op(chan) || me_voice(chan))) {
       if (ismember(chan, nick.c_str()))

+ 10 - 7
src/chanprog.h

@@ -15,7 +15,7 @@ void checkchans(int);
 void tell_verbose_uptime(int);
 void tell_verbose_status(int);
 void tell_settings(int);
-int isowner(char *);
+int isowner(const char *) __attribute__((pure));
 void reaffirm_owners();
 void reload();
 void chanprog();
@@ -26,40 +26,43 @@ void rmspace(char *s);
 void set_chanlist(const char *host, struct userrec *rec);
 void clear_chanlist_member(const char *nick);
 #define clear_chanlist() clear_chanlist_member(NULL)
-bool bot_shouldjoin(struct userrec* , struct flag_record *, const struct chanset_t *, bool = 0);
+bool bot_shouldjoin(struct userrec*, const struct flag_record *, const struct chanset_t *, bool = 0);
 bool shouldjoin(const struct chanset_t *);
-char *samechans(const char *, const char *);
+const char *samechans(const char *, const char *);
 void add_myself_to_userlist();
 void add_child_bots();
-bool is_hub(const char*);
+bool is_hub(const char*) __attribute__((pure));
 void load_internal_users();
 void setup_HQ(int);
 void privmsg(bd::String target, bd::String msg, int idx);
 void notice(bd::String target, bd::String msg, int idx);
 void keyx(const bd::String& target, const char *);
 void set_fish_key(char *, bd::String);
-struct userrec *check_chanlist(const char *);
-struct userrec *check_chanlist_hand(const char *);
+struct userrec *check_chanlist(const char *) __attribute__((pure));
+struct userrec *check_chanlist_hand(const char *) __attribute__((pure));
 /*
  * Returns memberfields if the nick is in the member list.
  */
 static inline memberlist *
+__attribute__((pure))
 ismember(const struct chanset_t *chan, const RfcString& nick) {
   if (!chan || !nick)
     return NULL;
   return (*chan->channel.hashed_members)[nick];
 }
 static inline memberlist *
+__attribute__((pure))
 ismember(const struct chanset_t *chan, const char *nick) {
   if (!chan || !nick || !nick[0])
     return NULL;
   return ismember(chan, RfcString(nick));
 }
-struct chanset_t *findchan(const char *name);
+struct chanset_t *findchan(const char *name) __attribute__((pure));
 /*
  * Find a chanset by display name (ie !channel)
  */
 static inline struct chanset_t *
+__attribute__((pure))
 findchan_by_dname(const char *name) {
   return chanset_by_dname[name];
 }

+ 5 - 13
src/cmds.cc

@@ -608,21 +608,13 @@ static void cmd_nohelp(int idx, char *par)
   dumplots(idx, "", buf);
 }
 
-bool is_restricted_cmd(const char* name) {
-  if (name) {
-    if (!HAVE_MDOP && !strcasecmp(name, "mmode"))
-      return 1;
-  }
-  return 0;
-}
-
 static int comp_help_t(const void *m1, const void *m2) {
   const help_t *mi1 = (const help_t *) m1;
   const help_t *mi2 = (const help_t *) m2;
   return strcasecmp(mi1->cmd, mi2->cmd);
 }
 
-help_t *
+const help_t *
 findcmd(const char *lookup, bool care_about_type)
 {
   help_t key;
@@ -679,7 +671,7 @@ static void cmd_help(int idx, char *par)
         flg[0] = 0;
         build_flags(flg, &(cmdlist[n].flags), NULL);
         dprintf(idx, "Showing you help for '%s' (%s):\n", match, flg);
-        help_t *h_entry = NULL;
+        const help_t *h_entry = NULL;
         if ((h_entry = findhelp(match)) != NULL) {
           if (h_entry->garble_len)
             showhelp(idx, &fr, degarble(h_entry->garble_len, h_entry->desc));
@@ -3033,7 +3025,7 @@ static void cmd_color(int idx, char *par)
   console_dostore(idx);
 }
 
-int stripmodes(char *s)
+int stripmodes(const char *s)
 {
   int res = 0;
 
@@ -3064,7 +3056,7 @@ int stripmodes(char *s)
   return res;
 }
 
-char *stripmasktype(int x)
+const char *stripmasktype(int x)
 {
   static char s[20] = "";
   char *p = s;
@@ -3087,7 +3079,7 @@ char *stripmasktype(int x)
   return s;
 }
 
-static char *stripmaskname(int x)
+static const char *stripmaskname(int x)
 {
   static char s[161] = "";
   size_t i = 0;

+ 14 - 5
src/cmds.h

@@ -3,8 +3,6 @@
 
 #include "types.h"
 
-bool is_restricted_cmd(const char*);
-
 typedef struct {
   const char          *name;
   const char          *flags;
@@ -44,12 +42,23 @@ typedef struct cmd_pass {
 extern mycmds 		cmdlist[]; 
 extern int		cmdi;
 
+static inline bool
+__attribute__((pure))
+is_restricted_cmd(const char* name)
+{
+  if (name) {
+    if (!HAVE_MDOP && !strcasecmp(name, "mmode"))
+      return 1;
+  }
+  return 0;
+}
+
 #define findhelp(x) findcmd(x, 1)
-help_t *findcmd(const char *lookup, bool care_about_type);
+const help_t *findcmd(const char *lookup, bool care_about_type) __attribute__((pure));
 int check_dcc_attrs(struct userrec *, flag_t);
 int check_dcc_chanattrs(struct userrec *, char *, flag_t, flag_t);
-int stripmodes(char *);
-char *stripmasktype(int);
+int stripmodes(const char *) __attribute__((pure));
+const char *stripmasktype(int);
 void gotremotecmd(char * forbot, char * frombot, char * fromhand, char * fromidx, char * cmd);
 void gotremotereply(char * frombot, char * tohand, char * toidx, char * ln);
 

+ 1 - 1
src/conf.h

@@ -72,7 +72,7 @@ void conf_checkpids(conf_bot *bots, bool all = 1);
 void conf_add_userlist_bots();
 conf_bot *conf_bots_dup(conf_bot *);
 void deluser_removed_bots(conf_bot *, conf_bot *);
-conf_bot *conf_getlocalhub(conf_bot *);
+conf_bot *conf_getlocalhub(conf_bot *) __attribute__((pure));
 void conf_setmypid(pid_t);
 void conf_bot_dup(conf_bot *dest, conf_bot *src);
 void conf_update_hubs(struct userrec* list);

+ 0 - 2
src/crypt.h

@@ -29,8 +29,6 @@ char *encrypt_string(const char *, char *);
 char *decrypt_string(const char *, char *);
 char *salted_sha1(const char *, const char* = NULL);
 int salted_sha1cmp(const char *, const char*);
-char *cryptit (char *);
-char *decryptit (char *);
 void Encrypt_File(char *, char *);
 void Decrypt_File(char *, char *);
 void btoh(const unsigned char *md, size_t md_len, char *buf, const size_t buf_len);

+ 4 - 3
src/dcc.cc

@@ -1145,7 +1145,8 @@ struct dcc_table DCC_CHAT_PASS = {
 /* Make sure ansi code is just for color-changing
  */
 static int
-check_ansi(char *v)
+__attribute__((pure))
+check_ansi(const char *v)
 {
   int count = 2;
 
@@ -1164,9 +1165,9 @@ check_ansi(char *v)
   return count;
 }
 
-int ansi_len(char *s)
+int ansi_len(const char *s)
 {
-  char *c = s;
+  const char *c = s;
   int count = 0;
 
   while (*c) {

+ 1 - 1
src/dcc.h

@@ -241,6 +241,6 @@ void send_timesync(int);
 void failed_link(int);
 void dupwait_notify(const char *);
 void send_sysinfo();
-int ansi_len(char *);
+int ansi_len(const char *) __attribute__((pure));
 
 #endif /* !_DCC_H */

+ 2 - 10
src/dccutil.cc

@@ -1119,17 +1119,9 @@ identd_close()
   }
 }
 
-bool
-valid_idx(int idx)
-{
-  if ((idx == -1) || (idx >= dcc_total) || (!dcc[idx].type))
-    return 0;
-  return 1;
-}
-
 int check_cmd_pass(const char *cmd, char *pass)
 {
-  struct cmd_pass *cp = NULL;
+  const struct cmd_pass *cp = NULL;
 
   for (cp = cmdpass; cp; cp = cp->next)
     if (!strcasecmp(cmd, cp->name)) {
@@ -1166,7 +1158,7 @@ int check_cmd_pass(const char *cmd, char *pass)
 
 int has_cmd_pass(const char *cmd)
 {
-  struct cmd_pass *cp = NULL;
+  const struct cmd_pass *cp = NULL;
 
   for (cp = cmdpass; cp; cp = cp->next)
     if (!strcasecmp(cmd, cp->name))

+ 9 - 3
src/dccutil.h

@@ -52,7 +52,6 @@ void not_away(int);
 void set_away(int, char *);
 void dcc_remove_lost(void);
 void flush_lines(int, struct chat_info *);
-struct dcc_t *find_idx(int);
 int new_dcc(struct dcc_table *, int);
 void del_dcc(int);
 char *add_cr(char *);
@@ -62,11 +61,18 @@ int detect_dcc_flood(time_t *, struct chat_info *, int);
 void identd_open(const char * = NULL, const char * = NULL, int identd = 1);
 void identd_close();
 int listen_all(in_port_t, bool, bool);
-bool valid_idx(int);
+static inline bool __attribute__((pure))
+valid_idx(int idx)
+{
+  if ((idx == -1) || (idx >= dcc_total) || (!dcc[idx].type))
+    return false;
+  return true;
+}
+
 int dcc_read(bd::Stream&);
 void dcc_write(bd::Stream&, int);
 int check_cmd_pass(const char *, char *);
-int has_cmd_pass(const char *);
+int has_cmd_pass(const char *) __attribute__((pure));
 void set_cmd_pass(char *, int);
 void cmdpass_free(struct cmd_pass *);
 

+ 2 - 1
src/egg_timer.h

@@ -20,7 +20,8 @@ void timer_get_now(egg_timeval_t *_now);
 int timer_get_now_sec(int *sec);
 void timer_update_now(egg_timeval_t *_now);
 int timer_diff(egg_timeval_t *from_time, egg_timeval_t *to_time, egg_timeval_t *diff);
-long timeval_diff(const egg_timeval_t *tv1, const egg_timeval_t *tv2);
+long timeval_diff(const egg_timeval_t *tv1, const egg_timeval_t *tv2)
+  __attribute__((pure));
 int timer_create_secs(int, const char *, Function);
 int timer_create_complex(egg_timeval_t *howlong, const char *name, Function callback, void *client_data, int flags);
 int timer_destroy(int timer_id);

+ 2 - 2
src/flags.cc

@@ -299,7 +299,7 @@ build_flags(char *string, struct flag_record *plus, struct flag_record *minus)
 
 /* Returns 1 if flags match, 0 if they don't. */
 int
-flagrec_ok(struct flag_record *req, struct flag_record *have)
+flagrec_ok(const struct flag_record *req, const struct flag_record *have)
 {
   if (req->match & FR_AND) {
     return flagrec_eq(req, have);
@@ -320,7 +320,7 @@ flagrec_ok(struct flag_record *req, struct flag_record *have)
 
 /* Returns 1 if flags match, 0 if they don't. */
 int
-flagrec_eq(struct flag_record *req, struct flag_record *have)
+flagrec_eq(const struct flag_record *req, const struct flag_record *have)
 {
   if (req->match & FR_AND) {
     if (req->match & FR_GLOBAL) {

+ 13 - 11
src/flags.h

@@ -167,18 +167,20 @@ void get_user_flagrec(const struct userrec *, struct flag_record *, const char *
 void set_user_flagrec(struct userrec *, struct flag_record *, const char *);
 void break_down_flags(const char *, struct flag_record *, struct flag_record *);
 int build_flags(char *, struct flag_record *, struct flag_record *);
-int flagrec_eq(struct flag_record *, struct flag_record *);
-int flagrec_ok(struct flag_record *, struct flag_record *);
-flag_t sanity_check(flag_t, int);
-flag_t chan_sanity_check(flag_t, int);
+int flagrec_eq(const struct flag_record *, const struct flag_record *)
+  __attribute__((pure));
+int flagrec_ok(const struct flag_record *, const struct flag_record *)
+  __attribute__((pure));
+flag_t sanity_check(flag_t, int) __attribute__((const));
+flag_t chan_sanity_check(flag_t, int) __attribute__((const));
 char geticon(int);
-int privchan(const struct flag_record, const struct chanset_t *, int);
+int privchan(const struct flag_record, const struct chanset_t *, int) __attribute__((pure));
 #define chk_op(fr, chan) real_chk_op(fr, chan, 1)
-int real_chk_op(const struct flag_record, const struct chanset_t *, bool);
-int chk_autoop(const memberlist *, const struct flag_record, const struct chanset_t *);
+int real_chk_op(const struct flag_record, const struct chanset_t *, bool) __attribute__((pure));
+int chk_autoop(const memberlist *, const struct flag_record, const struct chanset_t *) __attribute__((pure));
 #define chk_deop(fr, chan) real_chk_deop(fr, chan, 1)
-int real_chk_deop(const struct flag_record, const struct chanset_t *, bool);
-int chk_voice(const memberlist *, const struct flag_record, const struct chanset_t *);
+int real_chk_deop(const struct flag_record, const struct chanset_t *, bool) __attribute__((pure));
+int chk_voice(const memberlist *, const struct flag_record, const struct chanset_t *) __attribute__((pure));
 #define chk_noflood(fr) (chan_noflood(fr) || glob_noflood(fr))
 #define chk_devoice(fr) ((chan_quiet(fr) || (glob_quiet(fr) && !chan_voice(fr))) ? 1 : 0)
 #define isupdatehub() ((conf.bot->hub && conf.bot->u && (conf.bot->u->flags & BOT_UPDATEHUB)) ? 1 : 0)
@@ -188,9 +190,9 @@ int dovoice(const struct chanset_t *);
 int doflood(const struct chanset_t *);
 int dolimit(const struct chanset_t *);
 int whois_access(struct userrec *, struct userrec *);
-homechan_user_t homechan_user_translate(const char *);
+homechan_user_t homechan_user_translate(const char *) __attribute__((pure));
 void deflag_user(struct userrec *, deflag_event_t, const char *, const struct chanset_t *);
-deflag_t deflag_translate(const char *);
+deflag_t deflag_translate(const char *) __attribute__((pure));
 
 
 #endif				/* _EGG_FLAGS_H */

+ 1 - 1
src/garble.cc

@@ -10,7 +10,7 @@
 #include "main.h"
 
 #define GARBLE_BUFFERS 40
-unsigned char *garble_buffer[GARBLE_BUFFERS] = {
+static unsigned char *garble_buffer[GARBLE_BUFFERS] = {
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
 };

+ 2 - 2
src/log.cc

@@ -85,7 +85,7 @@ static logmode_mapping_t logmode_mappings[] = {
 
 int logmodes(const char *s)
 {
-	logmode_mapping_t *mapping = NULL;
+	const logmode_mapping_t *mapping = NULL;
 	int modes = 0;
 
 	while (*s) {
@@ -119,7 +119,7 @@ char *masktype(int x)
 char *maskname(int x)
 {
 	static char s[1024] = "";
-	logmode_mapping_t *mapping = NULL;
+	const logmode_mapping_t *mapping = NULL;
 	int len;
 
 	*s = 0;

+ 1 - 1
src/log.h

@@ -30,7 +30,7 @@
 
 void logidx(int, const char *, ...) __attribute__((format(printf, 2, 3)));
 void putlog (int, const char *, const char *, ...) __attribute__((format(printf, 3, 4)));
-int logmodes(const char *);
+int logmodes(const char *) __attribute__((pure));
 char *masktype(int);
 char *maskname(int);
 #if 0

+ 5 - 5
src/match.cc

@@ -64,13 +64,13 @@
 #define PERMATCH (match+saved+sofar)
 
 /* binds matching */
-int _wild_match_per(unsigned char *m, unsigned char *n)
+int _wild_match_per(const unsigned char *m, const unsigned char *n)
 {
   /* null strings should never match */
   if ((m == 0) || (n == 0) || (!*n))
     return NOMATCH;
 
-  unsigned char *ma = m, *lsm = NULL, *lsn = NULL, *lpm = NULL, *lpn = NULL;
+  const unsigned char *ma = m, *lsm = NULL, *lsn = NULL, *lpm = NULL, *lpn = NULL;
   int match = 1, saved = 0, space;
   int sofar = 0;
 
@@ -162,15 +162,15 @@ int _wild_match_per(unsigned char *m, unsigned char *n)
 
 
 /* general/host matching */
-int _wild_match(unsigned char *m, unsigned char *n)
+int _wild_match(const unsigned char *m, const unsigned char *n)
 {
-  unsigned char *ma = m, *na = n;
+  const unsigned char *ma = m, *na = n;
 
   /* null strings should never match */
   if ((ma == 0) || (na == 0) || (!*ma) || (!*na))
     return NOMATCH;
 
-  unsigned char *lsm = NULL, *lsn = NULL;
+  const unsigned char *lsm = NULL, *lsn = NULL;
   int match = 1;
   int sofar = 0;
 

+ 3 - 3
src/match.h

@@ -8,12 +8,12 @@ int wild_match_per(unsigned char *, unsigned char *);
 #define wild_match(a,b) _wild_match((unsigned char *)(a),(unsigned char *)(b))
 #define wild_match_per(a,b) _wild_match_per((unsigned char *)(a),(unsigned char *)(b))
 
-int _wild_match(unsigned char *, unsigned char *);
-int _wild_match_per(unsigned char *, unsigned char *);
+int _wild_match(const unsigned char *, const unsigned char *) __attribute__((pure));
+int _wild_match_per(const unsigned char *, const unsigned char *) __attribute__((pure));
 
 //int wild_match(char *, char *);
 //int wild_match_per(char *, char *);
 
-int match_cidr(const char *, const char *);
+int match_cidr(const char *, const char *) __attribute__((pure));
 
 #endif /* !_MATCH_H */

+ 3 - 4
src/misc.h

@@ -16,8 +16,8 @@
 
 
 void restart(int);
-int coloridx(int);
-const char *color(int, int, int);
+int coloridx(int) __attribute__((pure));
+const char *color(int, int, int) __attribute__((pure));
 void shuffle(char *, char *, size_t);
 void shuffleArray(char **, size_t);
 void showhelp(int, struct flag_record *, const char *);
@@ -31,7 +31,6 @@ size_t my_strcpy(char *, const char *);
 void maskaddr(const char *, char *, int);
 #define maskhost(a,b) maskaddr((a),(b),3)
 #define maskban(a,b)  maskaddr((a),(b),3)
-char *stristr(char *, char *);
 void splitc(char *, char *, char);
 void splitcn(char *, char *, char, size_t);
 int remove_crlf(char *);
@@ -49,7 +48,7 @@ void make_rand_str(char *, size_t, bool = 1);
 char *str_escape(const char *, const char, const char);
 char *strchr_unescape(char *, const char, const char);
 void str_unescape(char *, const char);
-int str_isdigit(const char *);
+int str_isdigit(const char *) __attribute__((pure));
 void kill_bot(char *, char *);
 char *strtolower(char *);
 char *strtoupper(char *);

+ 5 - 5
src/misc_file.h

@@ -13,11 +13,11 @@
 
 int copyfile(const char *, const char *);
 int movefile(const char *, const char *);
-int is_file(const char *);
-int can_stat(const char *);
-int can_lstat(const char *);
-int is_symlink(const char *);
-int is_dir(const char *);
+int is_file(const char *) __attribute__((pure));
+int can_stat(const char *) __attribute__((pure));
+int can_lstat(const char *) __attribute__((pure));
+int is_symlink(const char *) __attribute__((pure));
+int is_dir(const char *) __attribute__((pure));
 int fixmod(const char *);
 
 class Tempfile 

+ 3 - 9
src/net.cc

@@ -161,7 +161,7 @@ void init_net()
 
 /* Get my ipv? ip
  */
-char *myipstr(int af_type)
+const char *myipstr(int af_type)
 {
   if (cached_ip) {
 #ifdef USE_IPV6
@@ -185,12 +185,6 @@ char *myipstr(int af_type)
   return "";
 }
 
-/* Get my ip number
- */
-in_addr_t getmyip() {
-  return cached_myip4_so.sin.sin_addr.s_addr;
-}
-
 /* see if it's necessary to set inaddr_any... because if we can't resolve, we die anyway */
 void cache_my_ip()
 {
@@ -846,13 +840,13 @@ int open_listen_addr_by_af(const char *ip, in_port_t *port, int af_def)
 /* Returns the given network byte order IP address in the
  * dotted format - "##.##.##.##"
  */
-char *iptostr(in_addr_t ip)
+const char *iptostr(in_addr_t ip)
 {
   static char ipbuf[32];
   struct in_addr a;
 
   a.s_addr = ip;
-  return (char *) inet_ntop(AF_INET, &a, ipbuf, sizeof(ipbuf));
+  return inet_ntop(AF_INET, &a, ipbuf, sizeof(ipbuf));
 }
 
 /* Short routine to answer a connect received on a socket made previously

+ 13 - 8
src/net.h

@@ -101,9 +101,8 @@ typedef struct {
 
 # define killsock(x)     	real_killsock((x),__FILE__,__LINE__)
 
-unsigned long my_atoul(const char *);
-char *myipstr(int);
-in_addr_t getmyip();
+unsigned long my_atoul(const char *) __attribute__((pure));
+const char *myipstr(int);
 void cache_my_ip();
 void setsock(int, int);
 int allocsock(int, int);
@@ -117,11 +116,11 @@ int real_getsock(int, const char *, int);
 #endif /* USE_IPV6 */
 
 
-int sockprotocol(int);
+int sockprotocol(int) __attribute__((pure));
 void real_killsock(int, const char *, int);
 int answer(int, char *, in_addr_t *, in_port_t *, int);
-int findanysnum(int);
-int findanyidx(int sock);
+int findanysnum(int) __attribute__((pure));
+int findanyidx(int sock) __attribute__((pure));
 int open_listen(in_port_t *);
 int open_listen_by_af(in_port_t *, int);
 int open_listen_addr_by_af(const char*, in_port_t *, int);
@@ -137,8 +136,8 @@ void tputs(int, const char *, size_t);
 void dequeue_sockets();
 int sockgets(char *, int *);
 void tell_netdebug(int);
-char *iptostr(in_addr_t);
-bool sock_has_data(int, int);
+const char *iptostr(in_addr_t);
+bool sock_has_data(int, int) __attribute__((pure));
 int sockoptions(int sock, int operation, int sock_options);
 void init_net(void);
 int sock_read(bd::Stream&);
@@ -159,4 +158,10 @@ extern in_port_t				firewallport;
 extern jmp_buf				alarmret;
 extern sock_list			*socklist;
 
+static inline in_addr_t
+__attribute__((pure))
+getmyip() {
+  return cached_myip4_so.sin.sin_addr.s_addr;
+}
+
 #endif /* !_NET_H */

+ 2 - 1
src/response.h

@@ -25,9 +25,10 @@
 typedef const char* response_t;
 
 void init_responses();
-const char *response(response_t);
+const char *response(response_t) __attribute__((pure));
 
 inline const char *
+__attribute__((pure))
 r_banned(struct chanset_t *chan)
 {
   return response(RES_BANNED);

+ 2 - 2
src/rfc1459.cc

@@ -27,8 +27,8 @@
 #include "common.h"
 #include "rfc1459.h"
 
-int (*rfc_casecmp) (const char *, const char *) __attribute__((const)) = _rfc_casecmp;
-int (*rfc_ncasecmp) (const char *, const char *, size_t) __attribute__((const)) = _rfc_ncasecmp;
+int (*rfc_casecmp) (const char *, const char *) __attribute__((pure)) = _rfc_casecmp;
+int (*rfc_ncasecmp) (const char *, const char *, size_t) __attribute__((pure)) = _rfc_ncasecmp;
 bool (*rfc_char_equal) (const char, const char) __attribute__((const)) = _rfc_char_equal;
 
 int

+ 4 - 4
src/rfc1459.h

@@ -1,8 +1,8 @@
 #ifndef _RFC1459_H
 #define _RFC1459_H
 
-int _rfc_casecmp(const char *, const char *) __attribute__((const));
-int _rfc_ncasecmp(const char *, const char *, size_t) __attribute__((const));
+int _rfc_casecmp(const char *, const char *) __attribute__((pure));
+int _rfc_ncasecmp(const char *, const char *, size_t) __attribute__((pure));
 
 static const unsigned char rfc_touppertab[] = {
   0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa,
@@ -58,7 +58,7 @@ _rfc_char_equal(const char c1, const char c2)
 }
 
 extern bool (*rfc_char_equal) (const char, const char) __attribute__((const));
-extern int (*rfc_casecmp) (const char *, const char *) __attribute__((const));
-extern int (*rfc_ncasecmp) (const char *, const char *, size_t) __attribute__((const));
+extern int (*rfc_casecmp) (const char *, const char *) __attribute__((pure));
+extern int (*rfc_ncasecmp) (const char *, const char *, size_t) __attribute__((pure));
 
 #endif /* !_RFC1459_H */

+ 4 - 2
src/set.cc

@@ -525,14 +525,16 @@ static int comp_variable_t(const void *m1, const void *m2) {
   return strcasecmp(mi1->name, mi2->name);
 }
 
-static inline variable_t *var_get_var_by_name(const char *name)
+static inline variable_t * __attribute__((pure))
+var_get_var_by_name(const char *name)
 {
   variable_t key;
   key.name = name;
   return (variable_t*) bsearch(&key, &vars, lengthof(vars) - 1, sizeof(variable_t), comp_variable_t);
 }
 
-const char *var_get_gdata(const char *name) {
+const char * __attribute__((pure))
+var_get_gdata(const char *name) {
   variable_t* var = var_get_var_by_name(name);
   return var && var->gdata ? var->gdata : NULL;
 }

+ 1 - 1
src/set.h

@@ -87,7 +87,7 @@ void init_vars();
 void var_set_by_name(const char *, const char *, const char *);
 void var_set_userentry(const char *, const char *, const char *);
 const char *var_get_bot_data(struct userrec *u, const char *name, bool useDefault = false);
-const char *var_get_gdata(const char *name);
+const char *var_get_gdata(const char *name) __attribute__((pure));
 int cmd_set_real(const char *, int idx, char *);
 const char *var_get_str_by_name(const char *);
 

+ 2 - 2
src/shell.cc

@@ -777,7 +777,7 @@ void werr(int errnum)
   exit(1); // This is never reached, done for gcc() warnings
 }
 
-char *homedir(bool useconf)
+const char *homedir(bool useconf)
 {
   static char homedir_buf[PATH_MAX] = "";
 
@@ -793,7 +793,7 @@ char *homedir(bool useconf)
   return homedir_buf[0] ? homedir_buf : NULL;
 }
 
-char *my_username()
+const char *my_username()
 {
   static char username[DIRMAX] = "";
 

+ 5 - 5
src/shell.h

@@ -48,8 +48,8 @@ namespace bd {
 void check_maxfiles();
 void check_mypid();
 void clear_tmp();
-char *homedir(bool = 1);
-char *my_username();
+const char *homedir(bool = 1);
+const char *my_username();
 void expand_tilde(char **);
 int shell_exec(char *, char *, char **, char **, bool = 0);
 int simple_exec(const char* argv[]);
@@ -63,9 +63,9 @@ void crontab_create(int);
 void detected(int, const char *);
 void suicide(const char *);
 void werr(int) __attribute__((noreturn));
-const char *werr_tostr(int);
-int det_translate(const char *);
-const char *det_translate_num(int);
+const char *werr_tostr(int) __attribute__((const));
+int det_translate(const char *) __attribute__((pure));
+const char *det_translate_num(int) __attribute__((const));
 char *shell_escape(const char *);
 int mkdir_p(const char *);
 extern bool		clear_tmpdir;

+ 1 - 1
src/socket.cc

@@ -246,7 +246,7 @@ int socket_ip_to_uint(const char *ip, unsigned int *longip)
 }
 
 #ifdef USE_IPV6
-static char hex_digits[] = {
+static const char hex_digits[] = {
         '0', '1', '2', '3', '4', '5', '6', '7',
         '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
 };

+ 1 - 1
src/socket.h

@@ -40,7 +40,7 @@ int socket_get_name(int sock, char **ip, int *port);
 //int socket_get_peer_name(int sock, char **peer_ip, int *peer_port);
 //int socket_get_error(int sock);
 //int socket_accept(int sock, char **peer_ip, int *peer_port);
-int is_dotted_ip(const char *ip);
+int is_dotted_ip(const char *ip) __attribute__((pure));
 int socket_ip_to_uint(const char *ip, unsigned int *longip);
 int socket_ipv6_to_dots(const char *ip, char *dots);
 

+ 2 - 2
src/tandem.h

@@ -73,8 +73,8 @@ void botnet_send_part_party(int, int, char *, int);
 void botnet_send_bye(const char *);
 void botnet_send_nkch_part(int, int, char *);
 void botnet_send_nkch(int, char *);
-int bots_in_subtree(tand_t *);
-int users_in_subtree(tand_t *);
+int bots_in_subtree(const tand_t *) __attribute__((pure));
+int users_in_subtree(const tand_t *) __attribute__((pure));
 int botnet_send_cmd(char * fbot, char * bot, char *fhnd, int fromidx, char * cmd);
 void botnet_send_cmd_broad(int idx, char * fbot, char *fhnd, int fromidx, char * cmd);
 void botnet_send_cmdreply(char * fbot, char * bot, char * to, char * toidx, char * ln);

+ 1 - 1
src/userent.cc

@@ -1068,7 +1068,7 @@ bool add_entry_type(struct user_entry_type *type)
   return 1;
 }
 
-struct user_entry_type *find_entry_type(char *name)
+struct user_entry_type *find_entry_type(const char *name)
 {
   struct user_entry_type *p = NULL;
 

+ 3 - 3
src/users.h

@@ -42,8 +42,8 @@ list_delete(struct list_type **h, struct list_type *i)
   return 0;
 }
 
-static inline bool
-list_contains(struct list_type *h, struct list_type *i)
+static inline bool __attribute__((pure))
+list_contains(const struct list_type *h, const struct list_type *i)
 {
   for (; h; h = h->next)
     if (h == i) {
@@ -120,7 +120,7 @@ struct filesys_stats {
 };
 
 bool add_entry_type(struct user_entry_type *);
-struct user_entry_type *find_entry_type(char *);
+struct user_entry_type *find_entry_type(const char *) __attribute__((pure));
 struct user_entry *find_user_entry(struct user_entry_type *, struct userrec *);
 void *get_user(struct user_entry_type *, struct userrec *);
 bool user_has_host(const char *, struct userrec *, char *);

部分文件因文件數量過多而無法顯示