Make ...search_identifier safe against NULL arguments

Otherwise strstr will fail
This commit is contained in:
Holger Vogt 2019-09-08 09:34:15 +02:00
parent 0071ad8569
commit aa726c9864
1 changed files with 47 additions and 44 deletions

View File

@ -4452,6 +4452,7 @@ static bool b_transformation_wanted(const char *p)
char *search_identifier(char *str, const char *identifier, char *str_begin) char *search_identifier(char *str, const char *identifier, char *str_begin)
{ {
if (str && identifier) {
while ((str = strstr(str, identifier)) != NULL) { while ((str = strstr(str, identifier)) != NULL) {
char before; char before;
@ -4470,13 +4471,14 @@ char *search_identifier(char *str, const char *identifier, char *str_begin)
str++; str++;
} }
}
return NULL; return NULL;
} }
char *ya_search_identifier(char *str, const char *identifier, char *str_begin) char *ya_search_identifier(char *str, const char *identifier, char *str_begin)
{ {
if (str && identifier) {
while ((str = strstr(str, identifier)) != NULL) { while ((str = strstr(str, identifier)) != NULL) {
char before; char before;
@ -4488,21 +4490,22 @@ char *ya_search_identifier(char *str, const char *identifier, char *str_begin)
if (is_arith_char(before) || isspace_c(before) || if (is_arith_char(before) || isspace_c(before) ||
(str <= str_begin)) { (str <= str_begin)) {
char after = str[strlen(identifier)]; char after = str[strlen(identifier)];
if ((is_arith_char(after) || isspace_c(after) || after == '\0')) if ((is_arith_char(after) || isspace_c(after) ||
after == '\0'))
break; break;
} }
str++; str++;
} }
}
return str; return str;
} }
static char *search_plain_identifier(char *str, const char *identifier) static char *search_plain_identifier(char *str, const char *identifier)
{ {
if (str && identifier) {
char *str_begin = str; char *str_begin = str;
while ((str = strstr(str, identifier)) != NULL) { while ((str = strstr(str, identifier)) != NULL) {
char before; char before;
@ -4519,7 +4522,7 @@ static char *search_plain_identifier(char *str, const char *identifier)
str += strlen(identifier); str += strlen(identifier);
} }
}
return NULL; return NULL;
} }