Skip to content

Commit

Permalink
Did optimizations found by PVS-Studio
Browse files Browse the repository at this point in the history
  • Loading branch information
uhlin committed Jan 26, 2024
1 parent 49d2677 commit d262526
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/events/names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,18 +374,19 @@ get_list_of_matching_channel_users(CSTRING chan, CSTRING search_var)
{
PIRC_WINDOW window;
PTEXTBUF matches;
size_t varlen;

if ((window = window_by_label(chan)) == NULL)
return NULL;

matches = textBuf_new();
varlen = strlen(search_var);

for (size_t n = 0; n < ARRAY_SIZE(window->names_hash); n++) {
for (PNAMES names = window->names_hash[n];
names != NULL;
names = names->next) {
if (!strncmp(search_var, names->nick,
strlen(search_var)))
if (!strncmp(search_var, names->nick, varlen))
add_match(matches, names->nick);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/io-loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,11 @@ add_cmd(PTEXTBUF matches, CSTRING cmd)
PTEXTBUF
get_list_of_matching_commands(CSTRING search_var)
{
PTEXTBUF matches = textBuf_new();
PTEXTBUF matches = textBuf_new();
const size_t varlen = strlen(search_var);

FOREACH_COMMAND() {
if (!strncmp(search_var, sp->cmd, strlen(search_var)))
if (!strncmp(search_var, sp->cmd, varlen))
add_cmd(matches, sp->cmd);
}

Expand Down

0 comments on commit d262526

Please sign in to comment.