1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-02 19:21:53 +03:00

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

View File

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