Răsfoiți Sursa

* Port [3972] and [3973] to 1.2.16 from trunk
* Cleanup new use of bsearch()


svn: 3974

Bryan Drewery 17 ani în urmă
părinte
comite
f520680c80
4 a modificat fișierele cu 10 adăugiri și 7 ștergeri
  1. 3 2
      src/botcmd.c
  2. 3 2
      src/mod/share.mod/share.c
  3. 3 2
      src/mod/update.mod/update.c
  4. 1 1
      src/set.c

+ 3 - 2
src/botcmd.c

@@ -1215,7 +1215,8 @@ botcmd_t C_bot[] =
   {"vab",		bot_setbroad, 0},
   {"w",			bot_who, 0},
   {"z",			bot_zapf, 0},
-  {"zb",		bot_zapfbroad, 0}
+  {"zb",		bot_zapfbroad, 0},
+  {NULL,		NULL, 0}
 };
 
 static int comp_botcmd_t(const void *m1, const void *m2) {
@@ -1231,7 +1232,7 @@ const botcmd_t *search_botcmd_t(const botcmd_t *table, const char* keyString, si
 }
 
 void parse_botcmd(int idx, const char* code, const char* msg) {
-  const botcmd_t *cmd = search_botcmd_t((const botcmd_t*)&C_bot, code, sizeof(C_bot)/sizeof(botcmd_t));
+  const botcmd_t *cmd = search_botcmd_t((const botcmd_t*)&C_bot, code, (sizeof(C_bot)/sizeof(botcmd_t)) - 1);
 
   if (cmd) {
     /* Found a match */

+ 3 - 2
src/mod/share.mod/share.c

@@ -1079,7 +1079,8 @@ static botcmd_t C_share[] = {
   {"un", share_ufno, HUB},
   {"us", share_ufsend, 0},
   {"uy", share_ufyes, HUB},
-  {"v", share_version, 0}
+  {"v", share_version, 0},
+  {NULL, NULL, 0}
 };
 
 
@@ -1087,7 +1088,7 @@ void
 sharein(int idx, char *msg)
 {
   char *code = newsplit(&msg);
-  const botcmd_t *cmd = search_botcmd_t((const botcmd_t*)&C_share, code, sizeof(C_share)/sizeof(botcmd_t));
+  const botcmd_t *cmd = search_botcmd_t((const botcmd_t*)&C_share, code, (sizeof(C_share)/sizeof(botcmd_t)) - 1);
   if (cmd) {
     /* Found a match */
     (cmd->func) (idx, msg);

+ 3 - 2
src/mod/update.mod/update.c

@@ -171,7 +171,8 @@ static botcmd_t C_update[] =
   {"un",	update_ufno, 0},
   {"us",	update_ufsend, 0},
   {"uy",	update_ufyes, 0},
-  {"v",         update_version, 0}
+  {"v",         update_version, 0},
+  {NULL,	NULL, 0}
 };
 
 static void got_nu(char *botnick, char *code, char *par)
@@ -214,7 +215,7 @@ static cmd_t update_bot[] = {
 void updatein(int idx, char *msg)
 {
   char *code = newsplit(&msg);
-  const botcmd_t *cmd = search_botcmd_t((const botcmd_t*)&C_update, code, sizeof(C_update)/sizeof(botcmd_t));
+  const botcmd_t *cmd = search_botcmd_t((const botcmd_t*)&C_update, code, (sizeof(C_update)/sizeof(botcmd_t)) - 1);
   if (cmd) {
     /* Found a match */
     (cmd->func)(idx, msg);

+ 1 - 1
src/set.c

@@ -462,7 +462,7 @@ static inline variable_t *var_get_var_by_name(const char *name)
 {
   variable_t key;
   key.name = name;
-  return (variable_t*) bsearch(&key, &vars, sizeof(vars)/sizeof(variable_t), sizeof(variable_t), comp_variable_t);
+  return (variable_t*) bsearch(&key, &vars, (sizeof(vars)/sizeof(variable_t)) - 1, sizeof(variable_t), comp_variable_t);
 }
 
 void var_set(variable_t *var, const char *target, const char *datain)