fix(find.c): Check for empty pattern and free mem

This commit is contained in:
Sau P 2024-12-02 22:16:07 +00:00 committed by anon
parent 2b7b6d8de2
commit 51e8f8bf76

View File

@ -672,6 +672,12 @@ char *findinclude(const char *pattern) {
/* initialize */
int findinit(const char *pattern_) {
if (pattern_ == NULL
|| pattern_[0] == '\0') {
return NOTSYMBOL;
}
char *pattern = strdup(pattern_);
int r = NOERROR;
char buf[PATLEN + 3];
@ -685,8 +691,11 @@ int findinit(const char *pattern_) {
isregexp_valid = false;
/* Pattern length */
size_t pattlen = strlen(pattern);
/* remove trailing white space */
for(s = pattern + strlen(pattern) - 1; isspace((unsigned char)*s); --s) {
for(s = pattern + (pattlen - 1); isspace((unsigned char)*s); --s) {
*s = '\0';
}
@ -772,6 +781,7 @@ int findinit(const char *pattern_) {
}
end:
free(pattern);
return r;
}