Skip to content

Commit 15b43c1

Browse files
committed
fix highly faulty trim_trailing_ws()
1 parent 54d1af9 commit 15b43c1

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

source/find.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -680,17 +680,11 @@ char *findinclude(const char *pattern) {
680680
}
681681

682682
static inline
683-
void trim_trailing_ws(char *str, size_t len) {
683+
void trim_trailing_ws(char * str, size_t len) {
684+
char * end = str + len;
684685

685-
/* Jump to end of string */
686-
char *end = str;
687-
end += len;
688-
689-
/* While character is space and not NULL.
690-
* Checking for NULL is required otherwise 'isspace' will produce undefined
691-
behaviour when encountering a nonstandard character. */
692-
while ((end != NULL) && isspace(end)) {
693-
/* Move backwards */
686+
while (end > str
687+
&& isspace(*end)) {
694688
--end;
695689
}
696690
*end = '\0';
@@ -753,6 +747,9 @@ int findinit(const char *pattern_) {
753747

754748
/* Trim trailing whitespace */
755749
trim_trailing_ws(pattern, pattlen);
750+
if (pattern[0] == '\0') {
751+
return NOTSYMBOL;
752+
}
756753

757754
/* Make sure pattern is lowercased. Curses
758755
* mode gets this right all on its own, but at least -L mode

0 commit comments

Comments
 (0)