basic/string-table: avoid crash when table is sparse

Generated _from_string() would crash when invoked on a table with some
holes.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2020-02-27 21:28:54 +01:00
parent 1ad448673e
commit aa73f181e9
1 changed files with 1 additions and 1 deletions

View File

@ -44,7 +44,7 @@ ssize_t string_table_lookup(const char * const *table, size_t len, const char *k
char *s; \
if (i < 0 || i > max) \
return -ERANGE; \
if (i < (type) ELEMENTSOF(name##_table)) { \
if (i < (type) ELEMENTSOF(name##_table) && name##_table[i]) { \
s = strdup(name##_table[i]); \
if (!s) \
return -ENOMEM; \