Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
No use for strlen() in a loop
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFrench committed Sep 9, 2017
1 parent ea37928 commit 6833080
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions evhtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,7 @@ htp__callback_find_(evhtp_callbacks_t * cbs,
unsigned int * start_offset,
unsigned int * end_offset)
{
size_t path_len;
#ifndef EVHTP_DISABLE_REGEX
regmatch_t pmatch[28];
#endif
Expand All @@ -776,19 +777,16 @@ htp__callback_find_(evhtp_callbacks_t * cbs,
return NULL;
}

path_len = strlen(path);

TAILQ_FOREACH(callback, cbs, next)
{
switch (callback->type) {
case evhtp_callback_type_hash:
if (callback->val.path[1] != path[1])
{
continue;
}

if (strcmp(callback->val.path, path) == 0)
if (strncmp(callback->val.path, path, path_len) == 0)
{
*start_offset = 0;
*end_offset = (unsigned int)strlen(path);
*end_offset = path_len;

return callback;
}
Expand All @@ -810,7 +808,6 @@ htp__callback_find_(evhtp_callbacks_t * cbs,
#endif
case evhtp_callback_type_glob:
{
size_t path_len = strlen(path);
size_t glob_len = strlen(callback->val.glob);

if (htp__glob_match_(callback->val.glob,
Expand All @@ -819,7 +816,7 @@ htp__callback_find_(evhtp_callbacks_t * cbs,
path_len) == 1)
{
*start_offset = 0;
*end_offset = (unsigned int)path_len;
*end_offset = path_len;

return callback;
}
Expand Down

0 comments on commit 6833080

Please sign in to comment.