Skip to content

Commit

Permalink
refactor ada.c cmp function
Browse files Browse the repository at this point in the history
Do not call strlen 8 times, call only once.
Fix: ada.c(645): warning C4018: '<' : signed/unsigned mismatch
  • Loading branch information
bmateusz committed Feb 23, 2015
1 parent 92b715e commit afa52d3
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions ada.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ static void movePos(int amount)
static boolean cmp(const char *buf, int len, const char *match)
{
boolean status = FALSE;
int matchLen;

/* if we are trying to match nothing, that is always true */
if(match == NULL)
Expand All @@ -636,16 +637,18 @@ static boolean cmp(const char *buf, int len, const char *match)
return status;
}

matchLen = strlen(match);

/* A match only happens the number of chars in the matching string match,
* and whitespace follows... Which means we also must check to see if the
* end of the line is after the matching string. Also check for some
* separation characters such as (, ), :, or ; */
if((strncasecmp(buf, match, strlen(match)) == 0) &&
(strlen(match) == len ||
(strlen(match) < len &&
(isspace(buf[strlen(match)]) || buf[strlen(match)] == '(' ||
buf[strlen(match)] == ')' || buf[strlen(match)] == ':' ||
buf[strlen(match)] == ';'))))
if ((strncasecmp(buf, match, matchLen) == 0) &&
(matchLen == len ||
(matchLen < len &&
(isspace(buf[matchLen]) || buf[matchLen] == '(' ||
buf[matchLen] == ')' || buf[matchLen] == ':' ||
buf[matchLen] == ';'))))
{
status = TRUE;
}
Expand Down

0 comments on commit afa52d3

Please sign in to comment.