reftable/basics: handle allocation failures in parse_names()

Handle allocation failures in `parse_names()` by returning `NULL` in
case any allocation fails. While at it, refactor the function to return
the array directly instead of assigning it to an out-pointer.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt
2024-10-02 12:55:38 +02:00
committed by Junio C Hamano
parent 6593e147d3
commit eef7bcdafe
4 changed files with 33 additions and 13 deletions

View File

@ -38,9 +38,12 @@ size_t binsearch(size_t sz, int (*f)(size_t k, void *args), void *args);
*/
void free_names(char **a);
/* parse a newline separated list of names. `size` is the length of the buffer,
* without terminating '\0'. Empty names are discarded. */
void parse_names(char *buf, int size, char ***namesp);
/*
* Parse a newline separated list of names. `size` is the length of the buffer,
* without terminating '\0'. Empty names are discarded. Returns a `NULL`
* pointer when allocations fail.
*/
char **parse_names(char *buf, int size);
/* compares two NULL-terminated arrays of strings. */
int names_equal(const char **a, const char **b);