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

@ -2389,7 +2389,7 @@ static void inp_stripcomments_deck(struct card *c, bool cf)
('$' outside of .control section is o.k. however). ('$' outside of .control section is o.k. however).
If the comaptibility mode is PS, LTPS or LTPSA, '$' is treated as a valid If the comaptibility mode is PS, LTPS or LTPSA, '$' is treated as a valid
character, not a s end-of-line comment delimiter, except for that it is character, not as end-of-line comment delimiter, except for that it is
located at the beginning of a line. If inside of a control section, located at the beginning of a line. If inside of a control section,
still '$ ' is read a an end-of-line comment delimiter.*/ still '$ ' is read a an end-of-line comment delimiter.*/
static void inp_stripcomments_line(char *s, bool cs) static void inp_stripcomments_line(char *s, bool cs)
@ -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;
} }