diff --git a/include/typelib.h b/include/typelib.h index c979dc1..e26c15c 100644 --- a/include/typelib.h +++ b/include/typelib.h @@ -52,7 +52,11 @@ extern int find_type_or_exit(const char *x, TYPELIB *typelib, /** makes @c find_type() treat ',' as terminator */ #define FIND_TYPE_COMMA_TERM (1 << 3) -extern int find_type(const char *x, const TYPELIB *typelib, unsigned int flags); +extern int find_type(const char *x, const TYPELIB *typelib, unsigned int flags + , const char *end = nullptr +); extern const char *get_type(TYPELIB *typelib, unsigned int nr); extern TYPELIB *copy_typelib(MEM_ROOT *root, TYPELIB *from); diff --git a/mysys/typelib.cc b/mysys/typelib.cc index ae0b8e0..c8fdc48 100644 --- a/mysys/typelib.cc +++ b/mysys/typelib.cc @@ -83,7 +83,11 @@ int find_type_or_exit(const char *x, TYPELIB *typelib, const char *option) { >0 Offset+1 in typelib for matched string */ -int find_type(const char *x, const TYPELIB *typelib, uint flags) { +int find_type(const char *x, const TYPELIB *typelib, uint flags + , const char *end +) { int find, pos; int findpos = 0; /* guarded by find */ const char *i; @@ -107,7 +111,11 @@ int find_type(const char *x, const TYPELIB *typelib, uint flags) { ; if (!*j) { while (*i == ' ') i++; /* skip_end_space */ - if (!*i || ((flags & FIND_TYPE_COMMA_TERM) && is_field_separator(*i))) + if (!*i || ((flags & FIND_TYPE_COMMA_TERM) && is_field_separator(*i)) + || i == end + ) return pos + 1; } if ((!*i && (!(flags & FIND_TYPE_COMMA_TERM) || !is_field_separator(*i))) && @@ -252,7 +260,11 @@ static TYPELIB on_off_default_typelib = { static int parse_name(const TYPELIB *lib, const char **strpos, const char *end) { const char *pos = *strpos; - int find = find_type(pos, lib, FIND_TYPE_COMMA_TERM); + int find = find_type(pos, lib, FIND_TYPE_COMMA_TERM + , end + ); for (; pos != end && *pos != '=' && *pos != ','; pos++) ; *strpos = pos;