# HG changeset patch # User Matti Hamalainen # Date 1288879202 -7200 # Node ID 701c54a454668912ed358bee5e044ab8556bbdf4 # Parent cc1cc49d26f02c3197a9e6151febd6362dbd06ab Fix matching of usernames against hash. In some cases after the last match the function would not go back to the first match. diff -r cc1cc49d26f0 -r 701c54a45466 libnnchat.c --- a/libnnchat.c Thu Nov 04 15:55:37 2010 +0200 +++ b/libnnchat.c Thu Nov 04 16:00:02 2010 +0200 @@ -653,6 +653,18 @@ } +static nn_user_t *nn_user_match_do(nn_user_t *list, const char *pattern, size_t len) +{ + nn_user_t *curr = list; + while (curr != NULL) { + if (len <= strlen(curr->name) && strncasecmp(curr->name, pattern, len) == 0) + return curr; + curr = curr->next; + } + return NULL; +} + + nn_user_t *nn_user_match(const nn_userhash_t *list, const char *pattern, const char *current, BOOL again) { uint8_t hash; @@ -675,18 +687,13 @@ } curr = curr->next; } - if (found != NULL) - curr = found; - else - curr = list->buckets[hash]; + + if (found != NULL && (found = nn_user_match_do(found, pattern, len)) != NULL) + return found; } - - while (curr != NULL) { - if (len <= strlen(curr->name) && strncasecmp(curr->name, pattern, len) == 0) - return curr; - curr = curr->next; - } + if ((curr = nn_user_match_do(list->buckets[hash], pattern, len)) != NULL) + return curr; } return NULL;