Hi all ! This binary search seems to be fishy: I suggest moving if(bot>=top) return (-1); up some lines to avoid the invalid index mid==-1 ! Cat. PS: there might be some other binary-searches with the same implementation. int find_action(int cmd) { int bot, top, mid; bot = 0; top = list_top; if (top < 0) return (-1); for (;;) { mid = (bot + top) >> 1; // NEW SUGGESTED LOCATION if (bot >= top) return (-1); if (soc_mess_list[mid].act_nr == cmd) return (mid); /* ORIGINAL LOCATION if (bot >= top) return (-1); */ if (soc_mess_list[mid].act_nr > cmd) top = --mid; else bot = ++mid; } }
This archive was generated by hypermail 2b30 : 12/07/00 PST