mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-05-07 07:18:08 +02: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(in != NULL);
|
||||||
assert(separators != NULL);
|
assert(separators != NULL);
|
||||||
assert(num_elements != NULL);
|
|
||||||
|
|
||||||
const char *s = in;
|
const char *s = in;
|
||||||
size_t l, nelems = 0;
|
size_t l, nelems = 0;
|
||||||
|
|
@ -180,7 +179,8 @@ strv_from_string(const char *in, const char *separators, size_t *num_elements)
|
||||||
nelems++;
|
nelems++;
|
||||||
|
|
||||||
if (nelems == 0) {
|
if (nelems == 0) {
|
||||||
*num_elements = 0;
|
if (num_elements)
|
||||||
|
*num_elements = 0;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -194,14 +194,16 @@ strv_from_string(const char *in, const char *separators, size_t *num_elements)
|
||||||
char *copy = strndup(word, l);
|
char *copy = strndup(word, l);
|
||||||
if (!copy) {
|
if (!copy) {
|
||||||
strv_free(strv);
|
strv_free(strv);
|
||||||
*num_elements = 0;
|
if (num_elements)
|
||||||
|
*num_elements = 0;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
strv[idx++] = copy;
|
strv[idx++] = copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
*num_elements = nelems;
|
if (num_elements)
|
||||||
|
*num_elements = nelems;
|
||||||
|
|
||||||
return strv;
|
return strv;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue