mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-02-03 22:50:27 +01:00
util: allow strv_from_string() with NULL nelems
The caller may not care about the number of elements, let them be careless. Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1250>
This commit is contained in:
parent
9a8254fbb6
commit
dc8f7c3671
1 changed files with 6 additions and 4 deletions
|
|
@ -172,7 +172,6 @@ strv_from_string(const char *in, const char *separators, size_t *num_elements)
|
|||
{
|
||||
assert(in != NULL);
|
||||
assert(separators != NULL);
|
||||
assert(num_elements != NULL);
|
||||
|
||||
const char *s = in;
|
||||
size_t l, nelems = 0;
|
||||
|
|
@ -180,7 +179,8 @@ strv_from_string(const char *in, const char *separators, size_t *num_elements)
|
|||
nelems++;
|
||||
|
||||
if (nelems == 0) {
|
||||
*num_elements = 0;
|
||||
if (num_elements)
|
||||
*num_elements = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -194,14 +194,16 @@ strv_from_string(const char *in, const char *separators, size_t *num_elements)
|
|||
char *copy = strndup(word, l);
|
||||
if (!copy) {
|
||||
strv_free(strv);
|
||||
*num_elements = 0;
|
||||
if (num_elements)
|
||||
*num_elements = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strv[idx++] = copy;
|
||||
}
|
||||
|
||||
*num_elements = nelems;
|
||||
if (num_elements)
|
||||
*num_elements = nelems;
|
||||
|
||||
return strv;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue